chrome: migrate Chrome extension to Manifest V3 with service worker support #1700
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.
Changes
Manifest V3 Migration (
src/manifest.json)manifest_versionfrom 2 to 3browser_actiontoactionbackground.scriptstobackground.service_workerhost_permissionsarray for required permissionsweb_accessible_resourcesto MV3 object formatService Worker Compatibility (
src/background.ts)window.cryptowithglobalThis.cryptofor service worker compatibilitywindowreferences toglobalThisto work in service worker contextbrowser.browserAction.setIcon()tobrowser.action.setIcon()for MV3 APIBrowser Detection Fix (
src/utils/utils.ts)browser.runtime.getBrowserInfoinstead ofwindow.locationwindow.locationat module load time, breaking service workersIcon Generation Dual-Path (
src/utils/utils.ts)OffscreenCanvaswith PNG sincecreateImageBitmap()doesn't support SVGtypeof window === 'undefined' || typeof document === 'undefined'Canvas Performance Optimization (
src/utils/utils.ts,src/renderer.ts){ willReadFrequently: true }to all canvas context creation to fix Chrome performance warningsWebpack Configuration (
webpack.config.js)service_workerfor backgroundscripts: ["background.js"](Firefox MV3 still supports background scripts)Why This Approach
Firefox Compatibility: Firefox MV3 background scripts retain
window/documentaccess, so webpack explicitly configures Firefox to usescriptsmode. The runtime detection ensures the existing SVG code path is taken.Chrome Service Workers: Chrome MV3 requires true service workers without DOM access, so we use OffscreenCanvas with a pre-generated PNG for icon generation.
closes #1674