Make background script of context-menu-copy-link-with-types non-persistent? (#501)

* Made background script of context-menu-copy-link-with-types non-persistent. Now clearing errors that could result from background.js context menu creation happening more than once.

* Suggestions from code review

* Syntax error and formatting

* Added note about () => void browser.runtime.lastError

* Feedback suggestion

Co-authored-by: Rob Wu <rob@robwu.nl>

---------

Co-authored-by: rebloor <git@sherpa.co.nz>
Co-authored-by: Rob Wu <rob@robwu.nl>
This commit is contained in:
Aram Panasenco
2023-03-18 10:20:33 -06:00
committed by GitHub
parent 0d9c6623fb
commit a2da599980
2 changed files with 14 additions and 5 deletions

View File

@@ -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.

View File

@@ -8,7 +8,8 @@
"background": {
"scripts": [
"background.js"
]
],
"persistent": false
},
"permissions": [