I have an ember application that I create like this:
window.App = Ember.Application.create({});
I want to do some background processing on a web worker.
How can I get access to the window object or some other global object in the separate web worker thread?
Since web workers are in external files, they do not have access to the following JavaScript objects: The window object. The document object.
You can have no access to the window Object from a worker.
Web Workers are primarily used for CPU-intensive tasks to be run in the background without any network connectivity required to work on the tasks.
Due to their multi-threaded behavior, web workers only has access to a subset of JavaScript's features: The navigator object. The location object (read-only) XMLHttpRequest.
Short answer. You can't.
The only resources available to web workers are that which they load from JavaScript files using importScripts()
or anything that is passed to them via postMessage()
.
You can however now pass Objects to them. They are serialized and de-serialized to JSON automatically.
Also, there is no access to local storage from the Worker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With