Reputation: 51
I'm trying to create a right-click context menu for Chrome. I want to be able to highlight text, right click, then click to open a new tab using a URL determined by the highlighted text.
I have a manifest (though I'm not sure I've done the background part right):
{
"manifest_version": 2,
"name": "ClickMenu",
"version": "1.0",
"description": "A right-click context menu",
"icons": {
"16": "icons/icon-16.png",
"48": "icons/icon-48.png",
"128": "icons/icon-128.png"
},
"permissions": [ "contextMenus" ],
"background": {
"scripts": ["contextMenu.js"],
"persistent": false
}
}
And a contextMenu.js:
function MenuContext(contextInfo, tab) {
chrome.tabs.create({
'url' : 'https://myurl.com/' + contextInfo.selectionText + '/launch'
});
}
var contextId = chrome.contextMenus.create({
'title' : 'Launch this',
'contexts' : [
'selection'
],
'onclick' : MenuContext
});
It's not working. I can load the extension, but there's no context menu or functionality.
Can you see what I've done wrong?
Upvotes: 1
Views: 2518
Reputation: 1144
You create an event page (bacause in your manifest you define "persistent": false
).
In event page you to do three changes when you create context menu item.
chrome.contextMenus.onClicked
callback instead of an onclick parameter.chrome.runtime.onInstalled
event.For more information - Event pages best practices.
(By the way - in event page don't save data in variables).
(I'm sorry about my english...)
Upvotes: 1