← Back to Emulation domain

Emulation.setDeviceMetricsOverride

Overrides the values of device screen dimensions (window.screen.width, window.screen.height, window.innerWidth, window.innerHeight, and "device-width"/"device-height"-related CSS media query results).

Domain: Emulation stable

Parameters

NameTypeDescription
widthintegerOverriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
heightintegerOverriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
deviceScaleFactornumberOverriding device scale factor value. 0 disables the override.
mobilebooleanWhether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.
scale (optional)numberScale to apply to resulting view image.
screenWidth (optional)integerOverriding screen width value in pixels (minimum 0, maximum 10000000).
screenHeight (optional)integerOverriding screen height value in pixels (minimum 0, maximum 10000000).
positionX (optional)integerOverriding view X position on screen in pixels (minimum 0, maximum 10000000).
positionY (optional)integerOverriding view Y position on screen in pixels (minimum 0, maximum 10000000).
dontSetVisibleSize (optional)booleanDo not set visible view size, rely upon explicit setVisibleSize call.
screenOrientation (optional)ScreenOrientationScreen orientation override.
viewport (optional)Page.ViewportIf set, the visible area of the page will be overridden to this viewport. This viewport change is not observed by the page, e.g. viewport-relative elements do not change positions.
displayFeature (optional)DisplayFeatureIf set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off. Deprecated, use Emulation.setDisplayFeaturesOverride.
devicePosture (optional)DevicePostureIf set, the posture of a foldable device. If not set the posture is set to continuous. Deprecated, use Emulation.setDevicePostureOverride.
scrollbarType (optional)stringScrollbar type. Default: `default`.
screenOrientationLockEmulation (optional)booleanIf set to true, enables screen orientation lock emulation, which intercepts screen.orientation.lock() calls from the page and reports orientation changes via screenOrientationLockChanged events. This is useful for emulating mobile device orientation lock behavior in responsive design mode.

Example Request

{
  "id": 1,
  "method": "Emulation.setDeviceMetricsOverride",
  "params": {
    "width": 1280,
    "height": 720,
    "deviceScaleFactor": 1.0,
    "mobile": true
  }
}

Example Response

{
  "id": 1,
  "result": {}
}

Usage in Node.js

const result = await send('Emulation.setDeviceMetricsOverride', {"width": 1280, "height": 720, "deviceScaleFactor": 1.0, "mobile": true});
console.log(result);