Google chrome extension 无法读取属性';OnConnect';
我试图按照这里的文档将变量从后台脚本传递到内容脚本 舱单:Google chrome extension 无法读取属性';OnConnect';,google-chrome-extension,Google Chrome Extension,我试图按照这里的文档将变量从后台脚本传递到内容脚本 舱单: { "name": "name", "description": "desc", "version": "1.0", "manifest_version": 2, "content_scripts": [ { "matches": [ "http://*/*", "https://*/*" ], "js": ["content.js"] } ], "backgroun
{
"name": "name",
"description": "desc",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*" ],
"js": ["content.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"options_page": "options.html",
"browser_action":
{
"default_icon": "icon.png",
"default_title": "Settings",
"default_popup": "settingspanel.html"
}
}
background.js文件:
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
port.postMessage({counter: msg.counter+1});
});
});
content.js
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
sendResponse({counter: request.counter+1});
});
我在后台脚本上收到一个错误,上面写着“无法读取未定义的属性'onConnect'”可能是您的问题
在修复完成之前,您必须在重新加载扩展之前关闭开发人员工具