Fix Chrome MV3 compatibility: scripts key, duplicate context menus, getActiveFrame#71
Open
aragos wants to merge 2 commits into
Open
Fix Chrome MV3 compatibility: scripts key, duplicate context menus, getActiveFrame#71aragos wants to merge 2 commits into
aragos wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
background.scriptsfrom the base manifest tomanifest.firefox.jsonso Chrome/Edge builds only includeservice_worker(fully MV3-compliant), while Firefox builds still getscriptsas requiredchrome.contextMenus.createcalls inchrome.contextMenus.removeAll()to prevent "Cannot create item with duplicate id" errors on every MV3 service worker restartgetActiveFrameincommands.ts: add missingreturnstatement in injectedfuncand readresult[0].resultinstead ofresult[0](theInjectionResultwrapper), which was producingNaNasframeIdand causingchrome.tabs.sendMessageto throwTest plan
npm run build-chrome— confirmdist/chrome/manifest.jsonhas nobackground.scriptskeydist/chromeas an unpacked extension in Chrome; confirm no "duplicate id" errors in the service worker console on reloadnpm run build-firefox— confirmdist/firefox/manifest.jsonstill hasbackground.scriptsCloses #64.
🤖 Generated with Claude Code