MediaTrackSupportedConstraints: facingMode property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
TheMediaTrackSupportedConstraints dictionary'sfacingMode property is a read-only Boolean value which ispresent (and set totrue) in the object returned byMediaDevices.getSupportedConstraints() if and only if theuser agent supports thefacingMode constraint. If theconstraint isn't supported, it's not included in the list, so this value will never befalse.
You can access the supported constraints dictionary by callingnavigator.mediaDevices.getSupportedConstraints().
In this article
Value
This property is present in the dictionary (and its value is alwaystrue)if the user agent supports thefacingMode constraint. If the property isn'tpresent, this property is missing from the supported constraints dictionary, and you'llgetundefined if you try to look at its value.
Examples
<div></div>#result { font: 14px "Arial", sans-serif;}const result = document.getElementById("result");const supported = navigator.mediaDevices.getSupportedConstraints().facingMode;result.textContent = supported ? "Supported!" : "Not supported!";Result
Specifications
| Specification |
|---|
| Media Capture and Streams> # dom-mediatrackconstraintset-facingmode> |