-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
ort.wasm.bundle.min.mjs fails in Blob URL Web Workers due to two issues:
-
Eager URL resolution —
new URL("ort-wasm-simd-threaded.wasm", import.meta.url)throws becauseblob:URLs can't be a base for relative resolution. This runs even whenwasmBinaryis already provided. -
Same-origin check —
importWasmModulechecks if the script URL is same-origin to decide between the embedded Emscripten module and a dynamicimport('./ort-wasm-simd-threaded.mjs'). Blob URLs can fail this, triggering the import which doesn't exist.
Blob URL workers are the only option in environments where proxy = true fails (browser extensions, Electron apps with no static file serving).
Workaround
let code = readFileSync("ort.wasm.bundle.min.mjs", "utf-8");
code = code.replace(/import\.meta\.url/g, "self.location.href");
code = code.replace(/new URL\("ort-wasm-simd-threaded\.wasm",self\.location\.href\)\.href/g, '""');
code = code.replace(/export\{(.+?)\}/, (_, e) =>
`self.ort={${e.replace(/(\w+) as (\w+)/g, "$2:$1")}}`,
);Suggestion
When wasmBinary is provided + numThreads = 1: skip eager URL resolution and always use the embedded Emscripten module. A UMD/IIFE build or ort.env.wasm.skipUrlResolution flag would also help.
Environment: onnxruntime-web 1.24.1, Electron/Chromium, numThreads=1, wasmBinary from IndexedDB