developit / web-worker

Consistent Web Workers in browser and Node.
https://npm.im/web-worker
Apache License 2.0
1.06k stars 55 forks source link

add `WorkerGlobalScope` to `global` #34

Open mmomtchev opened 1 year ago

mmomtchev commented 1 year ago

The specification says that the constructor should be available in the global scope.

In particular, this is a valid way to check if one is running in a web worker:

if(!(globalThis.WorkerGlobalScope instanceof Function)){

https://html.spec.whatwg.org/multipage/workers.html#the-global-scope