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