XR.supportsSession()

The supportsSession() method of the XR interface returns an empty Promise that resolves if the requested session mode is available from the device. Supprted session modes include "inline" and "immersive-vr".

Syntax

var promise = XR.supportsSession(xrSessionMode)

Parameters

XRSessionMode

The desired session mode, one of "inline" and "immersive-vr".

Return value

A Promise that resolves if the desired session mode is supported.

Errors

This method can reject Promises with the following errors:

NotSupportedError
A DOMException indicating that the requestted session mode is not supported or that the underlying device does not support WebXR.

Examples

The following example shows how to use both supportsSession() and requestSession(). First it checks to see if WebXR is available. Next it calls supportsSession(), passing it the desired session option before enabling controls for entering XR. Adding controls is a necessary step because entering XR requires a user action. Finally the onButtonClicked() method calls requestSession() using the same session option passed to supportsSession().

if (navigator.xr) {
  navigator.xr.supportsSession('immersive-vr')
  .then(() => {
    userButton.addEventListener('click', onButtonClicked);
    userButton.innerHTML = 'Enter XR';
    userButton.disabled = false;
  });
}

function onButtonClicked() {
  if (!xrSession) {
    navigator.xr.requestSession('immersive-vr')
    .then(() => {
      // onSessionStarted() not shown for reasons of brevity and clarity.
      onSessionStarted(xrSession);
    });
  } else {
    // Button is a toggle button.
    xrSession.end();
  }
}

Specifications

Specification Status Comment
WebXR Device API
The definition of 'supportsSession' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
supportsSession()
ExperimentalNon-standard
Chrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.

Document Tags and Contributors

Contributors to this page: jpmedley, bershanskiy
Last updated by: jpmedley,