0

I have created an extension and I am trying to detect if this extension exists into one of my virtual hosts.

Here is the code for detecting if an extension exists or not: (script.js)

var detect = function(base, if_installed, if_not_installed) {
    var s = document.createElement('script');
    s.onerror = if_not_installed;
    s.onload = if_installed;
    document.body.appendChild(s);
    s.src = base + '/manifest.json';
};
detect('chrome-extension://' + "myExtensionId", function() {alert('boom!');},
    function() {alert("buf. nothin")});

When I open my virtual hosts in browser it alerts me: buf. nothin and in console log this error appears:

  • Denying load of chrome-extension://myExtensionId/manifest.json. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension

If I click the extension that I've created, it alerts boom and I receive no errors, so that means in extension it detects my extension, but within my virtual host it does not.

So, detecting if an extension exists within an extension is possible, but it is possible to detect if an extension exists from a Web Page?

Lucaci Sergiu
  • 564
  • 5
  • 17
  • error message clearly explains what [the problem is](https://developer.chrome.com/extensions/manifest/web_accessible_resources). But I recommend using the approach in @Daniel's answer – minj Jan 09 '16 at 13:16
  • this error message was persisting even I did this in `manifest.json`: `"web_accessible_resources": [ "/*" ]`. – Lucaci Sergiu Jan 09 '16 at 18:56
  • I don't think that's a valid glob. Try `[ "*.json", "scripts/*.js" ]` or similar – minj Jan 09 '16 at 19:16
  • It finally works! `manifest.json` was not configured well! Check the configuration here: [manifest](https://github.com/sergiulucaci/extension/blob/master/manifest.json) – Lucaci Sergiu Jan 11 '16 at 10:39
  • Possible duplicate of [Check whether user has a Chrome extension installed](http://stackoverflow.com/questions/6293498/check-whether-user-has-a-chrome-extension-installed) – Simon East Oct 24 '16 at 04:52

1 Answers1

3

If you own the page, you can send a message to the extension. If it responds, it is installed. Docs: https://developer.chrome.com/extensions/messaging#external-webpage

manifest.json

"externally_connectable": {
  "matches": ["https://example.com/*"]
}

page.js

var id = "randomlettersfromwebstoreurl"

chrome.runtime.sendMessage(id, "installed?", function(response) {
 if(response) {
  // The extension is installed
 } else {
  // The extension is not installed or disabled
} })

extension.js

chrome.runtime.onMessageExternal.addListener(function(request, sender, respond) {
 if(request == "installed?") {
  respond(true)
} })
Daniel Herr
  • 19,083
  • 6
  • 44
  • 61
  • I figured it out finally. In `manifest.json` -> `matches` I had ``. Instead of this I put for example _www.facebook.com_ and it worked. When I enter **facebook** in a new tab, **chrome** it detects if my extension is installed or not. `manifest.json`: `"content_scripts": [ { "matches": ["https://www.facebook.com/"], "js": [ "third/jquery-1.11.3.js", "script.js"], "run_at" : "document_start" } ],` – Lucaci Sergiu Jan 09 '16 at 18:58