Chrome扩展程序无法读取属性在contextMenus.create中创建未定义

Dav*_*don 5 javascript google-chrome-extension

这是我的contextMenus.create函数,它在未定义的错误中抛出了 create的无法读取属性.

chrome.contextMenus.create({
   "title": "Buzz This",
   "contexts": ["page", "selection", "image", "link"],
   "onclick" : clickHandler
   });
Run Code Online (Sandbox Code Playgroud)

我也在相同的内容脚本中有这个:

chrome.contextMenus.onClicked.addListener(onClickHandler);

// The onClicked callback function.
function onClickHandler(info, tab) {
     window.alert(info.srcUrl);    
};
Run Code Online (Sandbox Code Playgroud)

这是我的manifest.json

{
  "name": "ReportIt",
  "version": "0.0.1",
  "manifest_version": 2,

  "default_locale": "en",
  "description": "Immediately Remove and Report",
  "icons": {
   "16": "images/icon-128.png",
   "128": "images/icon-128.png"
   },


   "content_scripts": [{
    "matches": ["<all_urls>"],
    "js": ["scripts/contentscript.js"],
    "run_at": "document_end",
    "all_frames": false
    }],

      "permissions": [
      "http://*/*",
      "https://*/*",
      "contextMenus"
      ],

      "content_security_policy": "script-src 'self'; object-src 'self'",
      "web_accessible_resources": 
      [
      "bower_components/angular/*",
      "scripts/background.js"
      ]

    }
Run Code Online (Sandbox Code Playgroud)

我想要做的就是在内容脚本中创建一个上下文菜单.有谁能看到这个问题?

Dan*_*err 14

您不能在内容脚本中使用大多数chrome apis.而是在从内容脚本接收消息时创建后台页面并在其中创建上下文菜单.当后台页面收到click事件时,向内容脚本发送一条消息.

https://developer.chrome.com/extensions/messaging