Workers, web or service; anyway to access window object?
Asked Answered
V

1

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?

Viridissa answered 11/9, 2015 at 16:12 Comment(3)
Workers 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.Pose
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?Viridissa
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.Pose
D
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").

Devi answered 29/7, 2020 at 13:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.