Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. XRSystem
  4. isSessionSupported()

XRSystem: isSessionSupported() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

TheXRSystem methodisSessionSupported() returns a promise which resolves totrue if the specified WebXR session mode is supported by the user's WebXRdevice. Otherwise, the promise resolves withfalse.

If no devices are available or the browser doesn't have permissionto use the XR device, the promise is rejected with an appropriateDOMException.

Syntax

js
isSessionSupported(mode)

Parameters

mode

AString specifying the WebXR session mode for which support is tobe checked. Possible modes to check for:

Return value

APromise that resolves totrue if the specified sessionmode is supported; otherwise the promise resolves tofalse.

Exceptions

Rather than throwing true exceptions,isSessionSupported() rejects thereturned promise, passing to the rejection handler aDOMException whosename is one of the following strings.

SecurityError

Use of this feature is blocked by anxr-spatial-trackingPermissions Policy.

Examples

In this example, we seeisSessionSupported() used to detect whether or notthe device supports VR mode by checking to see if animmersive-vr sessionis supported. If it is, we set up a button to read "Enter XR", to call a methodonButtonClicked(), and enable the button.

If no session is already underway, we request the VR session and, if successful, set upthe session in a method calledonSessionStarted(), not shown. If a sessionis already underway when the button is clicked, we call thexrSession object'send() method to shutdown the WebXR session.

js
if (navigator.xr) {  navigator.xr.isSessionSupported("immersive-vr").then((isSupported) => {    if (isSupported) {      userButton.addEventListener("click", onButtonClicked);      userButton.textContent = "Enter XR";      userButton.disabled = false;    }  });}function onButtonClicked() {  if (!xrSession) {    navigator.xr.requestSession("immersive-vr").then((session) => {      xrSession = session;      // onSessionStarted() not shown for reasons of brevity and clarity.      onSessionStarted(xrSession);    });  } else {    // Button is a toggle button.    xrSession.end();  }}

Specifications

Specification
WebXR Device API
# dom-xrsystem-issessionsupported

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp