This is the first mechanism my chrome extension needs to perform, and I am unable to find a way to do this. I've tried using the window.getSelection().toString() / document.getSelection().toString() method, but I can only get it to work on a webpage, and I've also tried implementing an onclick function directly into the context menu object, but it did not even get the option to pop up in the context menu while I was running it. This is my manifest file so far:
{
"manifest_version": 2,
"name": "Menu",
"version": "1.0",
"icons": {
"128": "icon128.png",
"48": "icon48.png",
"16": "icon16.png"
},
"browser_action": {
"default_icon": "icon16.png"
},
"background": {
"scripts": ["eventPage.js"],
"persistent": false
},
"permissions": [
"contextMenus",
"tabs"
]
}
and this is my event page javascript file so far:
chrome.contextMenus.create({ id: "1", title: "Feature One", contexts: ["selection"] });
chrome.contextMenus.create({ id: "2", title: "Feature Two", contexts: ["selection"] });
chrome.contextMenus.create({ id: "3", title: "Feature Three", contexts: ["selection"] });
chrome.contextMenus.onClicked.addListener(function(clickData){
if (clickData.menuItemId == "1" && clickData.selectionText){
//alert("");
}
if (clickData.menuItemId == "2" && clickData.selectionText){
//alert("");
}
if (clickData.menuItemId == "3" && clickData.selectionText){
//alert("");
}
});
Thank you for reading my question