<分区>
我正在尝试设置我的 content_script.js 以将消息发送到 background.js。 Background.js 能够接收消息并对其执行操作,但 content_script.js 无法接收/打印它。
content_script.js
chrome.runtime.sendMessage({method: "getSettings"}, function(response) {
console.log(response.data);
console.log("This is not printing either");
});
背景.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == "getSettings") {
chrome.storage.sync.get(null, function (val) {
sendResponse({data: "test"});
console.log("Responding: " + val.radioSettings);
});
}
});
background.js 中的 Console.log 打印来自 chrome.storage 的正确消息,但我的 content_script.js 中的 console.log 从不打印。
我觉得这很接近,但只是缺少一些小东西。这是我的 list 的一部分:
list .json
{
"version": "0.0.1",
"manifest_version": 2,
"browser_action": {
"default_icon": "icons/icon19.png",
"default_popup": "popup.html"
},
"background": {
"scripts": ["js/background.js"]
},
"permissions": [
"storage",
"tabs"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["js/jquery-1.11.3.min.js", "js/content_script.js"]
}
]
}