我加载了一个简单的未打包的 Chrome 扩展。所有其他扩展均已关闭。
manifest.js
{
"manifest_version":2,
"name":"Etc",
"description":"Etc",
"version":"1.0",
"content_scripts": [{
"matches" : ["*://*/*"],
"js": ["contentscript.js"],
"run_at":"document_end"
}],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions":[
"tabs",
"*://*/*"
],
"browser_action": {
"default_title": "Idonethis",
"default_icon":"icon.png"
}
}
background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
contentscript.js
chrome.runtime.sendMessage({greeting:"hello"}, function(response) {
console.log(response.farewell);
});
在大多数域(例如 www.bbc.co.uk)上,消息传递工作正常并显示
message contentscript.js:2
但是,据我所知,在 www.google.co.uk 或 uk.yahoo.com 上,它不会传递消息,也不会执行任何 contentscript.js。这是 Chrome 扩展安全规范的一部分吗?
编辑 此代码已修复,可以在此处查看 https://github.com/lindaymacvean/test-chrome-ext
最佳答案
可能是因为匹配规则"matches": ["*://*/"]
。您需要将其更改为 "matches": ["*://*/*"]
因为目前它仅匹配没有路径的选项卡。例如。 http://example.com/
将匹配,但 http://example.co.uk/foo
将不匹配。
关于javascript - Chrome 扩展程序阻止 google.co.uk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25234414/