Conversation
| // Global object | ||
| else if (typeof WorkerGlobalScope === "function" && self instanceof WorkerGlobalScope) { | ||
| // Web Worker scope | ||
| self.msgpack = msgpack; |
There was a problem hiding this comment.
Would it make sense (or is it even possible) to let the name "msgpack" be configured in this case as well like for the browser below?
There was a problem hiding this comment.
No, since a web worker runs in a different execution thread and has no access to the window object.
There was a problem hiding this comment.
even on main document, the self or globalThis is valid, can check and use it in both world?
There was a problem hiding this comment.
@ygoe any news on the PR?
even on main document, the
selforglobalThisis valid, can check and use it in both world?
Not sure what do you mean.
I am using the self object because of how script importing works in a Web Worker scope.
In a browser scope, I am not sure what would the difference be between using self or window, but I'm guessing it's the same.
There was a problem hiding this comment.
Looks like self has been here since forever. Didn't know that.
So maybe the solution would be to just replace window with self everywhere? No additional check case needed.
fixes issues #12 and #35
It now detects the Web Worker scope properly and can be imported in a Web Worker with
self.importScripts.Note: The minified build has not been rebuilt!