我刚刚将我的chrome扩展更新为json版本2,并且我试图让我的扩展再次工作.问题是sendRequest一路贬值.所以我将代码从https://developer.chrome.com/extensions/messaging.html复制 到我的脚本中并将其修改为我自己的变量名称,但它不起作用.
那么我回去并输入原始代码,它仍然无法正常工作.我已经阅读了多个相似的问题[并希望这不会被复制,因为它们都不是我的情况].
manifest.json的:
{
"background": {
"page": "background.html"
},
... ... ...
"content_scripts": [ {
"css": [ "style.css" ],
"js": [ "jq.js", "script.js" ],
"matches": [ "http://*.craigslist.org/*/*.htm*" ]
} ],
... ... ...
"permissions": [ "tabs", "http://*.craigslist.org/*/*.htm*" ],
"manifest_version": 2,
"update_url": "http://clients2.google.com/service/update2/crx",
"version": "3.0"
}
Run Code Online (Sandbox Code Playgroud)
background.html:
<html>
<script type='text/javascript'>
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
});
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
的script.js: …