Skip to content
Advertisement

How to check if augmented reality permissions granted/blocked in Chrome mobile browser?

Issue:

WebXR in Chrome browser requires explicit user consent (permissions) for spatial tracking, but we’re having issues with users who block it. So in order to provide relevant UX to users with this issue (as opposed to other errors that may occur) we need to check if the permissions (Augmented Reality) in Chrome were granted or not as in the image below:

Augmented reality blocked img

What I have tried:

Although the ‘xr’ permission descriptor name is not listed in permissions registry, it is described in WebXR device API specification 14.2. However, the following code returns an error.

navigator.permissions.query({name: 'xr'});

Error (I guess it’s expected as it’s not in the permissions registry, I just thought that maybe Chrome has extended it somehow):

TypeError: Failed to execute 'query' on 'Permissions': The provided value 'xr' is not a valid enum value of type PermissionName.

I have also tried ‘immersive-ar’, ‘xr-spatial-tracking’ etc but with no success. The ‘xr-spatial-tracking’ is a Feature Policy, but if I understand it correctly, a feature policy purpose is not to grant permission, but rather to restrict permissions of certain elements on your page (e.g. iframes).

WebXR also uses the camera and most likely gyroscope and accelerometer, but the permissions for these are not affected by “Augmented reality allowed/blocked”. I think this is due to the camera/tracking part running natively on the device and not actually in the browser (I may be mistaken).

Example:

You can visit this three.js example with a mobile device on Chrome browser to see the “Augmented reality allowed/blocked” permission under the tablock button next to url.

How can I check if these permissions were granted or blocked? I’m not asking how to prompt the user with permission request, just a readonly value of the permission status would be perfect.

Thank you!

Advertisement

Answer

The best you can do right now is request spatial tracking during a user gesture, and display UI if the promise is rejected.

You can see the set of permission names that Chrome supports by reading ParsePermissionDescriptor in the Chromium source. It doesn’t support “xr”. I have filed this Chromium bug to add it, and this Web Platform Tests issue to add it to the W3C’s test suite for WebXR.

Here’s the list of things Chrome supports in that API. Some of these might be experimental.

  • accelerometer
  • accessibility-events
  • ambient-light-sensor
  • background-fetch
  • background-sync
  • camera
  • clipboard-read
  • clipboard-write
  • display-capture
  • font-access
  • geolocation
  • gyroscope
  • idle-detection
  • magnetometer
  • microphone
  • midi
  • nfc
  • notifications
  • payment-handler
  • periodic-background-sync
  • persistent-storage
  • push (only with {userVisible: true})
  • screen-wake-lock
  • storage-access
  • system-wake-lock
  • window-placement
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement