6

I am trying to utilise web workers in a webOS for signage application due to an odd bug where times between executing file downloads using the SCAP API slows down exponentially.

My idea was to try web workers to download the files, hopefully meaning the issue would go away/the app would be a bit snappier.

However, the SCAP API is based on Cordova and its seems Cordova needs to access the Window object, something a Web Worker cannot do it seems (I finally found out after hours of trying!)

My question is, is there anyway at all to get a web worker to work in conjunction with Cordova?

Are there any other types of workers that can access the window object?

Basically, is there any solution to this at all? Or is it 100% impossible and futile to attempt?

Mr Pablo
  • 4,109
  • 8
  • 51
  • 104
  • 1
    `Worker`s cannot directly reach a `window`, ever. you might be able to rewrite the API calls to not use anything that's window-only. you could download in a worker using ajax, and the transfer the blob via `postMessage()` to `window` at the last moment to download it to the OS. – dandavis Sep 11 '15 at 16:33
  • Yea, that was my next idea, to use XHR to download the files. But passing the blob through to the main app doesn't seem like it would make anything better. Unless the worker could write the file itself, is that possible? – Mr Pablo Sep 11 '15 at 16:40
  • afaik, no environ provides Workers with any call that could be used to save a file; namely `window.open()`, `msSaveBlob()`, or `a[download].click()`... you might be able to create a cordova app that runs in the background and only downloads stuff, when the other app tells it to. – dandavis Sep 11 '15 at 16:43

1 Answers1

4

You cannot use a service worker to control any window object.

Service workers run in a worker context (not a browser context); it therefore has no DOM access.

Since things like postMessage() is a window function, and window is part of the DOM, you cannot window.postMessage() from a service worker. And unfortunately, client.postMessage() only works between browser contexts (tabs, windows, etc.) from the same domain origin (and service worker "scope").

DougA
  • 1,213
  • 9
  • 17