Chrome 扩展:如何使用自定义名称而不是插件名称创建上下文菜单

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

我正在尝试创建一个基本的 chrome 扩展。在发现 root context menu can only contain one item per plugin 之后,我希望至少能够为父项命名而不是我的插件名称:

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

那我该怎么做呢?

我的方法是创建一个带有自定义 titleid 的父项,然后将我需要的所有项作为子项添加到父项(到我的script.js 文件):

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",
});

结果如下: