[英]Chrome extension Script Injection to each open tab
I tried to build simple extension according to the examples: from here and here 我尝试根据示例构建简单的扩展: 从这里到这里
and I must be doing something wrong here. 我在这里一定做错了。
All I want is for start that on each loading page ( or even better before loading ) it will popup hello alert 我想要的只是在每个加载页面上启动(甚至加载之前更好),它将弹出hello警报
manifest.json manifest.json
{
"background": {
"page": "background.html"
},
"content_scripts": [
{
"matches": ["http://*/*","https://*/*"],
"js": ["jquery-1.8.2.min.js","contentscript.js"],
"run_at": "document_end"
}
],
"web_accessible_resources": [
"script_inpage.js"
],
"browser_action": {
"default_popup": "popup.html",
"default_title": "Test 123"
},
"content_security_policy": "script-src 'self'; media-src *; object-src 'self'",
"description": "Simple Test 123.",
"manifest_version": 2,
"minimum_chrome_version": "18",
"name": "Test 123",
"permissions": [
"unlimitedStorage",
"http://*/",
"tabs",
],
"version": "2.6"
}
background.html is empty for now background.html目前为空
contentscript.js: contentscript.js:
var s = document.createElement('script');
s.src = chrome.extension.getURL('script_inpage.js');
(document.head||document.documentElement).appendChild(s);
s.onload = function() {
s.parentNode.removeChild(s);
};
script_inpage.js: script_inpage.js:
alert("this is script");
There is no error even when I trigger the developer console window. 即使触发开发人员控制台窗口也没有错误。
Your manifest file is invalid, there's a superfluous comma after the last entry in the "permissions"
section: 您的清单文件无效, "permissions"
部分中的最后一个条目后面有多余的逗号:
"permissions": [
"unlimitedStorage",
"http://*/",
"tabs", // <-- Remove that comma
],
If you want your script to run as early as possible, use "run_at": "document_start"
instead of "document_end"
. 如果希望脚本尽早运行,请使用"run_at": "document_start"
而不是"document_end"
。 Then, your script will run before <head>
and <body>
even exist. 然后,您的脚本将在<head>
和<body>
出现之前运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.