无法调用未定义的chrome-extension方法'create'

lug*_*ger 3 google-chrome-extension

当我完成我的chrome扩展时,我发现它是一个错误:

 Uncaught TypeError: Cannot call method 'create' of undefined chrome-extension://dpfgkakomehcgdcnigflmkcfngeaamlc/js/background.js:46
Run Code Online (Sandbox Code Playgroud)

injectScript startLiveReload init

我用它就是这个

mainfest.json"background":{"scripts":["js/background.js"]}

和background.js一样

var readMenuItemId = chrome.contextMenus.create({
  "title" : "????",
  "type" : "normal",
  contexts : [ "selection" ],
  documentUrlPatterns: ["http://*/*", "https://*/*"],
  "onclick" : genericOnClick
});
Run Code Online (Sandbox Code Playgroud)

我不知道哪里出错了

KiL*_*KiL 7

您需要contextMenus在清单文件中添加权限才能使用此对象:

"permissions": [
    "contextMenus"
],
Run Code Online (Sandbox Code Playgroud)