Best practices for platform detection / WebXR modes?

For some effects, it’s necessary to know which device/platform/XR mode one is on.
Does three have some central place / existing utility for this, or is that too much browser-related?

I’ve seen tons of approaches across the web that all looked hacky:

  • check for the existence of specific objects in the scene
  • check for domOverlayType
  • parse user agent string

Concrete questions would be:

  • an XR session has started, am I in VR or AR?
  • an XR session has started, should I hide the background because it’s a device that shows background data (e.g. mobile AR, Hololens)
  • an XR session has started, does it make sense to show a specator camera on the canvas? (e.g. makes sense on Desktop VR, but not on Quest; doesn’t make sense on Hololens etc.)

Thanks!

1 Like