我尝试根据示例构建简单的扩展:
从这里和这里
,我一定是在这里做错了什么。
我想要的只是在每个加载页面上开始(甚至在加载之前更好)它会弹出你好警报
清单.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 现在是空的
内容脚本.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:
alert("this is script");
即使我触发开发者控制台窗口也没有错误。