我已经为我的web应用程序开发了Chrome和Firefox的扩展。现在我想检查一下,用户是否已经安装了这个扩展。如果没有,则会弹出一条带有下载链接的消息。
为了有一个通用的代码基础,我选择了一个既适用于Chrome也适用于Firefox的选项。不幸的是,它只在Chrome上起作用。
我的代码:
//page.js
window.addEventListener("message", function(event){
if(event.data && event.data.direction == "from-content-script") {
document-getElementById("message").style = "display: none";
}
});//content-script.js
window.postMessage({
direction: "from-content-script",
message: "Message from the content script"
}, "*");//manifest.json
"content_scripts": [{
"matches": ["http://localhost:3000/*],
"js": ["content-script.js"]
}]所以它在Chrome上运行得很好,但在Firefox上就不行了。我想知道内容脚本是否被正确注入,因为如果我包含一个用于测试目的的警报,它不会显示出来。
我指的是这个:How to check if a Firefox WebExtension is installed or not with page JavaScript?,但我不能让它在火狐上工作。
谢谢你的帮忙!
发布于 2021-06-01 16:27:18
正如the docs所说:
路径模式字符串不应包含端口号。添加端口,例如:"http://localhost:1234/"*会导致匹配模式被忽略。
不要使用
"matches": ["http://localhost:3000/*"],但
"matches": ["http://localhost/*"],https://stackoverflow.com/questions/49747725
复制相似问题