Emulation#

This domain emulates different environments for the page.

Types#

Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.

class SafeAreaInsets(top=None, top_max=None, left=None, left_max=None, bottom=None, bottom_max=None, right=None, right_max=None)[source]#
top: Optional[int] = None#

Overrides safe-area-inset-top.

top_max: Optional[int] = None#

Overrides safe-area-max-inset-top.

left: Optional[int] = None#

Overrides safe-area-inset-left.

left_max: Optional[int] = None#

Overrides safe-area-max-inset-left.

bottom: Optional[int] = None#

Overrides safe-area-inset-bottom.

bottom_max: Optional[int] = None#

Overrides safe-area-max-inset-bottom.

right: Optional[int] = None#

Overrides safe-area-inset-right.

right_max: Optional[int] = None#

Overrides safe-area-max-inset-right.

class ScreenOrientation(type_, angle)[source]#

Screen orientation.

type_: str#

Orientation type.

angle: int#

Orientation angle.

class DisplayFeature(orientation, offset, mask_length)[source]#
orientation: str#

Orientation of a display feature in relation to screen

offset: int#

The offset from the screen origin in either the x (for vertical orientation) or y (for horizontal orientation) direction.

mask_length: int#

A display feature may mask content such that it is not physically displayed - this length along with the offset describes this area. A display feature that only splits content will have a 0 mask_length.

class DevicePosture(type_)[source]#
type_: str#

Current posture of the device

