Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome Extension: How to detect if an extension is installed using Content Scripts
    text
    copied!<p>I am asking this question after looking at several related questions on stackoverflow. I started with <a href="https://stackoverflow.com/a/6293601/206613">how to detect if an extension is installed</a>. I opted for the method where I add a div to body using content scripts on some pages. Here is how I did it...</p> <p>manifest.json</p> <pre><code>{ "name": "Install Check", "content_scripts": [ { "matches": ["http://host.com/*"], "js" : ["insert_node.js"] } ], "permissions": [ "tabs", "host.com/*" ] } </code></pre> <p>insert_node.js (content script)</p> <pre><code>var insert_node = document.createElement('div'); insert_node.id = "HOST_SITE"; document.body.appendChild(insert_node); </code></pre> <p>host page</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;This is a host site. Welcome!!!&lt;/h1&gt; &lt;script src="jquery.js"&gt;&lt;/script&gt; &lt;script src="notification.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>extension install script</p> <pre><code>$(document).ready(function() { if ($('#HOST_SITE').length &gt; 0) { alert("you have our extension installed"); } else { alert("not installed"); } }); </code></pre> <p>My problem is that the alert with message <code>not_installed</code> always pops up before the chrome can inject the node in DOM. I read about <code>run_at</code> attribute in <a href="https://stackoverflow.com/a/6124054/206613">manifest.json over here</a>. But that didn't solve the problem either. I tried all the three <code>document_start</code>, <code>document_idle</code>, <code>document_end</code> values. What am I doing wrong over here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload