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.


This content originally appeared on David Walsh Blog and was authored by David Walsh

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.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2023-01-02T18:09:11+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 ,<https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/>
VANCOUVER
David Walsh | Sciencx - » Detect XR Support with JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/
CHICAGO
" » Detect XR Support with JavaScript." David Walsh | Sciencx - Accessed . 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: ]
rf:citation
» Detect XR Support with JavaScript | David Walsh | Sciencx | https://www.scien.cx/2023/01/02/detect-xr-support-with-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.