class MediaFeature(name, value)[source]#
name: str#
value: str#
class VirtualTimePolicy(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

advance: If the scheduler runs out of immediate work, the virtual time base may fast forward to allow the next delayed task (if any) to run; pause: The virtual time base may not advance; pauseIfNetworkFetchesPending: The virtual time base may not advance if there are any pending resource fetches.

ADVANCE = 'advance'#
PAUSE = 'pause'#
PAUSE_IF_NETWORK_FETCHES_PENDING = 'pauseIfNetworkFetchesPending'#
class UserAgentBrandVersion(brand, version)[source]#

Used to specify User Agent Client Hints to emulate. See https://wicg.github.io/ua-client-hints

brand: str#
version: str#
class UserAgentMetadata(platform, platform_version, architecture, model, mobile, brands=None, full_version_list=None, full_version=None, bitness=None, wow64=None, form_factors=None)[source]#

Used to specify User Agent Client Hints to emulate. See https://wicg.github.io/ua-client-hints Missing optional values will be filled in by the target with what it would normally use.

platform: str#
platform_version: str#
architecture: str#
model: str#
mobile: bool#
brands: Optional[List[UserAgentBrandVersion]] = None#

Brands appearing in Sec-CH-UA.

full_version_list: Optional[List[UserAgentBrandVersion]] = None#

Brands appearing in Sec-CH-UA-Full-Version-List.

full_version: Optional[str] = None#
bitness: Optional[str] = None#
wow64: Optional[bool] = None#
form_factors: Optional[List[str]] = None#

Used to specify User Agent form-factor values. See https://wicg.github.io/ua-client-hints/#sec-ch-ua-form-factors

class SensorType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Used to specify sensor types to emulate. See https://w3c.github.io/sensors/#automation for more information.

ABSOLUTE_ORIENTATION = 'absolute-orientation'#
ACCELEROMETER = 'accelerometer'#
AMBIENT_LIGHT = 'ambient-light'#
GRAVITY = 'gravity'#
GYROSCOPE = 'gyroscope'#
LINEAR_ACCELERATION = 'linear-acceleration'#
MAGNETOMETER = 'magnetometer'#
RELATIVE_ORIENTATION = 'relative-orientation'#
class SensorMetadata(available=None, minimum_frequency=None, maximum_frequency=None)[source]#
available: Optional[bool] = None#
minimum_frequency: Optional[float] = None#
maximum_frequency: Optional[float] = None#
class SensorReadingSingle(value)[source]#
value: float#
class SensorReadingXYZ(x, y, z)[source]#
x: float#
y: float#
z: float#
class SensorReadingQuaternion(x, y, z, w)[source]#
x: float#
y: float#
z: float#
w: float#
class SensorReading(single=None, xyz=None, quaternion=None)[source]#
single: Optional[SensorReadingSingle] = None#
xyz: Optional[SensorReadingXYZ] = None#
quaternion: Optional[SensorReadingQuaternion] = None#
class PressureSource(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
CPU = 'cpu'#
class PressureState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
NOMINAL = 'nominal'#
FAIR = 'fair'#
SERIOUS = 'serious'#
CRITICAL = 'critical'#
class PressureMetadata(available=None)[source]#
available: Optional[bool] = None#
class WorkAreaInsets(top=None, left=None, bottom=None, right=None)[source]#
top: Optional[int] = None#

Work area top inset in pixels. Default is 0;

left: Optional[int] = None#

Work area left inset in pixels. Default is 0;

bottom: Optional[int] = None#

Work area bottom inset in pixels. Default is 0;

right: Optional[int] = None#

Work area right inset in pixels. Default is 0;

class ScreenId[source]#
class ScreenInfo(left, top, width, height, avail_left, avail_top, avail_width, avail_height, device_pixel_ratio, orientation, color_depth, is_extended, is_internal, is_primary, label, id_)[source]#

Screen information similar to the one returned by window.getScreenDetails() method, see https://w3c.github.io/window-management/#screendetailed.

left: int#

Offset of the left edge of the screen.

top: int#

Offset of the top edge of the screen.

width: int#

Width of the screen.

height: int#

Height of the screen.

avail_left: int#

Offset of the left edge of the available screen area.

avail_top: int#

Offset of the top edge of the available screen area.

avail_width: int#

Width of the available screen area.

avail_height: int#

Height of the available screen area.

device_pixel_ratio: float#

Specifies the screen’s device pixel ratio.

orientation: ScreenOrientation#

Specifies the screen’s orientation.

color_depth: int#

Specifies the screen’s color depth in bits.

is_extended: bool#

Indicates whether the device has multiple screens.

is_internal: bool#

Indicates whether the screen is internal to the device or external, attached to the device.

is_primary: bool#

Indicates whether the screen is set as the the operating system primary screen.

label: str#

Specifies the descriptive label for the screen.

id_: ScreenId#

Specifies the unique identifier of the screen.

class DisabledImageType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Enum of image types that can be disabled.

AVIF = 'avif'#
WEBP = 'webp'#

Commands#

Each command is a generator function. The return type Generator[x, y, z] indicates that the generator yields arguments of type x, it must be resumed with an argument of type y, and it returns type z. In this library, types x and y are the same for all commands, and z is the return type you should pay attention to. For more information, see Getting Started: Commands.

add_screen(left, top, width, height, work_area_insets=None, device_pixel_ratio=None, rotation=None, color_depth=None, label=None, is_internal=None)[source]#

Add a new screen to the device. Only supported in headless mode.

EXPERIMENTAL

Parameters:
  • left (int) – Offset of the left edge of the screen in pixels.

  • top (int) – Offset of the top edge of the screen in pixels.

  • width (int) – The width of the screen in pixels.

  • height (int) – The height of the screen in pixels.

  • work_area_insets (Optional[WorkAreaInsets]) – (Optional) Specifies the screen’s work area. Default is entire screen.

  • device_pixel_ratio (Optional[float]) – (Optional) Specifies the screen’s device pixel ratio. Default is 1.

  • rotation (Optional[int]) – (Optional) Specifies the screen’s rotation angle. Available values are 0, 90, 180 and 270. Default is 0.

  • color_depth (Optional[int]) – (Optional) Specifies the screen’s color depth in bits. Default is 24.

  • label (Optional[str]) – (Optional) Specifies the descriptive label for the screen. Default is none.

  • is_internal (Optional[bool]) – (Optional) Indicates whether the screen is internal to the device or external, attached to the device. Default is false.

Return type:

Generator[Dict[str, Any], Dict[str, Any], ScreenInfo]

Returns:

can_emulate()[source]#

Tells whether emulation is supported.

Deprecated since version 1.3.

Return type:

Generator[Dict[str, Any], Dict[str, Any], bool]

Returns:

True if emulation is supported.

Deprecated since version 1.3.

clear_device_metrics_override()[source]#

Clears the overridden device metrics.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

clear_device_posture_override()[source]#

Clears a device posture override set with either setDeviceMetricsOverride() or setDevicePostureOverride() and starts using posture information from the platform again. Does nothing if no override is set.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

clear_display_features_override()[source]#

Clears the display features override set with either setDeviceMetricsOverride() or setDisplayFeaturesOverride() and starts using display features from the platform again. Does nothing if no override is set.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

clear_geolocation_override()[source]#

Clears the overridden Geolocation Position and Error.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

clear_idle_override()[source]#

Clears Idle state overrides.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

get_overridden_sensor_information(type_)[source]#

EXPERIMENTAL

Parameters:

type

Return type:

Generator[Dict[str, Any], Dict[str, Any], float]

Returns:

get_screen_infos()[source]#

Returns device’s screen configuration.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], List[ScreenInfo]]

