Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension: How to create context menu with custom name, instead of plugin name

I'm trying to create a basic chrome extension. After finding out that the root context menu can only contain one item per plugin, I wanted to at least be able to name the parent something else than my plugin name:

chrome.contextMenus.create({
    title: "Child Item 1",
    contexts:["selection"],
});
chrome.contextMenus.create({
    title: "Child Item 2",
    contexts:["selection"],
});

http://i.imgur.com/hsObtyL.png

So how do I do that?

like image 213
Aske B. Avatar asked Dec 25 '22 14:12

Aske B.


1 Answers

The way I did it, was to create a parent item with a custom title and id, and then adding all the items I needed, as children to the parent item (to my script.js file):

chrome.contextMenus.create({
    title: "Custom Parent Name",
    contexts:["selection"],
    id: "parent",
});
chrome.contextMenus.create({
    title: "Child Item 1",
    contexts:["selection"],
    parentId: "parent",
    id: "child1",
});
chrome.contextMenus.create({
    title: "Child Item 2",
    contexts:["selection"],
    parentId: "parent",
    id: "child2",
});

Here's the result:

Result

like image 160
Aske B. Avatar answered Dec 28 '22 07:12

Aske B.