Skip to content

[Web] Ort tries (and fails) to fetch an .mjs file from localhost when imported through importScripts() using a CDN url in a web worker #24325

Description

@andynewman10

Describe the issue

I can succesfully use the ONNX runtime on the web from my main web page, using the following CDN URL and an async SCRIPT tag:

https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort.all.min.js

Execution providers such as WASM or WebGPU are working fine.

However, when I do exactly the same thing from a web worker, using importScripts, the importScripts statement runs fine, but the promise returned by ort.InferenceSession.create cannot be waited for - instead, an error happens (see below).

I am not sure what to do at this point. Is this a bug or is this limitation a by-design limitation of web workers? Shall I just host all ORT files on my web server?

My setup:

  • Windows 11 24H2
  • same result with both Chrome 134 or Edge 135.
  • nVidia GTX 1060 GPU with latest drivers

To reproduce

From a web worker:

importScripts("https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.1/dist/ort.all.min.js"); // succeeds
let onnxRT = ort.InferenceSession.create("http://localhost:7500/model.onnx", {'executionProviders': ['webgpu']}); // succeeds
let awaited = await onnxRT ; // does not succeed

The error is:

http://localhost:7500/ort-wasm-simd-threaded.jsep.mjs
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

no available backend found. ERR: [webgpu] TypeError: Failed to fetch dynamically imported module: http://localhost:7500/ort-wasm-simd-threaded.jsep.mjs

(here it basically says it cannot fetch the resource, this is not a MIME type issue).

Urgency

No response

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

See above CDN url.

Execution Provider

'webgpu' (WebGPU)

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeapi:Javascriptissues related to the Javascript APIep:WebGPUort-web webgpu providerplatform: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