mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
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:
@@ -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({
|
browser.contextMenus.create({
|
||||||
id: "copy-link-to-clipboard",
|
id: "copy-link-to-clipboard",
|
||||||
title: "Copy link to clipboard",
|
title: "Copy link to clipboard",
|
||||||
contexts: ["link"],
|
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) => {
|
browser.contextMenus.onClicked.addListener((info, tab) => {
|
||||||
if (info.menuItemId === "copy-link-to-clipboard") {
|
if (info.menuItemId === "copy-link-to-clipboard") {
|
||||||
// Examples: text and HTML to be copied.
|
// Examples: text and HTML to be copied.
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
"background": {
|
"background": {
|
||||||
"scripts": [
|
"scripts": [
|
||||||
"background.js"
|
"background.js"
|
||||||
]
|
],
|
||||||
|
"persistent": false
|
||||||
},
|
},
|
||||||
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
|||||||
Reference in New Issue
Block a user