Skip to content

Fix Chrome MV3 compatibility: scripts key, duplicate context menus, getActiveFrame#71

Open
aragos wants to merge 2 commits into
keeweb:masterfrom
aragos:fix/chrome-mv3-background-scripts
Open

Fix Chrome MV3 compatibility: scripts key, duplicate context menus, getActiveFrame#71
aragos wants to merge 2 commits into
keeweb:masterfrom
aragos:fix/chrome-mv3-background-scripts

Conversation

@aragos
Copy link
Copy Markdown

@aragos aragos commented Feb 18, 2026

Summary

  • Move background.scripts from the base manifest to manifest.firefox.json so Chrome/Edge builds only include service_worker (fully MV3-compliant), while Firefox builds still get scripts as required
  • Wrap chrome.contextMenus.create calls in chrome.contextMenus.removeAll() to prevent "Cannot create item with duplicate id" errors on every MV3 service worker restart
  • Fix getActiveFrame in commands.ts: add missing return statement in injected func and read result[0].result instead of result[0] (the InjectionResult wrapper), which was producing NaN as frameId and causing chrome.tabs.sendMessage to throw

Test plan

  • Build with npm run build-chrome — confirm dist/chrome/manifest.json has no background.scripts key
  • Load dist/chrome as an unpacked extension in Chrome; confirm no "duplicate id" errors in the service worker console on reload
  • Build with npm run build-firefox — confirm dist/firefox/manifest.json still has background.scripts
  • Test autofill keyboard shortcut resolves the correct frame

Closes #64.

🤖 Generated with Claude Code

Aragos and others added 2 commits February 18, 2026 18:09
Chrome 131+ rejects MV3 extensions that have the legacy background.scripts
key, disabling the extension with "no longer supported". The key was previously
kept in the base manifest for Firefox MV3 compatibility (Firefox uses scripts
instead of service_worker).

Move background.scripts into manifest.firefox.json so it is only merged in
for Firefox builds. Chrome/Edge builds now only see service_worker, which is
fully MV3-compliant.

Fixes keeweb#64.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Frame

Two bugs causing Chrome exceptions on every service worker activation:

1. ui.ts: chrome.contextMenus.create() was called unconditionally on every
   service worker startup. In MV3, the service worker is not persistent and
   restarts on each interaction, so recreating menus with the same IDs
   threw "Cannot create item with duplicate id" for all 11 menu items.
   Fix: wrap creation in chrome.contextMenus.removeAll() callback.

2. commands.ts (getActiveFrame): the func injected via executeScript was
   missing a return statement, so it always returned undefined. The callback
   also read result[0] (the InjectionResult wrapper) instead of
   result[0].result (the actual value), so frameId was always NaN.
   Passing NaN as frameId to chrome.tabs.sendMessage throws a Chrome error.
   Fix: add return statement and read result[0].result.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chrome 131: "This extension was turned off because it's no longer supported"

1 participant