diff --git a/context-menu-copy-link-with-types/background.js b/context-menu-copy-link-with-types/background.js index 9152745..1f965b7 100644 --- a/context-menu-copy-link-with-types/background.js +++ b/context-menu-copy-link-with-types/background.js @@ -1,8 +1,16 @@ +// Callback reads runtime.lastError to prevent an unchecked error from being +// logged when the extension attempt to register the already-registered menu +// again. Menu registrations in event pages persist across extension restarts. browser.contextMenus.create({ - id: "copy-link-to-clipboard", - title: "Copy link to clipboard", - contexts: ["link"], -}); + id: "copy-link-to-clipboard", + title: "Copy link to clipboard", + contexts: ["link"], + }, + // See https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/#event-pages-and-backward-compatibility + // for information on the purpose of this error capture. + () => void browser.runtime.lastError, +); + browser.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === "copy-link-to-clipboard") { // Examples: text and HTML to be copied. diff --git a/context-menu-copy-link-with-types/manifest.json b/context-menu-copy-link-with-types/manifest.json index b01b5ba..eed02e5 100644 --- a/context-menu-copy-link-with-types/manifest.json +++ b/context-menu-copy-link-with-types/manifest.json @@ -8,7 +8,8 @@ "background": { "scripts": [ "background.js" - ] + ], + "persistent": false }, "permissions": [