即使在堆栈溢出中搜索了很多主题之后,也没有什么能帮助我解决这个错误......
我试图创建一个扩展程序,现在其中有简单的代码,但不幸的是,控制台没有记录“Hello,world!'来自content_scripts文件。
的manifest.json
{
"manifest_version": 2,
"name": "Example",
"shortname": "exmpl",
"description": "__MSG_appDesc__",
"version": "0.0.1",
"default_locale": "en",
"author": "Mateus Akino",
"icons": {
"16": "i16x.png",
"48": "i48x.png",
"128": "i128x.png"
},
"homepage_url": "http://example.com/",
"browser_action": {
"default_icon": "i32x.png",
"default_popup": "popup.html"
},
"update_url": "http://example.com/update.xml",
"chrome_url_overrides": {
"newtab": "newtab.html"
},
"content_scripts": [{
"matches": ["*://*.youtube.com/*"],
"js": ["execute.js"],
"run_at": "document_end"
}],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"activeTab", "tabs", "i18n", "management", "webNavigation", "<all_urls>"
]
}
execute.js
console.log("Hello, world!");
background.js
chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) {
chrome.tabs.executeScript(null, {
file: "execute.js"
});
});
答案 0 :(得分:1)
我解决了这个问题,所以如果其他人有这个问题,我会在这里发帖...
好吧,看起来代码很好,但问题在于我正在加载此扩展程序... 由于我正在使用“加载解压缩的扩展程序”而我的 manifest.json 仅通过禁用和启用它来更新(立即刷新扩展程序)。
所以我删除了扩展并再次加载它现在正常工作。谢谢你们!