Returns:

remove_screen(screen_id)[source]#

Remove screen from the device. Only supported in headless mode.

EXPERIMENTAL

Parameters:

screen_id (ScreenId) –

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

reset_page_scale_factor()[source]#

Requests that page scale factor is reset to initial values.

EXPERIMENTAL

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_auto_dark_mode_override(enabled=None)[source]#

Automatically render all web contents using a dark theme.

EXPERIMENTAL

Parameters:

enabled (Optional[bool]) – (Optional) Whether to enable or disable automatic dark mode. If not specified, any existing override will be cleared.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_automation_override(enabled)[source]#

Allows overriding the automation flag.

EXPERIMENTAL

Parameters:

enabled (bool) – Whether the override should be enabled.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_cpu_throttling_rate(rate)[source]#

Enables CPU throttling to emulate slow CPUs.

Parameters:

rate (float) – Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc).

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_data_saver_override(data_saver_enabled=None)[source]#

Override the value of navigator.connection.saveData

EXPERIMENTAL

Parameters:

data_saver_enabled (Optional[bool]) – (Optional) Override value. Omitting the parameter disables the override.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_default_background_color_override(color=None)[source]#

Sets or clears an override of the default background color of the frame. This override is used if the content does not specify one.

Parameters:

color (Optional[RGBA]) – (Optional) RGBA of the default background color. If not specified, any existing override will be cleared.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_device_metrics_override(width, height, device_scale_factor, mobile, scale=None, screen_width=None, screen_height=None, position_x=None, position_y=None, dont_set_visible_size=None, screen_orientation=None, viewport=None, display_feature=None, device_posture=None)[source]#

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).

Parameters:
  • width (int) – Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.

  • height (int) – Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.

  • device_scale_factor (float) – Overriding device scale factor value. 0 disables the override.

  • mobile (bool) – Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.

  • scale (Optional[float]) – (EXPERIMENTAL) (Optional) Scale to apply to resulting view image.

  • screen_width (Optional[int]) – (EXPERIMENTAL) (Optional) Overriding screen width value in pixels (minimum 0, maximum 10000000).

  • screen_height (Optional[int]) – (EXPERIMENTAL) (Optional) Overriding screen height value in pixels (minimum 0, maximum 10000000).

  • position_x (Optional[int]) – (EXPERIMENTAL) (Optional) Overriding view X position on screen in pixels (minimum 0, maximum 10000000).

  • position_y (Optional[int]) – (EXPERIMENTAL) (Optional) Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).

  • dont_set_visible_size (Optional[bool]) – (EXPERIMENTAL) (Optional) Do not set visible view size, rely upon explicit setVisibleSize call.

  • screen_orientation (Optional[ScreenOrientation]) – (Optional) Screen orientation override.

  • viewport (Optional[Viewport]) – (EXPERIMENTAL) (Optional) If 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.

  • display_feature (Optional[DisplayFeature]) – (DEPRECATED) (EXPERIMENTAL) (Optional) If set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off. Deprecated, use Emulation.setDisplayFeaturesOverride.

  • device_posture (Optional[DevicePosture]) – (DEPRECATED) (EXPERIMENTAL) (Optional) If set, the posture of a foldable device. If not set the posture is set to continuous. Deprecated, use Emulation.setDevicePostureOverride.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_device_posture_override(posture)[source]#

