I'm trying to access the document in a react vr app. The app was created using the react-vr-cli. However, when I try to access the page I get the following error.
document is not defined
I'm trying to access the document in a react vr app. The app was created using the react-vr-cli. However, when I try to access the page I get the following error.
document is not defined
The React VR instance is run inside a web worker, that's why you're getting DedicatedWorkerGlobalScope
instead of window
and why there's no global document
.
This is just how React VR works and it's why there's a react-vr-web
package that's in charge of communicating with the VR instance via postMessage
.
Unfortunately web workers only have access to a subset of the features present on in the browser on the global scope.
For some you can find workarounds in React VR like AsyncStorage instead of localStorage
. For everything else you'll have to figure out a way of communicating outside the web worker via postMessage
and with a listener on onmessage
.
Another way of sending stuff from window
to the VR instance is to implement a native module as a bridge between the two. You can find more info in
Persistent bridge between a React VR component and native module code.