0

Are there any any events to listen for for when the browser has completed loading in VR?

I've seen this https://immersive-web.github.io/webvr/spec/1.1/#interface-vrdisplayevent

However

 window.addEventListener('onvrdisplayconnect', e => console.log('vr display connected'))

Isn't firing anything.

beek
  • 3,522
  • 8
  • 33
  • 86

1 Answers1

0

onvrdisplayconnect is the name of the event listener property; the name of the event is just vrdisplayconnect. So you can do either:

window.onvrdisplayconnect = e => console.log;

// Similar thing but you can have multiple listeners wired up at once.
window.addEventListener('vrdisplayconnect', e => console.log(e));

Most (all?) DOM events are named this way.

Note, WebVR has been superseded by WebXR. The new API has an event for a device changes, but typically you just start a session with navigator.xr.startSession('immersive-vr') and when the Promise resolves the session has started. Listen to the "end" event for when the session ends.

Dominic Cooney
  • 6,317
  • 1
  • 26
  • 38