XRSession: enabledFeatures 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

XRSession 接口的只读 enabledFeatures 属性返回一个已为 XRSession 启用的(授予的)功能的数组。这包括所有 requiredFeatures 以及通过 XRSystem.requestSession() 请求的 optionalFeatures 的一个子集。

字符串的 Array

示例

检测可用的 WebXR 会话功能

XRSystem.requestSession() 方法允许您请求 XR 会话功能。这些功能可以作为 requiredFeaturesXRSession 必须支持该功能)或 optionalFeaturesXRSession 可能支持该功能)来请求。enabledFeatures 属性标识了会话中实际可用的功能。

js
navigator.xr
  .requestSession("immersive-ar", {
    requiredFeatures: ["local", "hit-test"],
    optionalFeatures: ["anchors"],
  })
  .then((xrSession) => {
    // Log enabledFeatures
    console.log(xrSession.enabledFeatures);

    // Check if anchors can be used
    if (xrSession.enabledFeatures.includes("anchors")) {
      // Go ahead and set up anchors
    }
  });

规范

规范
WebXR Device API
# dom-xrsession-enabledfeatures

浏览器兼容性

另见