Start reporting the given posture value to the Device Posture API. This override can also be set in setDeviceMetricsOverride().

EXPERIMENTAL

Parameters:

posture (DevicePosture) –

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_disabled_image_types(image_types)[source]#

EXPERIMENTAL

Parameters:

image_types (List[DisabledImageType]) – Image types to disable.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_display_features_override(features)[source]#

Start using the given display features to pupulate the Viewport Segments API. This override can also be set in setDeviceMetricsOverride().

EXPERIMENTAL

Parameters:

features (List[DisplayFeature]) –

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

EXPERIMENTAL

Parameters:

disabled (bool) – Whether document.coookie API should be disabled.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_emit_touch_events_for_mouse(enabled, configuration=None)[source]#

EXPERIMENTAL

Parameters:
  • enabled (bool) – Whether touch emulation based on mouse input should be enabled.

  • configuration (Optional[str]) – (Optional) Touch/gesture events configuration. Default: current platform.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_emulated_media(media=None, features=None)[source]#

Emulates the given media type or media feature for CSS media queries.

Parameters:
  • media (Optional[str]) – (Optional) Media type to emulate. Empty string disables the override.

  • features (Optional[List[MediaFeature]]) – (Optional) Media features to emulate.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_emulated_os_text_scale(scale=None)[source]#

Emulates the given OS text scale.

Parameters:

scale (Optional[float]) – (Optional)

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_emulated_vision_deficiency(type_)[source]#

Emulates the given vision deficiency.

Parameters:

type – Vision deficiency to emulate. Order: best-effort emulations come first, followed by any physiologically accurate emulations for medically recognized color vision deficiencies.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_focus_emulation_enabled(enabled)[source]#

Enables or disables simulating a focused and active page.

EXPERIMENTAL

Parameters:

enabled (bool) – Whether to enable to disable focus emulation.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_geolocation_override(latitude=None, longitude=None, accuracy=None, altitude=None, altitude_accuracy=None, heading=None, speed=None)[source]#

Overrides the Geolocation Position or Error. Omitting latitude, longitude or accuracy emulates position unavailable.

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_hardware_concurrency_override(hardware_concurrency)[source]#

EXPERIMENTAL

Parameters:

hardware_concurrency (int) – Hardware concurrency to report

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_idle_override(is_user_active, is_screen_unlocked)[source]#

Overrides the Idle state.

Parameters:
  • is_user_active (bool) – Mock isUserActive

  • is_screen_unlocked (bool) – Mock isScreenUnlocked

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_locale_override(locale=None)[source]#

Overrides default host system locale with the specified one.

EXPERIMENTAL

Parameters:

locale (Optional[str]) – (Optional) ICU style C locale (e.g. “en_US”). If not specified or empty, disables the override and restores default host system locale.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_navigator_overrides(platform)[source]#

Overrides value returned by the javascript navigator object.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:

platform (str) – The platform navigator.platform should return.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

Deprecated since version 1.3.

set_page_scale_factor(page_scale_factor)[source]#

Sets a specified page scale factor.

EXPERIMENTAL

Parameters:

page_scale_factor (float) – Page scale factor.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_pressure_data_override(source, state, own_contribution_estimate=None)[source]#

Provides a given pressure data set that will be processed and eventually be delivered to PressureObserver users. source must have been previously overridden by setPressureSourceOverrideEnabled.

EXPERIMENTAL

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_pressure_source_override_enabled(enabled, source, metadata=None)[source]#

Overrides a pressure source of a given type, as used by the Compute Pressure API, so that updates to PressureObserver.observe() are provided via setPressureStateOverride instead of being retrieved from platform-provided telemetry data.

EXPERIMENTAL

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_pressure_state_override(source, state)[source]#

TODO: OBSOLETE: To remove when setPressureDataOverride is merged. Provides a given pressure state that will be processed and eventually be delivered to PressureObserver users. source must have been previously overridden by setPressureSourceOverrideEnabled.

EXPERIMENTAL

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_safe_area_insets_override(insets)[source]#

