Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension 无法读取属性';OnConnect';_Google Chrome Extension - Fatal编程技术网

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'”

可能是您的问题

在修复完成之前,您必须在重新加载扩展之前关闭开发人员工具