WebRTC firefox constraints

Firefox does support a subset of constraints with getUserMedia(), but not the outdated syntax that Chrome and Opera are using. The mandatory / optional syntax was deprecated years ago, and minWidth and minHeight the year before that.

The MediaCapture specification

According to the specification, which is now stable, your example should be written like this:

var constraints = {
    audio: false,
    video: {
        width: { min: 1280 },
        height: { min: 720 },
    }
};

This works in Firefox (and Chrome with adapter.js): https://jsfiddle.net/34qxx5w1

In the specification, the keywords min, max, and exact (a.k.a. min == max) are inherently mandatory, whereas plain values and ideal are not. Here’s a fuller example:

var constraints = {
    audio: false,
    video: {
        width: { min: 1024, ideal: 1280, max: 1920 },
        height: { min: 576, ideal: 720, max: 1080 },
    }
};

This works in Firefox (and Chrome with the adapter.js polyfill in straightforward cases).

An ideal value, when used, has gravity, which means that the browser will try to find the setting (and camera, if you have more than one), with the smallest fitness distance from the ideal values given.

Plain values are inherently ideal, which means that:

var constraints = { video: { width: 640, height: 480 } };

is the same as:

var constraints = { video: { width: { ideal: 640 }, height: { ideal: 480 } } };

In other words, a preference that getUserMedia() will try to honor, but never fail over.

If you must have a specific resolution, use this shorthand:

var constraints = { video: { width: { exact: 640 }, height: { exact: 480 } } };

Firefox

As of right now, width, height, frameRate and (on mobile) facingMode are supported in Firefox. Also, some caveats by version:

  • FF32-37: Plain values and ideal are not supported. However, values are not mandatory unless you add a non-spec require keyword.

  • FF38+: Implements the spec for the above constraints. Improved handling of Mac cameras (though frameRate has limitations on Mac).

  • FF43+: Implements MediaStreamTrack.applyConstraints() and mediaDevices.getSupportedConstraints().

  • FF46+: Implements echoCancellation.

Leave a Comment