MediaDevices:getSupportedConstraints() 方法

Baseline 已廣泛支援

此功能已成熟,可跨多種裝置和瀏覽器版本使用。自 2017 年 9 月以來,它已在瀏覽器中提供。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

getSupportedConstraints()MediaDevices 介面的一個方法。它返回一個基於 MediaTrackSupportedConstraints 字典的物件,該物件的成員欄位分別指定了 使用者代理 理解的約束屬性。

語法

js
getSupportedConstraints()

引數

無。

返回值

基於 MediaTrackSupportedConstraints 字典的新物件列出了使用者代理支援的約束。因為列表中只包含使用者代理支援的約束,所以每個布林屬性的值都為 true

示例

此示例輸出瀏覽器支援的約束列表。

js
const constraintList = document.querySelector("#constraintList");
const supportedConstraints = navigator.mediaDevices.getSupportedConstraints();

for (const constraint of Object.keys(supportedConstraints)) {
  const elem = document.createElement("li");
  elem.appendChild(document.createElement("code")).textContent = constraint;
  constraintList.appendChild(elem);
}

結果

規範

規範
媒體捕獲和流
# dom-mediadevices-getsupportedconstraints

瀏覽器相容性