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 cdp.emulation.ScreenOrientation(type_, angle)

Screen orientation.

angle = None

Orientation angle.

type_ = None

Orientation type.

class cdp.emulation.VirtualTimePolicy

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'

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.

cdp.emulation.can_emulate()

Tells whether emulation is supported.

Return type:Generator[Dict[str, Any], Dict[str, Any], bool]
Returns:True if emulation is supported.
cdp.emulation.clear_device_metrics_override()

Clears the overriden device metrics.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.clear_geolocation_override()

Clears the overriden Geolocation Position and Error.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.reset_page_scale_factor()

Requests that page scale factor is reset to initial values.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.set_cpu_throttling_rate(rate)

Enables CPU throttling to emulate slow CPUs.

EXPERIMENTAL

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]
cdp.emulation.set_default_background_color_override(color=None)

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]
cdp.emulation.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)

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.
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]
cdp.emulation.set_emit_touch_events_for_mouse(enabled, configuration=None)

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]

cdp.emulation.set_emulated_media(media)

Emulates the given media for CSS media queries.

Parameters:media (str) – Media type to emulate. Empty string disables the override.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.set_focus_emulation_enabled(enabled)

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]
cdp.emulation.set_geolocation_override(latitude=None, longitude=None, accuracy=None)

Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.

Parameters:
  • latitude (Optional[float]) – (Optional) Mock latitude
  • longitude (Optional[float]) – (Optional) Mock longitude
  • accuracy (Optional[float]) – (Optional) Mock accuracy
Return type:

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

cdp.emulation.set_navigator_overrides(platform)

Overrides value returned by the javascript navigator object.

Deprecated since version 1.3.

EXPERIMENTAL

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

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.set_page_scale_factor(page_scale_factor)

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]
cdp.emulation.set_script_execution_disabled(value)

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]
cdp.emulation.set_scrollbars_hidden(hidden)

EXPERIMENTAL

Parameters:hidden (bool) – Whether scrollbars should be always hidden.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.set_timezone_override(timezone_id)

Overrides default host system timezone with the specified one.

EXPERIMENTAL

Parameters:timezone_id (str) – The timezone identifier. If empty, disables the override and restores default host system timezone.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.emulation.set_touch_emulation_enabled(enabled, max_touch_points=None)

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]

cdp.emulation.set_user_agent_override(user_agent, accept_language=None, platform=None)

Allows overriding user agent with the given string.

Parameters:
  • user_agent (str) – User agent to use.
  • accept_language (Optional[str]) – (Optional) Browser langugage to emulate.
  • platform (Optional[str]) – (Optional) The platform navigator.platform should return.
Return type:

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

cdp.emulation.set_virtual_time_policy(policy, budget=None, max_virtual_time_task_starvation_count=None, wait_for_navigation=None, initial_virtual_time=None)

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.
  • wait_for_navigation (Optional[bool]) – (Optional) If set the virtual time policy change should be deferred until any frame starts navigating. Note any previous deferred policy change is superseded.
  • initial_virtual_time (Optional[TimeSinceEpoch]) – (Optional) If set, base::Time::Now will be overriden 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).

cdp.emulation.set_visible_size(width, height)

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

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]

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 cdp.emulation.VirtualTimeBudgetExpired

EXPERIMENTAL

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