Skip to content

Commit a2da599

Browse files
panasencorebloorRob--W
authored
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>
1 parent 0d9c662 commit a2da599

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

context-menu-copy-link-with-types/background.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
// Callback reads runtime.lastError to prevent an unchecked error from being
2+
// logged when the extension attempt to register the already-registered menu
3+
// again. Menu registrations in event pages persist across extension restarts.
14
browser.contextMenus.create({
2-
id: "copy-link-to-clipboard",
3-
title: "Copy link to clipboard",
4-
contexts: ["link"],
5-
});
5+
id: "copy-link-to-clipboard",
6+
title: "Copy link to clipboard",
7+
contexts: ["link"],
8+
},
9+
// See https://extensionworkshop.com/documentation/develop/manifest-v3-migration-guide/#event-pages-and-backward-compatibility
10+
// for information on the purpose of this error capture.
11+
() => void browser.runtime.lastError,
12+
);
13+
614
browser.contextMenus.onClicked.addListener((info, tab) => {
715
if (info.menuItemId === "copy-link-to-clipboard") {
816
// Examples: text and HTML to be copied.

context-menu-copy-link-with-types/manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"background": {
99
"scripts": [
1010
"background.js"
11-
]
11+
],
12+
"persistent": false
1213
},
1314

1415
"permissions": [

0 commit comments

Comments
 (0)