Skip to content
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

runtime.onInstalled use in event pages clarification #29716

Merged

Conversation

rebloor
Copy link
Contributor

@rebloor rebloor commented Oct 19, 2023

Description

Add an explanation as to why stateful API should be included in the onInstalled for event pages. Fixed #17212

@rebloor rebloor added the Content:WebExt WebExtensions docs label Oct 19, 2023
@rebloor rebloor self-assigned this Oct 19, 2023
@rebloor rebloor requested a review from a team as a code owner October 19, 2023 02:12
@rebloor rebloor requested review from Rob--W and removed request for a team October 19, 2023 02:12
@github-actions
Copy link
Contributor

github-actions bot commented Oct 19, 2023

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that more details are needed before #17212 can be marked as resolved.

The Extension Workshop has a lot of detail on the persistence of menu items across restarts. The short version is that in Firefox, menu items are not persisted in persistent background pages (a persistent background page starts up once and doesn't terminate until the browser or extension unloads, so a top-level create call will always create the menu), and persisted in non-persistent background pages (aka event page; to avoid repeated attempts to create the menu item, it should be registered only once).

Can you clarify the documentation to reduce this confusion? E.g. by adding a NOTE and more details (maybe even a link to Extension workshop?) in the menus.create article on MDN.

@rebloor rebloor requested a review from Rob--W October 25, 2023 17:37
@@ -21,6 +21,8 @@ Except for [`menus.getTargetElement()`](/en-US/docs/Mozilla/Add-ons/WebExtension

To create a menu item call the {{WebExtAPIRef("menus.create()")}} method. You pass this method an object containing options for the item, including the item ID, item type, and the contexts in which it should be shown.

In an extension using non-persistent [background pages](/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts) (Event pages), you call `menus.create` from within a {{WebExtAPIRef("runtime.onInstalled")}} listener. In an extension using persistent background pages, you make a top-level call. See {{WebExtAPIRef("menus.create()")}} for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is Firefox/Chrome-dependent.

@rebloor rebloor requested a review from Rob--W October 27, 2023 01:42
@rebloor rebloor merged commit bf45251 into mdn:main Oct 27, 2023
6 checks passed
@rebloor
Copy link
Contributor Author

rebloor commented Oct 27, 2023

Thanks @Rob--W

@rebloor rebloor deleted the runtime.onInstalled-use-in-event-pages-clarification branch October 27, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebExt WebExtensions docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example code works via web-ext run but not after packaging into an XPI
2 participants