fix: use static import + initSync for WASM in service worker

Chrome MV3 service workers do not support dynamic import().
Switch to static import of the wasm-pack JS glue and use
initSync() with fetch() to load the WASM binary at runtime.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
adlee-was-taken
2026-04-12 11:37:44 -04:00
parent 8236a18433
commit 336e90fc84
2 changed files with 23 additions and 18 deletions

View File

@@ -8,14 +8,16 @@ import type { GitHost } from './git-host';
import type { Entry, Manifest, ManifestEntry } from '../shared/types';
// WASM module reference — set once during init.
let wasm: typeof import('idfoto-wasm') | null = null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let wasm: any = null;
/// Store the WASM module reference after dynamic import.
export function setWasm(w: typeof import('idfoto-wasm')): void {
/// Store the WASM module reference after initialization.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function setWasm(w: any): void {
wasm = w;
}
function requireWasm(): NonNullable<typeof wasm> {
function requireWasm(): any {
if (!wasm) throw new Error('WASM module not initialized');
return wasm;
}