Phonegap and WebWorkers

前端 未结 3 1892
旧时难觅i
旧时难觅i 2021-02-13 21:24

I am trying to write a PhoneGap/Cordova app.

I am trying to do some of the more long running background stuff in Web Workers. However I am finding that some of the funct

3条回答
  •  星月不相逢
    2021-02-13 21:45

    Due to the fact that your Web Workers run outside of the main application thread they do not have the same access to JavaScript features as your main application does. Your workers do not have access to:

    • The DOM
    • The document object
    • The window object
    • The parent object

    If you want your application in the UI thread to communicate with a worker you need to pass the object through the message. But since worker accepts string, you can use JSON.parse() or JSON.stringify() to successfully send the object.

提交回复
热议问题