Overrides the values for env(safe-area-inset-) and env(safe-area-max-inset-). Unset values will cause the respective variables to be undefined, even if previously overridden.

EXPERIMENTAL

Parameters:

insets (SafeAreaInsets) –

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_script_execution_disabled(value)[source]#

Switches script execution in the page.

Parameters:

value (bool) – Whether script execution should be disabled in the page.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_scrollbars_hidden(hidden)[source]#

EXPERIMENTAL

Parameters:

hidden (bool) – Whether scrollbars should be always hidden.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_sensor_override_enabled(enabled, type_, metadata=None)[source]#

Overrides a platform sensor of a given type. If enabled is true, calls to Sensor.start() will use a virtual sensor as backend rather than fetching data from a real hardware sensor. Otherwise, existing virtual sensor-backend Sensor objects will fire an error event and new calls to Sensor.start() will attempt to use a real sensor instead.

EXPERIMENTAL

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_sensor_override_readings(type_, reading)[source]#

Updates the sensor readings reported by a sensor type previously overridden by setSensorOverrideEnabled.

EXPERIMENTAL

Parameters:
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_small_viewport_height_difference_override(difference)[source]#

Allows overriding the difference between the small and large viewport sizes, which determine the value of the svh and lvh unit, respectively. Only supported for top-level frames.

EXPERIMENTAL

Parameters:

difference (int) – This will cause an element of size 100svh to be `difference` pixels smaller than an element of size 100lvh.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_timezone_override(timezone_id)[source]#

Overrides default host system timezone with the specified one.

Parameters:

timezone_id (str) – The timezone identifier. List of supported timezones: https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt If empty, disables the override and restores default host system timezone.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_touch_emulation_enabled(enabled, max_touch_points=None)[source]#

Enables touch on platforms which do not support them.

Parameters:
  • enabled (bool) – Whether the touch event emulation should be enabled.

  • max_touch_points (Optional[int]) – (Optional) Maximum touch points supported. Defaults to one.

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_user_agent_override(user_agent, accept_language=None, platform=None, user_agent_metadata=None)[source]#

Allows overriding user agent with the given string. userAgentMetadata must be set for Client Hint headers to be sent.

Parameters:
  • user_agent (str) – User agent to use.

  • accept_language (Optional[str]) – (Optional) Browser language to emulate.

  • platform (Optional[str]) – (Optional) The platform navigator.platform should return.

  • user_agent_metadata (Optional[UserAgentMetadata]) – (EXPERIMENTAL) (Optional) To be sent in Sec-CH-UA-* headers and returned in navigator.userAgentData

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

set_virtual_time_policy(policy, budget=None, max_virtual_time_task_starvation_count=None, initial_virtual_time=None)[source]#

Turns on virtual time for all frames (replacing real-time with a synthetic time source) and sets the current virtual time policy. Note this supersedes any previous time budget.

EXPERIMENTAL

Parameters:
  • policy (VirtualTimePolicy) –

  • budget (Optional[float]) – (Optional) If set, after this many virtual milliseconds have elapsed virtual time will be paused and a virtualTimeBudgetExpired event is sent.

  • max_virtual_time_task_starvation_count (Optional[int]) – (Optional) If set this specifies the maximum number of tasks that can be run before virtual is forced forwards to prevent deadlock.

  • initial_virtual_time (Optional[TimeSinceEpoch]) – (Optional) If set, base::Time::Now will be overridden to initially return this value.

Return type:

Generator[Dict[str, Any], Dict[str, Any], float]

Returns:

Absolute timestamp at which virtual time was first enabled (up time in milliseconds).

set_visible_size(width, height)[source]#

Resizes the frame/viewport of the page. Note that this does not affect the frame’s container (e.g. browser window). Can be used to produce screenshots of the specified size. Not supported on Android.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:
  • width (int) – Frame width (DIP).

  • height (int) – Frame height (DIP).

Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

Deprecated since version 1.3.

Events#

Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.

class VirtualTimeBudgetExpired[source]#

EXPERIMENTAL

Notification sent after the virtual time budget for the current VirtualTimePolicy has run out.