Reputation: 23
I tried all solutions in this question
Check whether user has a Chrome extension installed
what I did:
1- I added background js file and in manifest I added the following
"background": {
"scripts": ["js/background.js"],
"persistent": true
},
"permissions": [ "https://*.mydomain.com/*" ],
in background.js I added
chrome.runtime.onMessageExternal.addListener(function(msg, sender, sendResponse) {
if ((msg.action == "id") && (msg.value == id))
{
sendResponse({id : id});
}
});
and in my website I added this code
<script>
var id = "madbfblbpcoiddlankhkdbagjeemnlof";
chrome.runtime.sendMessage(id, {action: "id", value : id}, function(response) {
if(response && (response.id == id)) //extension installed
{
console.log(response);
}
else //extension not installed
{
console.log("Please consider installig extension");
}
});
</script>
and I always get Please consider installig extension
How can I fix this issue ??
Upvotes: 1
Views: 1807
Reputation: 1093
Define your id
at the start of your background.js
like so: var id = chrome.runtime.id;
.
Also you need to add your site to the externally_connectable
instead of the permissions
in the manifest.json
as:
"externally_connectable": {
"matches": ["https://*.mydomain.com/*"]
}
Upvotes: 3