我制作了一个简单的Chrome扩展程序,其中我试图在这些特定网页中包含内容脚本。但问题是他们没有被纳入网站。我使用Chrome的开发者工具工具进行了检查。 然后我将match_urls设置为所有页面,但仍然没有包含它们。
这里是 manifest.json :
{
"manifest_version": 2,
"name": "TestExten",
"description": "Test description.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"run_at": "document.end",
"js": ["content.js"]
}
],
"permissions": [
"tabs",
"http://*/", "https://*/",
"cookies"
],
}
和 content.js :
alert("loaded");
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
alert("received message");
});
这里出了什么问题?
答案 0 :(得分:1)
看看这里:https://developer.chrome.com/extensions/content_scripts
参数run_at
接受document_end
,而非document.end
。所以你的清单应该是这样的:
{
"manifest_version": 2,
"name": "TestExten",
"description": "Test description.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"run_at": "document_end",
"js": ["content.js"]
}
],
"permissions": [
"tabs",
"http://*/", "https://*/",
"cookies"
],
}