因此,我查看了有关此主题的所有其他 Stack Overflow 帖子,逐行更改了所有内容,但没有任何效果。(没关系,这段代码的 99% 直接来自 dev.google.com)无论我尝试什么,我都会得到标题中提到的错误。似乎没有任何解释,所以我希望这个小组能够发现我遗漏的潜在愚蠢的东西。谢谢!
清单.json
{
"manifest_version": 2,
"name": "Topic Fetch",
"description": "This extension extracts the meta keywords from a news article and give you related articles from Google News",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_title" : "Get Related Links"
},
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["Content-Script.js"],
"run_at": "document_end"
}
],
"permissions": [
"tabs","<all_urls>",
"activeTab"
]
}
背景.js
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
console.log(tabs);
chrome.tabs.sendMessage(tabs[0].id, "message", function(response) {
alert(response);
});
});
内容脚本.js
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
sendResponse('Hello!');
});
编辑:这是我正在使用的代码(大部分)和有关在 Chrome 扩展中传递消息的信息:https ://developer.chrome.com/extensions/messaging.html