navigator.xr is the experimental entry point to the WebXR Device API. Learn feature detection, XRSystem, isSessionSupported(), immersive-vr checks, secure-context rules, five examples, and try-it labs.
01
Kind
Read-only property
02
Returns
XRSystem
03
Status
Experimental
04
Context
Secure (HTTPS)
05
API family
WebXR Device API
06
Key method
isSessionSupported()
Fundamentals
Introduction
Virtual reality (VR) and augmented reality (AR) on the web start with one property: navigator.xr. When it exists, you get an XRSystem object that can ask whether a session mode is available and then start an XRSession.
You do not draw immersive scenes with navigator.xr alone. Think of it as the front door: detect it, check support, then request a session (usually from a button click) and render with WebGL / WebGPU or a framework such as Three.js, Babylon.js, or A-Frame.
💡
WebXR vs WebVR
Older tutorials mention navigator.activeVRDisplays and WebVR. That path is deprecated. New projects should use navigator.xr and WebXR.
Concept
Understanding the xr Property
The property itself is only the entry point. The useful pieces live on the returned XRSystem object.
Feature detect — "xr" in navigator (MDN) or truthy navigator.xr.
isSessionSupported(mode) — Promise<boolean> for modes like "immersive-vr", "immersive-ar", or "inline".
requestSession(mode) — starts an XRSession (usually from a user gesture).
devicechange — event when XR devices appear or disappear.
Secure context — HTTPS / localhost required.
Limited support — depends on browser + hardware; always fall back.
Foundation
📝 Syntax
General form of the property:
JavaScript
navigator.xr
Value
An XRSystem object used to interface with the WebXR Device API (when supported).
Common patterns
JavaScript
// MDN-style feature detect
if ("xr" in window.navigator) {
// WebXR can be used!
} else {
// WebXR isn't available
}
// Check immersive VR support (async)
async function checkImmersiveVr() {
if (!navigator.xr) return false;
return navigator.xr.isSessionSupported("immersive-vr");
}
// Enable a button only when immersive-vr is supported (MDN XRSystem pattern)
if (navigator.xr) {
immersiveButton.addEventListener("click", onButtonClicked);
navigator.xr.isSessionSupported("immersive-vr").then((isSupported) => {
immersiveButton.disabled = !isSupported;
});
}
Examples follow MDN navigator.xr / XRSystem patterns. Prefer Try It Yourself — many desktops report xr missing or isSessionSupported as false without a headset / compatible browser.
📚 Getting Started
Detect WebXR and confirm you are in a secure context.
Example 1 — Feature Detection
MDN-style support check before using WebXR.
JavaScript
if ("xr" in window.navigator) {
console.log("WebXR can be used!");
} else {
console.log("WebXR isn't available");
}
No navigator.xr — keep Enter VR disabled
(or "Enter VR disabled: false" when immersive-vr is supported)
How It Works
Start requestSession only from a user gesture after support is confirmed.
Example 5 — Prefer WebXR Over WebVR
Beginner migration helper: choose the modern API when both worlds appear in old docs.
JavaScript
function pickImmersiveApi() {
if ("xr" in navigator && navigator.xr) {
return "Use WebXR via navigator.xr";
}
if ("activeVRDisplays" in navigator) {
return "Legacy WebVR detected — do not use for new apps";
}
return "No WebXR / WebVR entry point — show 2D fallback";
}
console.log(pickImmersiveApi());
navigator.xr belongs to the experimental WebXR Device API and is not Baseline. Support depends on the browser and XR hardware / drivers. Always feature-detect, use HTTPS, call isSessionSupported(), and keep a non-XR fallback.
✓ Experimental · Not Baseline
Navigator.xr
XRSystem entry point — detect WebXR, check session modes, then request a session.
LimitedExperimental
Google ChromeWebXR on compatible devices / flags
Limited
Microsoft EdgeWebXR / follow Chromium support
Limited
Mozilla FirefoxWebXR where enabled / hardware available
Limited
OperaFollow Chromium WebXR support
Limited
Apple SafariLimited / platform-dependent — feature-detect
Limited
Internet ExplorerNo navigator.xr / WebXR support
Unavailable
xrLimited
Bottom line: Detect navigator.xr, check isSessionSupported for your mode, start sessions from a user gesture, and never require a headset for core page content.
Wrap Up
Conclusion
navigator.xr is the experimental front door to WebXR. Detect it on HTTPS, ask isSessionSupported before advertising immersive modes, start sessions from a user gesture, and keep a clear 2D fallback when XR is missing.
Experimental WebXR entry point — detect, check modes, fall back.
5
Core concepts
🔮01
Returns
XRSystem
Value
⚡02
Status
Experimental
Limited
🔒03
Context
secure HTTPS
Required
🔎04
Check
isSessionSupported
Modes
🎯05
Prefer
WebXR over WebVR
Migrate
❓ Frequently Asked Questions
A read-only XRSystem object — the entry point to the WebXR Device API for VR and AR sessions in the current browsing context.
MDN marks it Experimental and Limited availability (not Baseline). It is not Deprecated or Non-standard. Always feature-detect and provide a non-XR fallback.
Yes. MDN lists navigator.xr as a secure-context feature (HTTPS or localhost) in supporting browsers.
After detecting navigator.xr, call await navigator.xr.isSessionSupported("immersive-vr"). The promise resolves to true or false.
The WebXR Device API. Start with navigator.xr, then isSessionSupported() and requestSession() instead of the old WebVR VRDisplay APIs.
Usually no — starting an immersive session typically requires a user gesture (for example a button click). Check support first, then request the session from a click handler.
Did you know?
navigator.xr existing does not guarantee a headset is plugged in. Always follow up with isSessionSupported() for the mode you want, then only enable Enter VR / Enter AR UI when that check succeeds.