0

Im trying to make an extension for chrome, that based on an options.html page will allow certain context menu items to show up. I know there is the Demo of 'Global Context Search' made by google. But I want a selection of urls to appear based on the users choice.

chrome.storage.onChanged.addListener(function(list, sync) {
let newlyDisabled = [];
let newlyEnabled = [];
let currentRemoved = list.nrMenu.newValue;
let oldRemoved = list.nrMenu.oldValue || [];
for (let key of Object.keys(nrAgentList)) {
if (currentRemoved.includes(key) && !oldRemoved.includes(key)) {
  newlyDisabled.push(key);
} else if (oldRemoved.includes(key) && !currentRemoved.includes(key)) 
{
  newlyEnabled.push({
    id: nrAgentList[key],
    title: key
  });
}
}
for (let locale of newlyEnabled) {
     var locale.title = chrome.contextMenus.create({title: locale.id+'+'+locale.title+"+"+ locale , id: locale.title});

console.log(locale.title);
console.log("Enabled");
console.log(newlyEnabled);
 }
});

So in theory when the ParentID is called above with the value APM, I want it to pass in the links below to appear in the context menu.

var Installation_APM = chrome.contextMenus.create({title: "Installation", "parentId": APM,});
   chrome.contextMenus.create({title: "Link1", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://link1.com"});}});
   chrome.contextMenus.create({title: "Link2", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://link2.com"});}});
   chrome.contextMenus.create({title: "link3", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://Link3.com"});}});
   chrome.contextMenus.create({title: "Link4", "parentId": Installation_APM, "onclick": function(e){chrome.tabs.create({"url": "https://Link4.com"});}});

Im guessing that Im missing something fundamental, if you could point me in the right direction I would be grateful.

Nemothefish
  • 47
  • 10
  • 1
    Do you see any errors in the devtools console? What's your manifest.json? If you have a background page, [check that too](https://stackoverflow.com/a/10258029). My guess is you must call chrome.contextMenus.create from your background/event page because otherwise Chrome is unable to run the callback. – wOxxOm Aug 21 '18 at 17:23
  • No Im not getting any errors in the console.... it just doesn't pick up the connection. would you know where I might find examples of something similar to what Im trying to achieve – Nemothefish Aug 22 '18 at 12:26

0 Answers0