Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: mainScriptUrlOrBlob ignored when USE_ES6_IMPORT_META is off #23769

Open
JoeOsborn opened this issue Feb 26, 2025 · 3 comments
Open

Comments

@JoeOsborn
Copy link
Contributor

Per #23171 (comment)

The recent removal of USE_ES6_IMPORT_META broke a use case like this:

  1. I want to host an emscripten-compiled package somewhere (e.g., a CDN) that is compiled to use pthreads
  2. I want to instantiate a module from those scripts on another origin domain
  3. Browsers refuse to download cross-origin workers, so I can't create threads.

This used to be supported using either an importScripts() hack in the worker or by downloading the whole script as a blob, but now that's not possible since the fix in #23171 forces the use of a specific file name.

@JoeOsborn
Copy link
Contributor Author

For a bit more detail: Using a blob as the actual script means that import.meta.url is a blob, so new URL(...) can't work. Using a mainScriptBlobOrUrl is just ignored. So both of the tricks I've used in the past for cross origin workers are not available.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 26, 2025

Thanks Joe! We are obviously lacking some test coverage here.

@JoeOsborn
Copy link
Contributor Author

I think a reasonable fix for this is to:

  1. If mainScriptUrlOrBlob is set, create the worker as in the old non-use-import-meta case (or else deprecate that field under export_es6 and assert that mainScriptUrlOrBlob is not set)
  2. If import.meta.url is a blob url, use it instead of creating a new URL.

JoeOsborn added a commit to JoeOsborn/emscripten that referenced this issue Feb 28, 2025
Per the discussion in emscripten-core#23769, implement this policy:

- If mainScriptUrlOrBlob is set, create the worker as in the old non-use-import-meta case
- If import.meta.url is a blob url, use it for the worker script
- Otherwise, use new URL(TARGET_JS_NAME, import.meta.url)
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

No branches or pull requests

2 participants