diff --git a/background.js b/background.js index 1d2cd5d..f440d30 100644 --- a/background.js +++ b/background.js @@ -2,35 +2,41 @@ console.clear() console.log("[小墨助手]", "Service Worker init success.") -/** - * 右键菜单 - */ -chrome.contextMenus.create({ - id: 'bitdance', - title: '小墨助手' -}) -chrome.contextMenus.create({ - id: 'bitdance-advanced-search', - title: '高级搜索', - parentId: 'bitdance', - // onclick: function (info) { - // } -}) -chrome.contextMenus.onClicked.addListener(function (info) { - console.log('当前菜单信息:' + JSON.stringify(info)) - console.log("[小墨助手]", "高级搜索 已点击菜单") -}) // Events must be registered synchronously from the start of the page. chrome.runtime.onInstalled.addListener(() => { console.log("[小墨助手]", "chrome.runtime.onInstalled.") + + // In Chrome, you should create the context menu just once after install/update. + // refer: https://stackoverflow.com/questions/64318529/cannot-create-item-with-duplicate-context-menu-id-in-extension + + /** + * 右键菜单 + */ + chrome.contextMenus.create({ + id: 'bitdance', + title: '小墨助手' + }) + + chrome.contextMenus.create({ + id: 'bitdance-advanced-search', + title: '高级搜索', + parentId: 'bitdance', + // onclick: function (info) { + // } + }) + chrome.contextMenus.onClicked.addListener(function (info) { + console.log('当前菜单信息:' + JSON.stringify(info)) + console.log("[小墨助手]", "高级搜索 已点击菜单") + }) + chrome.contextMenus.create({ "id": "sampleContextMenu", "title": "Sample Context Menu", "contexts": ["selection"] - }); + }) }); // diff --git a/generate-manifest.js b/generate-manifest.js index 6b3a997..5f0f437 100644 --- a/generate-manifest.js +++ b/generate-manifest.js @@ -56,7 +56,6 @@ var manifest = { // "automation": {}, "background": { - // "service_worker": "scripts/service_worker/background.js" "service_worker": "background.js" },