2

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);
simple
  • 2,327
  • 7
  • 35
  • 55
  • 1
    Sorry, that question is still the place to ask. The answer you quote is outdated: this method does not exist anymore. Check BJury's answer for an up-to-date and more complete version. – Xan Jan 13 '15 at 19:38
  • @simple Do you solve this problem? could you please share your solution? I think `chrome.management` is undefined in javascript – Hosein Aqajani Dec 20 '15 at 07:28

3 Answers3

10

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) {
    ...
}
Alejandro Montilla
  • 2,626
  • 3
  • 31
  • 35
Leo Tavares
  • 355
  • 3
  • 7
3

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

Alejandro Silvestri
  • 3,706
  • 31
  • 43
  • it is not work and return this error: `cannot read property get of undefined` also I have management permission in my manifest. – Hosein Aqajani Dec 20 '15 at 07:25
  • It seems the browser isn't recongnizing chrome.management, or perhaps you misspelled it. Please refer to https://developer.chrome.com/extensions/management#method-get – Alejandro Silvestri Jan 10 '17 at 10:32
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.

Nick McMillan
  • 41
  • 1
  • 6