Detect AR or VR

Is there a way to detect whether the WebXR is running on desktop, in AR or in VR?

Well, onXRSessionStart callback receives whether it’s AR or VR
And if no session is started, it’s desktop, you could also detect that by checking if navigator.xr.isSessionSupported('immersive-vr') etc works. There also is WL.arSupported and WL.vrSupported