-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make background script of context-menu-copy-link-with-types non-persistent? #501
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contextMenus.create call in the background page is going to result in an inresolved error, when it wakes up, because the menu will be registered twice. To avoid logspam, check the error by reading the lastError property.
This can be done by adding a callback with void browser.runtime.lastError;
and adding a comment before that explaining why it's needed.
I finally found the error message you were referring to in the Multiprocess Browser Console (Ctrl+Shift+J -> Multiprocess): I also realized that menu-demo already has an example of the creation callback. I'll force-push an update with the changes you proposed. I also realized that event pages (non-persistent background scripts) are not supported on current stable FF (105), so I added the "strict_min_version" setting and set it 106.0. Haven't tested yet on FF 106 myself yet though... |
…stent. Now clearing errors that could result from background.js context menu creation happening more than once.
Nope, didn't see it there at all. It might be related to bug 1410932.
Yup, it works on 105, no problem. |
@@ -3,12 +3,18 @@ | |||
"name": "Context menu: Copy link with types", | |||
"description": "Add a context menu option to links to copy the link to the clipboard, as plain text and as a link in rich HTML.", | |||
"version": "1.0", | |||
"browser_specific_settings": { | |||
"gecko": { | |||
"strict_min_version": "106.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this addition since it's not needed.
@@ -1,8 +1,12 @@ | |||
// Callback clears runtime.lastError to prevent logspam errors from the menu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change it to:
"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."
Co-authored-by: Rob Wu <rob@robwu.nl>
@panasenco many thanks for kicking this off |
Mozilla documentation recommends changing background scripts to non-persistent to ensure future compatibility with Manifest V3.
I'm pretty sure the example
context-menu-copy-link-with-types
can be made non-persistent as-is. I tested in Firefox and all the functionality seems to work after switching it to non-persistent.However, I'm not super familiar with background script persistence, so if there are gotchas I missed, let me know!