Detect XR Support with JavaScript

A few years ago I wrote an article about how to detect VR support with JavaScript. Since that time, a whole lot has changed. “Augmented reality” became a thing and terminology has moved to “XR”, instead of VR or AR. As such, the API has needed to evolve. The presence of navigator.xr signals that the […]

The post Detect XR Support with JavaScript appeared first on David Walsh Blog.

A few years ago I wrote an article about how to detect VR support with JavaScript. Since that time, a whole lot has changed. “Augmented reality” became a thing and terminology has moved to “XR”, instead of VR or AR. As such, the API has needed to evolve.

The presence of navigator.xr signals that the browser supports the WebXR API and XR devices:

const supportsXR = 'xr' in window.navigator;

I really like using in for feature checking rather than if(navigator.xr), as simply invoking that could cause some initialization to take place. In future posts we’ll explore identifying and connecting to different devices.

The post Detect XR Support with JavaScript appeared first on David Walsh Blog.


Print Share Comment Cite Upload Translate
APA
David Walsh | Sciencx (2024-03-28T17:03:36+00:00) » Detect XR Support with JavaScript. Retrieved from https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/.
MLA
" » Detect XR Support with JavaScript." David Walsh | Sciencx - Monday January 2, 2023, https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/
HARVARD
David Walsh | Sciencx Monday January 2, 2023 » Detect XR Support with JavaScript., viewed 2024-03-28T17:03:36+00:00,<https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/>
VANCOUVER
David Walsh | Sciencx - » Detect XR Support with JavaScript. [Internet]. [Accessed 2024-03-28T17:03:36+00:00]. Available from: https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/
CHICAGO
" » Detect XR Support with JavaScript." David Walsh | Sciencx - Accessed 2024-03-28T17:03:36+00:00. https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/
IEEE
" » Detect XR Support with JavaScript." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/. [Accessed: 2024-03-28T17:03:36+00:00]
rf:citation
» Detect XR Support with JavaScript | David Walsh | Sciencx | https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/ | 2024-03-28T17:03:36+00:00
https://github.com/addpipe/simple-recorderjs-demo