The trick is to use the same JS script as you’re r...
# javascript
h
The trick is to use the same JS script as you’re running in, and catch the exception when you access
window
. That will throw a
ReferenceError
, but since that isn’t exposed to the Kotlin/JS API, you have to catch
Throwable
instead. Now you know if you’re running in the window or as a service worker
a
I'm not aware of any progress towards Service Workers. But we've got a person working on integration with Web Workers as a 20% project. I can put you in touch with him if you wish.
My colleague suggested that what you actually want is to put the worker code into a separate
.js
file. The only way to do that at the moment is to move the worker code to a separate module.
h
Yeah, that was my next step. Do I just add a project dependency to my main module then and the runBrowser task will give me two files?
a
Something like that, yes. My understanding is that you want to end up with 2 self-sufficient bundles. Then you pass the second one as the worker.