Take the 2-minute tour ×

I am trying to detect if my chrome extension is installed using js executed on my website. I have found some examples, some I don't even understand or could make them work. What I tried and kinda worked is adding elements to DOM or modifying some css property. For example:

On my extension background page I have:

function changeBG(tab){
     chrome.tabs.executeScript(tab.id, {
      code: ' document.body.bgColor="red" '


On my website I have:


The background does turn red, but .bgColor is null because I try to read it on the top of my website code as soon as the page starts loading. After the page loaded I can read it and it returns "red". (same thing happen if injecting an element into the page and then trying to read innerHTML or a property of the element).

But I don't want to wait for onload or anything, because my content depends on if the extension is installed or not.

I have also tried the method of loading an image from the extension content but once again this is an indirect ¿asynchronous? method.

I don't want to "swap" the content, I want to know if the extension is installed before continuing to load anything else on my website.

Does someone knows how I could do this?

share|improve this question
add comment

2 Answers

As I understand, javascript check is executed too late for you, because webpage content is already processed by a browser. If you want to know if extension is enabled before any content is loaded you should check it on the server side. The way to do this is to make your extension to append some signature to headers sent by browser to servers. Then, if signature is present, you will know that request sender has your extension installed and you will be able to return proper content. Header manipulation is described here. You will probably need to use this: chrome.webRequest.onBeforeSendHeaders.addListener.

share|improve this answer
Thats a great solution, I will do some research to see how I can achieve that, thanks a lot. –  user979390 Jan 20 '12 at 16:52
add comment

Since it is your own website use the chrome.app.isInstalled method used for inline installation. You will have to verify your domain with Webmaster Tools first.

share|improve this answer
How do I run "chrome.app.isInstalled" from www.myWebsite.com/somePage.php ? Wouldn't I need to wait for DOM or document to be loaded first? EDIT: The extension if for internal use, I don't think I could get the site verified, plus it seems like my extension would need to be in the Chrome Web Store for using this. –  user979390 Jan 21 '12 at 5:45
Yes. The extension would need to be in the Chrome Web Store. –  abraham Jan 21 '12 at 15:20
add comment

Your Answer


