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

浏览器兼容性