我在这个问题上尝试了所有解决方案
我做了什么:
1-我添加了后台js文件,并在清单中添加了以下内容
"background": {
"scripts": ["js/background.js"],
"persistent": true
},
"permissions": [ "https://*.mydomain.com/*" ],
在我添加的background.js中
chrome.runtime.onMessageExternal.addListener(function(msg, sender, sendResponse) {
if ((msg.action == "id") && (msg.value == id))
{
sendResponse({id : id});
}
});
在我的网站上,我添加了此代码
<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>
我总是得到请考虑installig扩展
我该如何解决这个问题?
定义你id
在你开始background.js
像这样:var id = chrome.runtime.id;
。
同时您需要将您的网站添加到externally_connectable
而不是permissions
在manifest.json
为:
"externally_connectable": {
"matches": ["https://*.mydomain.com/*"]
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句