Detect if a Chrome extension is installed

12,819

Solution 1

I know it's an old question, but since I managed to solve this problem (for my needs) I'd like to share.

I accomplished this by adding some info into the DOM. In extension's content.js file I have:

document.documentElement.setAttribute('extension-installed', true);

And in my page:

var isInstalled = document.documentElement.getAttribute('extension-installed');

if (isInstalled) {
    ...
}

Solution 2

I'm not sure if you want to check from a web page or from an already installed extension.

From a web page

You can't. Only Chrome Web Store can check that.

But if you write the extension and the web page, you could make your extension execute some content script in you page to confirm its installed and working.

From an extension

Provided you know the extension's id you are looking for, you can use

chrome.management.get(id, callback);

You can use chrome.management.getAll() to get a list of installed extensions, with more info than their id.

https://developer.chrome.com/extensions/management

Solution 3

Assuming you are the author of the extension, you can include a CustomEvent within your extension.js file, and within your site you can addEventListener to that event.

Within your extension:

const customEvent = new CustomEvent('myExtensionCheckEvent', {
    detail: true // whatever value you enter here will be passed in the event
})
document.dispatchEvent(customEvent)

And your sites javascript file:

document.addEventListener('myExtensionCheckEvent', e => {
    if (e.detail) {
        // the extension is installed
    }
})

Note that the key must be called detail.

Share:
12,819
simple
Author by

simple

Updated on June 04, 2022

Comments

  • simple
    simple almost 2 years

    I want to detect if a Chrome extension is installed in user's browser. If not, I want to display a link to install the extension. If it is already installed, I want to hide the link.

    This seems like a possible solution but I am confused what some_object_to_send_on_connect is supposed to be? https://developer.chrome.com/extensions/extension#global-events

    var myPort=chrome.extension.connect('jllpkdkcdjndhggodimiphkghogcpida', some_object_to_send_on_connect);
    
  • Hosein Aqajani
    Hosein Aqajani over 8 years
    it is not work and return this error: cannot read property get of undefined also I have management permission in my manifest.
  • Alejandro Silvestri
    Alejandro Silvestri over 7 years
    It seems the browser isn't recongnizing chrome.management, or perhaps you misspelled it. Please refer to developer.chrome.com/extensions/management#method-get
  • Alejandro Montilla
    Alejandro Montilla over 6 years
    Hello @Leo Tavares, here you can find a guide on how format your answers on SO: stackoverflow.com/help/formatting.
  • Leo Tavares
    Leo Tavares over 6 years
    Thanks, @AlejandroMontilla (Y)
  • Alejandro Montilla
    Alejandro Montilla over 6 years
    You're Welcome!!
  • Houssem Chlegou
    Houssem Chlegou about 4 years
    somehow, this is the simpler solution ever provided! :D Nice and clean. Thanks for sharing it.