Example 1 — Feature Detection
Check whether WebXR is exposed before calling any methods.
if ("xr" in navigator) {
console.log("WebXR available");
} else {
console.log("WebXR not supported");
}
console.log("secure:", window.isSecureContext); How It Works
- Ask the browser. The
inoperator checks for the property. - Gate your code. Only call
isSessionSupported/requestSessionwhen present. - Check HTTPS. MDN requires a secure context in supporting browsers.
- Expect gaps. Limited availability means Firefox and Safari omit the API.

