Skip to content

Commit

Permalink
Make background script of context-menu-copy-link-with-types non-persi…
Browse files Browse the repository at this point in the history
…stent? (#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>
  • Loading branch information
3 people committed Mar 18, 2023
1 parent 0d9c662 commit a2da599
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions context-menu-copy-link-with-types/background.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion context-menu-copy-link-with-types/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"background": {
"scripts": [
"background.js"
]
],
"persistent": false
},

"permissions": [
Expand Down

0 comments on commit a2da599

Please sign in to comment.