javascript - Chrome Extension Cannot Read Property create of undefined in contextMenus.create -


this contextmenus.create function throwing cannot read property of create in undefined error.

chrome.contextmenus.create({    "title": "buzz this",    "contexts": ["page", "selection", "image", "link"],    "onclick" : clickhandler    }); 

i have in same content script:

chrome.contextmenus.onclicked.addlistener(onclickhandler);  // onclicked callback function. function onclickhandler(info, tab) {      window.alert(info.srcurl);     }; 

this manifest.json

{   "name": "reportit",   "version": "0.0.1",   "manifest_version": 2,    "default_locale": "en",   "description": "immediately remove , 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"       ]      } 

all want create context menu in content script. can see problem?

you cannot use chrome apis in content scripts. instead, create background page , create context menu there when receives message content script. when background page receives click event, send message content script.

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


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -