Vico
Vico

Reputation: 1256

Detect if another Chrome Extension is installed

I'm developing an extension for Chrome, but I want my extension to work only if another is disabled/removed.

It means that when my users install my extension, I would like to tell them "if you install my extension, you have to accept to disable this other extension".

I don't want my extension to work if the other one is active.

Do you know how I could proceed?

Upvotes: 0

Views: 1052

Answers (1)

Dmitri Pavlutin
Dmitri Pavlutin

Reputation: 19130

To detect if another extension is installed:

1) Update the manifest.json to include the necessary management permission:

{
    "name": "My extension",
    ...
    "permissions": [
      "management"
    ],
    ...
}

2) To check if the extension is installed exist 2 options:

a) If you know the extension id, use the chrome.management.get(extensionId, function callback) method:

 var extensionId = '<the_extension_id>';
 chrome.management.get(extensionId, function(extensionInfo) {
    var isInstalled;
    if (chrome.runtime.lastError) {
      //When the extension does not exist, an error is generated
      isInstalled = false;
    } else {
      //The extension is installed. Use "extensionInfo" to get more details
      isInstalled = true;
    }
  });

b) If you know the extension name (or any other parameter), you can use chrome.management.getAll(function callback):

var extensionName = '<the_extension_name>';

chrome.management.getAll(function(extensions) {
    var isInstalled = extensions.some(function(extensionInfo) {
       return extensionInfo.name === extensionName;       
    });
});

Upvotes: 2

Related Questions