A method is to expose a web-accessible resource, though this will allow any website to test if your extension is installed.

Suppose your extension’s ID is aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, and you add a file (say, a transparent pixel image) as test.png in your extension’s files.

Then, you expose this file to the web pages with web_accessible_resources manifest key in manifest.json:

  "web_accessible_resources": [
    "test.png"
  ],

In your web page, you can try to load this file by its full URL (in an tag, via XHR, or in any other way):

chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/test.png

If the file loads, then the extension is installed. If there’s an error while loading this file, then the extension is not installed.

// Code from http://goo.gl/SnuOJV
function detectExtension(extensionId, callback) { 
  var img; 
  img = new Image(); 
  img.src = "chrome-extension://" + extensionId + "/test.png"; 
  img.onload = function() { 
    callback(true); 
  }; 
  img.onerror = function() { 
    callback(false); 
  };
}

C2: Another way is access direct via connect method:

var extApp = chrome.extension || chrome.runtime;
var myPort = extApp.connect('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', some_object_to_send_on_connect);

Reference Link

About The Author