Accessing localStorage from a webWorker

前端 未结 4 779
灰色年华
灰色年华 2020-11-28 06:21

Can a WebWorker access the localStorage?

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

4条回答
  •  天命终不由人
    2020-11-28 06:25

    Web workers only have access to the following:

    • XMLHttpRequest
    • Application Cache
    • Create other web workers
    • navigator object
    • location object
    • setTimeout method
    • clearTimeout method
    • setInterval method
    • clearInterval method
    • Performance object (mark,measure,now methods: caniuse?)
    • IndexedDB API (see: caniuse?)
    • importScripts method
    • JSON
    • Worker

    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.

提交回复
热议问题