Is there a "clean" way of checking whether the DOM...
# javascript
a
Is there a "clean" way of checking whether the DOM is available in the currently running JS environment? I'm working on a multiplatform project, and have a
*-common-js
gradle subproject that gets imported in a version of the app that I would like to be able to run both headlessly (e.g. with node) or in a browser. I thought perhaps I could check if
kotlin.browser.window
and compare it with either
null
or
kotlin.js.undefined
, however both these give me
Copy code
ReferenceError: window is not defined
Okay, so this worked... Can it be done in a nicer way?
Copy code
private val hasDom = eval("typeof window").toString() != "undefined"
k
Copy code
private val hasDom: Boolean get() = jsTypeOf(window) != "undefined"