Checking XR capabilities

I intended to create a panel with some XR experiences but graying out the ones that are not available for your current device like image-tracking and IOS

I’ve tried to do that with vanilla JS but it doesn’t close the XR mode

I’ve tried to do the same with Babylon itself, but unfortunately, I had the same problem

(press space in both playgrounds to print it to the console)

Any tip is welcome!

Wrap the exit in a setTimeout. it needs to run on the next frame:

Thank you @RaananW it works great (but with a non-so important flicker), but is there any chance to do it using raw xr api as in the first sample? My idea was to show the users a menu where the user could select the AR mode before opening the actual 3d viewport.

sure, you could do the same thing using native WebXR calls - request the session with the required features (the ones you are trying to check), and that’s it.

Side note - There is a simpler way of checking if you can run an AR - isSessionSupported on the navigator.xr object allows you to check if your devices supports a certain session type (vr, ar). Otherwise - The WebXR API does its best to prevent fingerprinting (which is technically what you are trying to achieve). There are a lot of good reasons for that. WebXR is trying to convince you to make a more dynamic and defensive application - defined the required features, defined the optional ones, and then react accordingly if any of the initialization fails.

I mean that my problem with native webXR is that it doesn’t exist automatically, checking if AR is available seems to be pretty straightforward but checking image-tracking and light-estimation is not.

For a reason :slight_smile:

WebGL, for example, is used for device fingerpinting. WebXR tried preventing this by making it a bit harder to detect features, like you are trying to achieve.
Haing said that - if it is possible with babylon, it should be possible with native webxr calls. I haven’t tried TBH (and am a great believer in fingerprinting prevention) but t should be possible. You will, of course, need user interaction for that to work correctly, but you have it with the space keydown event.