Skip to content

[js/web] Use embedded WASM module in Blob URL workers when wasmBinary is provided#27318

Merged
fs-eire merged 4 commits intomicrosoft:mainfrom
0-don:fix/blob-url-worker-embedded-module
Feb 21, 2026
Merged

[js/web] Use embedded WASM module in Blob URL workers when wasmBinary is provided#27318
fs-eire merged 4 commits intomicrosoft:mainfrom
0-don:fix/blob-url-worker-embedded-module

Conversation

@0-don
Copy link
Copy Markdown
Contributor

@0-don 0-don commented Feb 11, 2026

Fixes #27317

When running inside a Blob URL Web Worker with wasmBinary provided and numThreads=1, isSameOrigin(scriptSrc) can fail because blob: URLs have opaque origins. This causes a fallback to dynamic import('./ort-wasm-simd-threaded.mjs') which doesn't exist in that context.

Since wasmBinary is already provided and no worker spawning is needed (single-threaded), the embedded Emscripten module can be used directly — no URL resolution or same-origin check is needed.

Change: One line in wasm-utils-import.ts line 275:

// Before:
useEmbeddedModule = isSameOrigin(scriptSrc);

// After:
useEmbeddedModule = isSameOrigin(scriptSrc) || (isWasmOverridden && !isMultiThreaded);

This extends the existing pattern from the !scriptSrc case (line 268) to also apply when scriptSrc is available but fails same-origin checks. The condition (wasmBinary provided + single-threaded) guarantees no file resolution or worker spawning is needed.

… is provided

When running inside a Blob URL Web Worker with wasmBinary provided and
numThreads=1, the isSameOrigin check can fail (blob: URLs have opaque
origins in some contexts), causing a fallback to dynamic import of
ort-wasm-simd-threaded.mjs which doesn't exist in that context.

Since wasmBinary is already provided and no worker spawning is needed
(single-threaded), the embedded module can be used directly without
requiring a same-origin check.

This extends the existing pattern from the !scriptSrc case (line 268)
to also apply when scriptSrc is available but fails same-origin checks.

Fixes #27317
@fs-eire
Copy link
Copy Markdown
Contributor

fs-eire commented Feb 19, 2026

/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline

@fs-eire fs-eire enabled auto-merge (squash) February 19, 2026 02:01
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@fs-eire
Copy link
Copy Markdown
Contributor

fs-eire commented Feb 19, 2026

thank you for the fix!

@fs-eire
Copy link
Copy Markdown
Contributor

fs-eire commented Feb 19, 2026

Please sync to latest main branch to pick up the CUDA build break fix.

@0-don
Copy link
Copy Markdown
Contributor Author

0-don commented Feb 19, 2026

Please sync to latest main branch to pick up the CUDA build break fix.

done

@fs-eire
Copy link
Copy Markdown
Contributor

fs-eire commented Feb 20, 2026

/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@fs-eire
Copy link
Copy Markdown
Contributor

fs-eire commented Feb 21, 2026

/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@0-don
Copy link
Copy Markdown
Contributor Author

0-don commented Feb 21, 2026

seems quite difficult to make it work 😆

@fs-eire
Copy link
Copy Markdown
Contributor

fs-eire commented Feb 21, 2026

/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

@fs-eire fs-eire merged commit 0f93853 into microsoft:main Feb 21, 2026
88 checks passed
tianleiwu pushed a commit that referenced this pull request Feb 26, 2026
… is provided (#27318)

Fixes #27317

When running inside a Blob URL Web Worker with `wasmBinary` provided and
`numThreads=1`, `isSameOrigin(scriptSrc)` can fail because blob: URLs
have opaque origins. This causes a fallback to dynamic
`import('./ort-wasm-simd-threaded.mjs')` which doesn't exist in that
context.

Since `wasmBinary` is already provided and no worker spawning is needed
(single-threaded), the embedded Emscripten module can be used directly —
no URL resolution or same-origin check is needed.

**Change:** One line in `wasm-utils-import.ts` line 275:
```typescript
// Before:
useEmbeddedModule = isSameOrigin(scriptSrc);

// After:
useEmbeddedModule = isSameOrigin(scriptSrc) || (isWasmOverridden && !isMultiThreaded);
```

This extends the existing pattern from the `!scriptSrc` case (line 268)
to also apply when `scriptSrc` is available but fails same-origin
checks. The condition (`wasmBinary` provided + single-threaded)
guarantees no file resolution or worker spawning is needed.
tianleiwu added a commit that referenced this pull request Feb 27, 2026
This cherry-picks the following commits for the release:

| Commit ID | PR Number | Commit Title |
|-----------|-----------|-------------|
| decd177 | #27090 | Fix GatherND division by zero when batch
dimensions mismatch |
| 55f8234 | #27360 | Fix QMoE CPU Operator |
| df9146f | #27403 | [MLAS] Adding DynamicQGemm function pointers and
ukernel interface |
| 0f93853 | #27318 | [js/web] Use embedded WASM module in Blob URL
workers when wasmBinary is provided |
| b2a6e69 | #27364 | QMoE CPU Performance Update (Up to 4x on 4-bit)
|
| f501e1d | #27413 | Fix refcount bug in map input conversion that
caused shutdown segfault |
| b32b205 | #27421 | Fix error where bytes is not assigned for
dynamic qgemm pack b size |
| 426b006 | #27397 | Fix DllImportResolver |
| 0982844 | #27412 | MatmulNBits prepacking scales fix |
| 9afb0d2 | #27430 | Fix validation for external data paths for
models loaded from bytes |
| 71d2cd0 | #27401 | Enable Python 3.14 CI and Upgrade Dependencies |
| 79e0676 | #27419 | fix: out of bounds access for resize operation |
| 82eb99c | #27459 | Fix SkipLayerNorm fusion incorrectly applied
when gamma/beta are not 1D |
| 355278a | #27444 | Fix GatherCopyData Integer Truncation Leading to
Heap Out-of-Bounds Read/Write |
| cf96123 | #27411 | [web] fix usage of wasmBinary together with a
blob URL for .mjs |
| 1131a86 | #27399 | [web] remove the unhelpful "Unknown CPU vendor"
warning. |
| ffbbc4f | #27316 | Build Windows ARM64X binaries as part of
packaging pipeline |

---------

Signed-off-by: Jonathan Clohessy <Jonathan.Clohessy@arm.com>
Co-authored-by: patryk-kaiser-ARM <patryk.kaiser@arm.com>
Co-authored-by: don <70039285+0-don@users.noreply.github.com>
Co-authored-by: Jonathan Clohessy <jonathan.clohessy@arm.com>
Co-authored-by: Hariharan Seshadri <shariharan91@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Adrian Lizarraga <adlizarraga@microsoft.com>
Co-authored-by: Lukas Folle <126877803+lukas-folle-snkeos@users.noreply.github.com>
Co-authored-by: Chi Lo <54722500+chilo-ms@users.noreply.github.com>
Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
Co-authored-by: Chaya <cha182350@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Erik <erscor@microsoft.com>
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants