Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The MediaTrackSettings dictionary's screenPixelRatio property is a number representing the ratio of the physical size of a pixel on the captured display surface (displayed at its physical resolution) to the logical size of a CSS pixel on the capturing screen (displayed at its logical resolution). It cannot be used as a constraint or capability.
This property allows applications using the Screen Capture API to save resources by sending the video of a screen capture at its logical, or device independent, resolution.
A number representing the screen pixel ratio.
This is calculated by dividing the size of a CSS pixel at a page zoom of 1.0 and using a scale factor of 1.0 on the capturing screen by the vertical size of a pixel from the captured display surface.
It is common for a screen to have zoom applied via the operating system (OS), for example when the display is a high-resolution display, and you want the graphics to be shown at the same physical size as they would on a standard resolution display. The resolution before applying the zoom is called the logical resolution, and the resolution after the zoom is applied is called the physical resolution.
If the sender's captured screen is zoomed in, then the physical resolution is greater than the logical resolution, and a video-conferencing app can therefore save bandwidth and CPU by:
The screenPixelRatio property describes the ratio of the physical size of a pixel to the logical size of a CSS pixel, and therefore enables the application to work out how much of a zoom factor has been applied, and then constrain the video to the logical size.
For example:
screenPixelRatio will return a value of 1.screenPixelRatio will return a value of 2.screenPixelRatio usageIn this example, the application defines a constant RESOLUTION_LIMIT, which represents the scaling factor beyond which the sending application should send video at the logical resolution rather than the physical resolution.
When screenPixelRatio exceeds this limit, the application uses the screenPixelRatio value to calculate the logical resolution from the physical resolution, and then constrains the captured MediaStreamTrack to the logical resolution.
const RESOLUTION_LIMIT = 1.5;
async function startCapture() {
const stream = await navigator.mediaDevices.getDisplayMedia({
video: true,
});
const track = stream.getVideoTracks()[0];
const settings = track.getSettings();
const capabilities = track.getCapabilities();
if (settings.screenPixelRatio > RESOLUTION_LIMIT) {
const physicalWidth = capabilities.width.max;
const physicalHeight = capabilities.height.max;
const logicalWidth = physicalWidth / settings.screenPixelRatio;
const logicalHeight = physicalHeight / settings.screenPixelRatio;
await track.applyConstraints({
width: logicalWidth,
height: logicalHeight,
});
}
}
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
screenPixelRatio |
136 | 136 | No | 121 | No | No | No | No | No | No | No | No |
MediaTrackSettings
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/screenPixelRatio