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

瀏覽器相容性

另見