# WebXR

Wavedash games can start immersive VR and AR sessions with the WebXR Device API. No setup is needed.

Source: https://docs.wavedash.com/platform/webxr

The game frame is granted the `xr-spatial-tracking` permission, so the [WebXR Device API](https://developer.mozilla.org/en-US/docs/Web/API/WebXR_Device_API) works with no setup.

## Starting a session

Browsers only start an immersive session from a user gesture, so call `requestSession()` from a click handler in your game:

```javascript
if (await navigator.xr?.isSessionSupported("immersive-vr")) {
  enterButton.hidden = false;
  enterButton.addEventListener("click", async () => {
    const session = await navigator.xr.requestSession("immersive-vr"); // or "immersive-ar"
    // Hand the session to your engine, e.g. renderer.xr.setSession(session) in three.js
  });
}
```

Your game doesn't receive input while a Wavedash purchase overlay is open, so players can't start a session until it closes.

## Browser support

- **Meta Quest Browser** supports `immersive-vr` and `immersive-ar`. It's the main target.
- **Chrome on Android** supports `immersive-ar` on ARCore devices.
- **Safari on visionOS** supports `immersive-vr` but not `immersive-ar`.
- **Safari on iOS** has no WebXR. Keep a flat-screen mode.

## Engines

- **three.js**, **Babylon.js**, and **Godot 4** web exports support WebXR natively.
- **Unity** doesn't support WebXR in WebGL builds. Community packages such as [WebXR Export](https://github.com/De-Panther/unity-webxr-export) add it.

Assets loaded from other servers still need the [cross-origin isolation](/platform/cross-origin-isolation) headers.
