Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web workers and accessing object attached to the window object

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?

like image 782
dagda1 Avatar asked Jun 08 '12 08:06

dagda1


People also ask

Does web worker have access to window?

Since web workers are in external files, they do not have access to the following JavaScript objects: The window object. The document object.

Can Webworker access Windows object?

You can have no access to the window Object from a worker.

What are web workers used for?

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.

Which object web workers have read only access?

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.


1 Answers

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.

like image 72
Jivings Avatar answered Nov 14 '22 21:11

Jivings