1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

[bugfix] 解决右键菜单重复添加报错问题

This commit is contained in:
程序员小墨 2023-01-07 00:48:01 +08:00
parent 0620de4fa7
commit 0bdf1bf0df
2 changed files with 25 additions and 20 deletions

View File

@ -2,6 +2,16 @@
console.clear() console.clear()
console.log("[小墨助手]", "Service Worker init success.") console.log("[小墨助手]", "Service Worker init success.")
// 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
/** /**
* 右键菜单 * 右键菜单
*/ */
@ -22,15 +32,11 @@ chrome.contextMenus.onClicked.addListener(function (info) {
console.log("[小墨助手]", "高级搜索 已点击菜单") console.log("[小墨助手]", "高级搜索 已点击菜单")
}) })
// Events must be registered synchronously from the start of the page.
chrome.runtime.onInstalled.addListener(() => {
console.log("[小墨助手]", "chrome.runtime.onInstalled.")
chrome.contextMenus.create({ chrome.contextMenus.create({
"id": "sampleContextMenu", "id": "sampleContextMenu",
"title": "Sample Context Menu", "title": "Sample Context Menu",
"contexts": ["selection"] "contexts": ["selection"]
}); })
}); });
// //

View File

@ -56,7 +56,6 @@ var manifest = {
// "automation": {}, // "automation": {},
"background": { "background": {
// "service_worker": "scripts/service_worker/background.js"
"service_worker": "background.js" "service_worker": "background.js"
}, },