Secure contextThis feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
User permissions in the WebXR Device API are managed using the Permissions API. To that end, the XRPermissionDescriptor
dictionary is used to describe the WebXR features the app needs to use, as well as those features it would like ot use if permision is granted.
The XRPermissionDescriptor
's name
must be set to xr
in order to direct the Permissions API to correctly handle the request as applying to WebXR.
Properties
In addition to inheriting the properties of the parent interface, PermissionDescriptor
, XRPermissionDescriptor
provides the following properties.
mode
- An
XRSessionMode
value indicating the XR mode (inline
,immersive-vr
, orimmersive-ar
) for which the permissions are requested. optionalFeatures
- An array of strings, each specifying the name of a WebXR feature which is requested but not required for the app to function. The available features are the same as those used by
XRSessionInit
; see Default features in XRSessionInit for further information. requiredFeatures
- An array of strings giving the names of the WebXR features for which permission must be obtained in order to use your app or site.
Examples
The example below demonstrates performing the permission request for an application that requires the local-floor
reference space in an immersive-vr
environment.
If the Permissions API is found to be available (by checking to see if navigator.permissions
is defined), its query()
method is called, specifying the permission descriptor we've established, xrPermissionDesc
.
When the returned promise resolves, we check the returned status. If permission has been granted, we call a function setupXR()
that handles preparing the WebXR environment for use. If permission is conditional based on prompting, we call a function promptAndSetupXR()
that would handle asking for permission before enabling and starting up the environment. And for any other returned state—which is almost certainly denied
, which is the only other option as of this article's writing—we do nothing, since we can't use WebXR.
If the permission request promise is rejected, the error is handled (currently by just dumping it to the console using domxref("console.log()")}}).
If the Permissions API isn't available at all, this example simply assumes that WebXR will report an appropriate error if permission isn't available, and tries to start up the WebXR session using the same setupXR()
function called by the granted
case.
let xrPermissionDesc = {
name: "xr",
mode: "immersive-vr",
requiredFeatures: [ "local-floor" ]
};
if (navigator.permissions) {
navigator.permissions.query(xrPermissionDesc).then(({state}) => {
switch(state) {
case "granted":
setupXR();
break;
case "prompt":
promptAndSetupXR();
break;
default:
/* do nothing otherwise */
break;
}
.catch(err) {
console.log(err);
}
} else {
setupXR();
}
Specifications
Specification | Status | Comment |
---|---|---|
WebXR Device APIThe definition of 'XRPermissionDescriptor' in that specification. | Working Draft | Initial definition. |
Browser compatibility
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
XRPermissionDescriptor
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
mode
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
optionalFeatures
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
requiredFeatures
|
Chrome
No support No |
Edge
No support No |
Firefox
No support No |
IE
No support No |
Opera
No support No |
Safari
No support No |
WebView Android
No support No |
Chrome Android
No support No |
Firefox Android
No support No |
Opera Android
No support No |
Safari iOS
No support No |
Samsung Internet Android
No support No |
Legend
- No support
- No support
See also
- Permissions and security for WebXR
XRPermissionStatus
navigator.permissions
andWorkerNavigator.permissions
Permissions
XRPermissionDescriptor by Mozilla Contributors is licensed under CC-BY-SA 2.5.