Skip to content

menu-demo to Manifest v3#634

Open
rebloor wants to merge 3 commits into
mdn:mainfrom
rebloor:menu-demo-to-MV3
Open

menu-demo to Manifest v3#634
rebloor wants to merge 3 commits into
mdn:mainfrom
rebloor:menu-demo-to-MV3

Conversation

@rebloor
Copy link
Copy Markdown
Collaborator

@rebloor rebloor commented May 27, 2026

Description

This change migrates the menu-demo example to manifest V3. To do this, these changes were made:

manifest.json

  • manifest_version upgraded from 2 to 3
  • Background script converted to non-persistent event page (scripts array)
  • Added "scripting" permission (required by the Scripting API)
  • Extension ID added: menu-demo@mozilla.org
  • strict_min_version updated from 56.0a1 to 109.0 (minimum for MV3)
  • data_collection_permissions key added with "required": ["none"]
  • open_at_install: false added to sidebar_action to suppress automatic sidebar opening on install

background.js

  • All menu item creation moved inside browser.runtime.onInstalled.addListener() — the correct pattern for non-persistent backgrounds, since menus persist across restarts but the top-level code would otherwise re-run each time the background wakes
  • browser.tabs.executeScript replaced with browser.scripting.executeScript using func and args instead of an inline code string
  • let blue/green (code strings) replaced with const blue/green (border value strings)
  • removing.then(...) inlined to browser.menus.remove(...).then(...)
  • Minor typo fix in a comment: "only work" → "only works"

examples.json

  • runtime.lastError replaced with runtime.onInstalled
  • tabs.executeScript replaced with scripting.executeScript

messages.json

  • Changed the sidebar menu label to "Toggle sidebar" to more accurately reflect behavior

README.md

  • Clarified that additional changes, beyond the use of the contextMenus alias are needed to run on Chrome.
  • minor edits.

@rebloor rebloor requested review from Rob--W and bacharakis May 27, 2026 22:30
@rebloor rebloor self-assigned this May 27, 2026
@rebloor rebloor requested a review from a team as a code owner May 27, 2026 22:30
@rebloor rebloor added the enhancement Improves an existing repo feature. label May 27, 2026
@rebloor rebloor requested a review from caugner May 27, 2026 22:30
Copy link
Copy Markdown
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.

Looks good with minor adjustments.

Comment thread menu-demo/background.js Outdated
Comment thread menu-demo/background.js
*/
function onCreated() {
if (browser.runtime.lastError) {
console.log(`Error: ${browser.runtime.lastError}`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

menus.create is special, unlike many other extension APIs it does not return a Promise even though it is async.

I think that it would still be useful to log an error to show how error handling works. The "Item created successfully" part can be dropped though.

The console.log call should include a .message though, as in: browser.runtime.lastError.message

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@Rob--W done, plus some tweaks to the comments

Comment thread examples.json
"menus.onClicked",
"menus.remove",
"menus.update",
"runtime.lastError",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Keep runtime.lastError as an example, see my comment in background.js.

@rebloor rebloor requested a review from Rob--W May 28, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improves an existing repo feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants