D
D
dllweb2016-05-27 20:44:26
JavaScript
dllweb, 2016-05-27 20:44:26

Duplicating context menu, where to initialize menu in extension?

Good day.
Dear, I encountered the following problem when creating an extension for Chrome.
The essence of the problem, I don’t know where to place the code that initializes the creation of the context menu

chrome.contextMenus.create({
      "title": "Сохранить",
      "contexts": ["image"],
      "onclick" : function(OnclickData, tab){
      				var current = localStorage.active;
            var url_pic = OnclickData.srcUrl;
            var sendData = { "group_id": current, "src_link": url_pic };
          }
    });

I place it in background.js which is essentially the background in the extension.
And now, the problem is, every time the popup extension is opened, the context menu tab is
duplicated
, and I need to open it in order to change and store the extension settings there.
e87dd6307ac947ae9b8b1c7a3892e0e7.png
Can you please tell me where to start creating the context menu?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OVK2015, 2016-05-27
@dllweb

У меня вот так сделано в background.js:
var rootItem, translateItem;

function createContextMenu()
{
....
rootItem = chrome.contextMenus.create
    (
      {
        id: "utilsExtRootMenuItem",
        title: "Утилиты",
        contexts: ["all"]
      }, 
      function(){}
    );

translateItem = chrome.contextMenus.create
    (
      {
        id: "utilsExtTranslateMenuItem",
        parentId: rootItem,
        title: "Перевести...",
        contexts: ["all"],
        onclick: translateWithWordReference
      }, 
      function(){}
    );	
....
}
function translateWithWordReference()
{
....
}
createContextMenu();

Everything works as it should.

#
#algooptimize #bottize, 2016-05-27
@user004

https://developer.chrome.com/extensions/samples#se...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question