Skip to content

Conversation

hamishwillee
Copy link
Collaborator

FF144 added a new constraint parameter resizeMode for use with MediaDevices.getUserMedia() and getDisplayMedia().

This allows a developer to specify whether the video from the camera should be cropped and/or downscaled to match other constraints, which may be natively supported by the camera - essentially gives them what they ask for rather than what the camera is capable of delivering. It also allows them to specify that it doesn't want scaling.

This updates the relevant docs (First two commits are layout only).

The main changes are to:

  • Better cross-link MediaTrackConstraints which is where the constraint is documented to make it clear that it is also used in these methods (not just some others).
  • Provide an example explaining the downscaling.

Related docs work can be tracked in #41132

@hamishwillee hamishwillee requested a review from a team as a code owner September 16, 2025 05:59
@hamishwillee hamishwillee requested review from wbamberg and removed request for a team September 16, 2025 05:59
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Sep 16, 2025
Copy link
Contributor

The **`MediaTrackConstraints`** dictionary is used to describe a set of capabilities and the value or values each can take on. A constraints dictionary is passed into {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.
The **`MediaTrackConstraints`** dictionary is used to describe a set of media capabilities and the value or values each can take on.

A constraints dictionary is passed into the {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} method of the {{domxref("MediaStreamTrack")}} interface to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A constraints dictionary is passed into the {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} method of the {{domxref("MediaStreamTrack")}} interface to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.
A constraints dictionary is passed into the {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} method of the {{domxref("MediaStreamTrack")}} interface to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track.
The most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.


A constraints dictionary is passed into the {{domxref("MediaStreamTrack.applyConstraints", "applyConstraints()")}} method of the {{domxref("MediaStreamTrack")}} interface to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling {{domxref("MediaStreamTrack.getConstraints", "getConstraints()")}}.

Objects of this type may also be passed to the {{domxref("MediaDevices/getUserMedia","getUserMedia()")}} and {{domxref("MediaDevices/getDisplayMedia","getDisplayMedia()")}} methods of the {{domxref("MediaDevices")}} interface in order to specify constraints on a media stream requested from hardware such as a camera or microphone, and from a screen or window capture, respectively.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Objects of this type may also be passed to the {{domxref("MediaDevices/getUserMedia","getUserMedia()")}} and {{domxref("MediaDevices/getDisplayMedia","getDisplayMedia()")}} methods of the {{domxref("MediaDevices")}} interface in order to specify constraints on a media stream requested from hardware such as a camera or microphone, and from a screen or window capture, respectively.
Objects of this type may also be passed to:
- The {{domxref("MediaDevices.getUserMedia()")}} method, to specify constraints on a media stream requested from hardware such as a camera or microphone.
- The {{domxref("MediaDevices.getDisplayMedia()")}} method, to specify constraints on a media stream requested from a screen or window capture.

});
```

The browser may return another resolutions if an exact match is not available and the source is not to be scaled.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The browser may return another resolutions if an exact match is not available and the source is not to be scaled.
The browser may return another resolution if an exact match is not available and the source is not to be scaled.

resolutions if an exact match is not available, or the user overrides it.
The browser will try to honor the constraints, and will return a matching track if supported by the underlying hardware.
If not supported, the browser may attempt to crop and downscale a higher resolution stream from the underlying hardware in order to match the constraint.
This will commonly be the default behavior, but can be forced by setting the [`resizeMode`](/en-US/docs/Web/API/MediaTrackConstraints#resizemode) constraint to `crop-and-scale` (or disabled with `none`):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This will commonly be the default behavior, but can be forced by setting the [`resizeMode`](/en-US/docs/Web/API/MediaTrackConstraints#resizemode) constraint to `crop-and-scale` (or disabled with `none`):
This will commonly be the default behavior, but can be forced by setting the [`resizeMode`](/en-US/docs/Web/API/MediaTrackConstraints#resizemode) constraint to `crop-and-scale` (or disabled by setting it to `none`):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants