Skip to content

onnxruntime-web: Bundle variant fails in Blob URL Web Workers #27317

@0-don

Description

@0-don

ort.wasm.bundle.min.mjs fails in Blob URL Web Workers due to two issues:

  1. Eager URL resolutionnew URL("ort-wasm-simd-threaded.wasm", import.meta.url) throws because blob: URLs can't be a base for relative resolution. This runs even when wasmBinary is already provided.

  2. Same-origin checkimportWasmModule checks if the script URL is same-origin to decide between the embedded Emscripten module and a dynamic import('./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

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform:webissues related to ONNX Runtime web; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions