Chrome extension cannot read create undefined property in context of Menus.create

This is my contextMenus.create function, which throws cannot read the create property in an undefined error.

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

I also have this in the same content script:

 chrome.contextMenus.onClicked.addListener(onClickHandler); // The onClicked callback function. function onClickHandler(info, tab) { window.alert(info.srcUrl); }; 

This is my 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" ] } 

All I want to do is create a context menu in the content script. Can anyone see the problem?

+5
source share
1 answer

You cannot use most chrome apis in content scripts. Instead, create a background image and create a context menu there when it receives a message from the contents of the script. When the background page receives a click event, send a message to the content script.

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

+10
source

All Articles