安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
User permissions in the
WebXR 设备 API
are managed using the
权限 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.
XRPermissionDescriptor
's
名称
must be set to
xr
in order to direct the Permissions API to correctly handle the request as applying to WebXR.
In addition to inheriting the properties of the parent interface,
PermissionDescriptor
,
XRPermissionDescriptor
provides the following properties.
mode
XRSessionMode
value indicating the XR mode (
inline
,
immersive-vr
,或
immersive-ar
) for which the permissions are requested.
optionalFeatures
XRSessionInit
;见
Default features
in
XRSessionInit
了解进一步信息。
requiredFeatures
The example below demonstrates performing the permission request for an application that requires the
local-floor
reference space in an
immersive-vr
environment.
若
权限 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;
默认:
/* do nothing otherwise */
break;
}
.catch(err) {
console.log(err);
}
} else {
setupXR();
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRPermissionDescriptor' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
XRPermissionDescriptor
|
Chrome No | Edge No | Firefox No | IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
mode
|
Chrome No | Edge No | Firefox No | IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
optionalFeatures
|
Chrome No | Edge No | Firefox No | IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
requiredFeatures
|
Chrome No | Edge No | Firefox No | IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
不支持
XRPermissionStatus
navigator.permissions
and
WorkerNavigator.permissions
权限
XRPermissionDescriptor
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceArray
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRRigidTransform
XRSession
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer