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?
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?
Share Improve this question asked Sep 11, 2015 at 16:12 Mr PabloMr Pablo 4,1879 gold badges54 silver badges111 bronze badges 3-
1
Worker
s cannot directly reach awindow
, 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 viapostMessage()
towindow
at the last moment to download it to the OS. – dandavis Commented Sep 11, 2015 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 Commented Sep 11, 2015 at 16:40
-
afaik, no environ provides Workers with any call that could be used to save a file; namely
window.open()
,msSaveBlob()
, ora[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 Commented Sep 11, 2015 at 16:43
1 Answer
Reset to default 4You 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").