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]#
- class DisplayFeature(orientation, offset, mask_length)[source]#
- 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
- 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.
-
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.
-
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
-
brands:
- 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 SensorReading(single=None, xyz=None, quaternion=None)[source]#
-
single:
Optional[SensorReadingSingle] = None#
-
xyz:
Optional[SensorReadingXYZ] = None#
-
quaternion:
Optional[SensorReadingQuaternion] = None#
-
single:
- 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 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.
-
orientation:
ScreenOrientation# Specifies the screen’s orientation.
-
orientation:
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:
- Returns:
- can_emulate()[source]#
Tells whether emulation is supported.
Deprecated since version 1.3.
- Return type:
- Returns:
True if emulation is supported.
Deprecated since version 1.3.
- 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
- 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
- remove_screen(screen_id)[source]#
Remove screen from the device. Only supported in headless mode.
EXPERIMENTAL
- reset_page_scale_factor()[source]#
Requests that page scale factor is reset to initial values.
EXPERIMENTAL
- set_auto_dark_mode_override(enabled=None)[source]#
Automatically render all web contents using a dark theme.
EXPERIMENTAL
- set_data_saver_override(data_saver_enabled=None)[source]#
Override the value of navigator.connection.saveData
EXPERIMENTAL
- 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.
- 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:
- 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
- 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
- set_emulated_media(media=None, features=None)[source]#
Emulates the given media type or media feature for CSS media queries.
- set_focus_emulation_enabled(enabled)[source]#
Enables or disables simulating a focused and active page.
EXPERIMENTAL
- 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.
- set_locale_override(locale=None)[source]#
Overrides default host system locale with the specified one.
EXPERIMENTAL
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:
Deprecated since version 1.3.
- 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.
sourcemust have been previously overridden by setPressureSourceOverrideEnabled.EXPERIMENTAL
- 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
- 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.
sourcemust have been previously overridden by setPressureSourceOverrideEnabled.EXPERIMENTAL
- Parameters:
source (
PressureSource) –state (
PressureState) –
- Return type:
- 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
EXPERIMENTAL
- set_sensor_override_enabled(enabled, type_, metadata=None)[source]#
Overrides a platform sensor of a given type. If
enabledis 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
- set_sensor_override_readings(type_, reading)[source]#
Updates the sensor readings reported by a sensor type previously overridden by setSensorOverrideEnabled.
EXPERIMENTAL
- 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
svhandlvhunit, respectively. Only supported for top-level frames.EXPERIMENTAL
- 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:
- set_touch_emulation_enabled(enabled, max_touch_points=None)[source]#
Enables touch on platforms which do not support them.
- set_user_agent_override(user_agent, accept_language=None, platform=None, user_agent_metadata=None)[source]#
Allows overriding user agent with the given string.
userAgentMetadatamust 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:
- 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:
- 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:
- Return type:
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.