Accessing localStorage from a webWorker

ciochPep picture ciochPep · May 30, 2011 · Viewed 31.7k times · Source

Can a WebWorker access the localStorage?

If not why not? Is it problematic from a security stand point?

Answer

filipe picture filipe · May 30, 2011

Web workers only have access to the following:

The window or parent objects are not accessible from a Web worker therefore you can't access the localStorage.

To communicate between window and the workerglobalscope you may use postMessage() function and onmessage event.

Accessing the DOM and window would not be thread safe, since the child thread would have the same privileges as its parent.