-
Notifications
You must be signed in to change notification settings - Fork 331
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
Consider adding self.location
to the worker global scope.
#1521
Comments
Not sure there's really sufficient use case justification for this. How would you expect to use it? I'll note that none of the other primary non-browser runtimes (node.js, deno, bun, etc) implement |
I ran into emscripten js boilerplate that does a "am I running in a web worker" check using I have a PR out for that on their side - honestly I was surprised |
For Emscripten feature detection I've been doing: // Force Emscripten to feature detect the way we want
// They used to have an `environment` setting that did this but it has been
// removed =(
globalThis.window = {}; // makes ENVIRONMENT_IS_WEB = true
globalThis.importScripts = 1; // makes ENVIRONMENT_IS_WORKER = false
const p = createEmscriptenModule(emscriptenSettings);
delete globalThis.window;
delete globalThis.importScripts;
const emscriptenModule = await p; |
Here's the PR over there in case anyone wants to +1: emscripten-core/emscripten#21010 For workerd tho, I'm still curious why |
It's also not implemented: jsg::Unimplemented importScripts(kj::String s) { return {}; };
So removing it should be pretty harmless... |
I'd be fine with removing |
We have no plans to ever implement `importScripts()` and having it defined but marked explicitly non-implemented is causing issues with using certain third-party libraries in workers. So let's just remove it entirely. Refs: #1521
We have no plans to ever implement `importScripts()` and having it defined but marked explicitly non-implemented is causing issues with using certain third-party libraries in workers. So let's just remove it entirely. Refs: #1521
Landed the PR that removes |
FWIW, the most reliable means of determining if code is running within the workers environment is to check the value of |
@jasnell, I'm getting |
@johnspurlock I'm guessing you don't have the |
@mrbbot ah right, that new worker had no compatibility flag/date at all
After redeploying with a compat date >= |
A common way for Cloudflare-unaware JS libraries to check if they are running in a web worker is:
typeof importScripts == 'function'
.Once this passes, they assume other web-standard API like
self.location
is defined.Perhaps workerd could use a blob url as the
location
here instead of leaving it undefined?The text was updated successfully, but these errors were encountered: