emulation
DevicePosture
dataclass
Source code in zendriver/cdp/emulation.py
type_: str
instance-attribute
__init__(type_)
from_json(json)
classmethod
DisabledImageType
Bases: Enum
Enum of image types that can be disabled.
Source code in zendriver/cdp/emulation.py
AVIF = 'avif'
class-attribute
instance-attribute
WEBP = 'webp'
class-attribute
instance-attribute
from_json(json)
classmethod
DisplayFeature
dataclass
Source code in zendriver/cdp/emulation.py
mask_length: int
instance-attribute
offset: int
instance-attribute
orientation: str
instance-attribute
__init__(orientation, offset, mask_length)
from_json(json)
classmethod
MediaFeature
dataclass
Source code in zendriver/cdp/emulation.py
name: str
instance-attribute
value: str
instance-attribute
__init__(name, value)
from_json(json)
classmethod
PressureMetadata
dataclass
Source code in zendriver/cdp/emulation.py
available: typing.Optional[bool] = None
class-attribute
instance-attribute
__init__(available=None)
from_json(json)
classmethod
PressureSource
Bases: Enum
Source code in zendriver/cdp/emulation.py
CPU = 'cpu'
class-attribute
instance-attribute
from_json(json)
classmethod
PressureState
Bases: Enum
Source code in zendriver/cdp/emulation.py
CRITICAL = 'critical'
class-attribute
instance-attribute
FAIR = 'fair'
class-attribute
instance-attribute
NOMINAL = 'nominal'
class-attribute
instance-attribute
SERIOUS = 'serious'
class-attribute
instance-attribute
from_json(json)
classmethod
ScreenOrientation
dataclass
Screen orientation.
Source code in zendriver/cdp/emulation.py
angle: int
instance-attribute
type_: str
instance-attribute
__init__(type_, angle)
from_json(json)
classmethod
SensorMetadata
dataclass
Source code in zendriver/cdp/emulation.py
available: typing.Optional[bool] = None
class-attribute
instance-attribute
maximum_frequency: typing.Optional[float] = None
class-attribute
instance-attribute
minimum_frequency: typing.Optional[float] = None
class-attribute
instance-attribute
__init__(available=None, minimum_frequency=None, maximum_frequency=None)
from_json(json)
classmethod
Source code in zendriver/cdp/emulation.py
to_json()
Source code in zendriver/cdp/emulation.py
SensorReading
dataclass
Source code in zendriver/cdp/emulation.py
quaternion: typing.Optional[SensorReadingQuaternion] = None
class-attribute
instance-attribute
single: typing.Optional[SensorReadingSingle] = None
class-attribute
instance-attribute
xyz: typing.Optional[SensorReadingXYZ] = None
class-attribute
instance-attribute
__init__(single=None, xyz=None, quaternion=None)
from_json(json)
classmethod
Source code in zendriver/cdp/emulation.py
to_json()
Source code in zendriver/cdp/emulation.py
SensorReadingQuaternion
dataclass
Source code in zendriver/cdp/emulation.py
w: float
instance-attribute
x: float
instance-attribute
y: float
instance-attribute
z: float
instance-attribute
__init__(x, y, z, w)
from_json(json)
classmethod
SensorReadingSingle
dataclass
Source code in zendriver/cdp/emulation.py
value: float
instance-attribute
__init__(value)
from_json(json)
classmethod
SensorReadingXYZ
dataclass
Source code in zendriver/cdp/emulation.py
x: float
instance-attribute
y: float
instance-attribute
z: float
instance-attribute
__init__(x, y, z)
from_json(json)
classmethod
SensorType
Bases: Enum
Used to specify sensor types to emulate. See https://w3c.github.io/sensors/#automation for more information.
Source code in zendriver/cdp/emulation.py
ABSOLUTE_ORIENTATION = 'absolute-orientation'
class-attribute
instance-attribute
ACCELEROMETER = 'accelerometer'
class-attribute
instance-attribute
AMBIENT_LIGHT = 'ambient-light'
class-attribute
instance-attribute
GRAVITY = 'gravity'
class-attribute
instance-attribute
GYROSCOPE = 'gyroscope'
class-attribute
instance-attribute
LINEAR_ACCELERATION = 'linear-acceleration'
class-attribute
instance-attribute
MAGNETOMETER = 'magnetometer'
class-attribute
instance-attribute
RELATIVE_ORIENTATION = 'relative-orientation'
class-attribute
instance-attribute
from_json(json)
classmethod
UserAgentBrandVersion
dataclass
Used to specify User Agent Client Hints to emulate. See https://wicg.github.io/ua-client-hints
Source code in zendriver/cdp/emulation.py
brand: str
instance-attribute
version: str
instance-attribute
__init__(brand, version)
from_json(json)
classmethod
UserAgentMetadata
dataclass
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.
Source code in zendriver/cdp/emulation.py
architecture: str
instance-attribute
bitness: typing.Optional[str] = None
class-attribute
instance-attribute
brands: typing.Optional[typing.List[UserAgentBrandVersion]] = None
class-attribute
instance-attribute
full_version: typing.Optional[str] = None
class-attribute
instance-attribute
full_version_list: typing.Optional[typing.List[UserAgentBrandVersion]] = None
class-attribute
instance-attribute
mobile: bool
instance-attribute
model: str
instance-attribute
platform: str
instance-attribute
platform_version: str
instance-attribute
wow64: typing.Optional[bool] = None
class-attribute
instance-attribute
__init__(platform, platform_version, architecture, model, mobile, brands=None, full_version_list=None, full_version=None, bitness=None, wow64=None)
from_json(json)
classmethod
Source code in zendriver/cdp/emulation.py
to_json()
Source code in zendriver/cdp/emulation.py
VirtualTimeBudgetExpired
dataclass
EXPERIMENTAL
Notification sent after the virtual time budget for the current VirtualTimePolicy has run out.
Source code in zendriver/cdp/emulation.py
VirtualTimePolicy
Bases: Enum
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.
Source code in zendriver/cdp/emulation.py
ADVANCE = 'advance'
class-attribute
instance-attribute
PAUSE = 'pause'
class-attribute
instance-attribute
PAUSE_IF_NETWORK_FETCHES_PENDING = 'pauseIfNetworkFetchesPending'
class-attribute
instance-attribute
from_json(json)
classmethod
can_emulate()
Tells whether emulation is supported.
.. deprecated:: 1.3
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, bool]
|
True if emulation is supported. |
Source code in zendriver/cdp/emulation.py
clear_device_metrics_override()
Clears the overridden device metrics.
Source code in zendriver/cdp/emulation.py
clear_device_posture_override()
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
Source code in zendriver/cdp/emulation.py
clear_geolocation_override()
Clears the overridden Geolocation Position and Error.
Source code in zendriver/cdp/emulation.py
clear_idle_override()
Clears Idle state overrides.
get_overridden_sensor_information(type_)
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_
|
SensorType
|
|
required |
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, float]
|
|
Source code in zendriver/cdp/emulation.py
reset_page_scale_factor()
Requests that page scale factor is reset to initial values.
EXPERIMENTAL
Source code in zendriver/cdp/emulation.py
set_auto_dark_mode_override(enabled=None)
Automatically render all web contents using a dark theme.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
Optional[bool]
|
(Optional) Whether to enable or disable automatic dark mode. If not specified, any existing override will be cleared. |
None
|
Source code in zendriver/cdp/emulation.py
set_automation_override(enabled)
Allows overriding the automation flag.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether the override should be enabled. |
required |
Source code in zendriver/cdp/emulation.py
set_cpu_throttling_rate(rate)
Enables CPU throttling to emulate slow CPUs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rate
|
float
|
Throttling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc). |
required |
Source code in zendriver/cdp/emulation.py
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:
Name | Type | Description | Default |
---|---|---|---|
color
|
Optional[RGBA]
|
(Optional) RGBA of the default background color. If not specified, any existing override will be cleared. |
None
|
Source code in zendriver/cdp/emulation.py
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)
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:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override. |
required |
height
|
int
|
Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override. |
required |
device_scale_factor
|
float
|
Overriding device scale factor value. 0 disables the override. |
required |
mobile
|
bool
|
Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more. |
required |
scale
|
Optional[float]
|
(EXPERIMENTAL) (Optional) Scale to apply to resulting view image. |
None
|
screen_width
|
Optional[int]
|
(EXPERIMENTAL) (Optional) Overriding screen width value in pixels (minimum 0, maximum 10000000). |
None
|
screen_height
|
Optional[int]
|
(EXPERIMENTAL) (Optional) Overriding screen height value in pixels (minimum 0, maximum 10000000). |
None
|
position_x
|
Optional[int]
|
(EXPERIMENTAL) (Optional) Overriding view X position on screen in pixels (minimum 0, maximum 10000000). |
None
|
position_y
|
Optional[int]
|
(EXPERIMENTAL) (Optional) Overriding view Y position on screen in pixels (minimum 0, maximum 10000000). |
None
|
dont_set_visible_size
|
Optional[bool]
|
(EXPERIMENTAL) (Optional) Do not set visible view size, rely upon explicit setVisibleSize call. |
None
|
screen_orientation
|
Optional[ScreenOrientation]
|
(Optional) Screen orientation override. |
None
|
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. |
None
|
display_feature
|
Optional[DisplayFeature]
|
(EXPERIMENTAL) (Optional) If set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off. |
None
|
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. |
None
|
Source code in zendriver/cdp/emulation.py
set_device_posture_override(posture)
Start reporting the given posture value to the Device Posture API. This override can also be set in setDeviceMetricsOverride().
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
posture
|
DevicePosture
|
|
required |
Source code in zendriver/cdp/emulation.py
set_disabled_image_types(image_types)
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_types
|
List[DisabledImageType]
|
Image types to disable. |
required |
Source code in zendriver/cdp/emulation.py
set_document_cookie_disabled(disabled)
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
disabled
|
bool
|
Whether document.coookie API should be disabled. |
required |
Source code in zendriver/cdp/emulation.py
set_emit_touch_events_for_mouse(enabled, configuration=None)
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether touch emulation based on mouse input should be enabled. |
required |
configuration
|
Optional[str]
|
(Optional) Touch/gesture events configuration. Default: current platform. |
None
|
Source code in zendriver/cdp/emulation.py
set_emulated_media(media=None, features=None)
Emulates the given media type or media feature for CSS media queries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
media
|
Optional[str]
|
(Optional) Media type to emulate. Empty string disables the override. |
None
|
features
|
Optional[List[MediaFeature]]
|
(Optional) Media features to emulate. |
None
|
Source code in zendriver/cdp/emulation.py
set_emulated_vision_deficiency(type_)
Emulates the given vision deficiency.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_
|
str
|
Vision deficiency to emulate. Order: best-effort emulations come first, followed by any physiologically accurate emulations for medically recognized color vision deficiencies. |
required |
Source code in zendriver/cdp/emulation.py
set_focus_emulation_enabled(enabled)
Enables or disables simulating a focused and active page.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether to enable to disable focus emulation. |
required |
Source code in zendriver/cdp/emulation.py
set_geolocation_override(latitude=None, longitude=None, accuracy=None)
Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
latitude
|
Optional[float]
|
(Optional) Mock latitude |
None
|
longitude
|
Optional[float]
|
(Optional) Mock longitude |
None
|
accuracy
|
Optional[float]
|
(Optional) Mock accuracy |
None
|
Source code in zendriver/cdp/emulation.py
set_hardware_concurrency_override(hardware_concurrency)
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hardware_concurrency
|
int
|
Hardware concurrency to report |
required |
Source code in zendriver/cdp/emulation.py
set_idle_override(is_user_active, is_screen_unlocked)
Overrides the Idle state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_user_active
|
bool
|
Mock isUserActive |
required |
is_screen_unlocked
|
bool
|
Mock isScreenUnlocked |
required |
Source code in zendriver/cdp/emulation.py
set_locale_override(locale=None)
Overrides default host system locale with the specified one.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
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. |
None
|
Source code in zendriver/cdp/emulation.py
set_navigator_overrides(platform)
Overrides value returned by the javascript navigator object.
.. deprecated:: 1.3
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
platform
|
str
|
The platform navigator.platform should return. |
required |
Source code in zendriver/cdp/emulation.py
set_page_scale_factor(page_scale_factor)
Sets a specified page scale factor.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_scale_factor
|
float
|
Page scale factor. |
required |
Source code in zendriver/cdp/emulation.py
set_pressure_source_override_enabled(enabled, source, metadata=None)
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:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
|
required |
source
|
PressureSource
|
|
required |
metadata
|
Optional[PressureMetadata]
|
(Optional) |
None
|
Source code in zendriver/cdp/emulation.py
set_pressure_state_override(source, state)
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:
Name | Type | Description | Default |
---|---|---|---|
source
|
PressureSource
|
|
required |
state
|
PressureState
|
|
required |
Source code in zendriver/cdp/emulation.py
set_script_execution_disabled(value)
Switches script execution in the page.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
bool
|
Whether script execution should be disabled in the page. |
required |
Source code in zendriver/cdp/emulation.py
set_scrollbars_hidden(hidden)
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hidden
|
bool
|
Whether scrollbars should be always hidden. |
required |
Source code in zendriver/cdp/emulation.py
set_sensor_override_enabled(enabled, type_, metadata=None)
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:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
|
required |
type_
|
SensorType
|
|
required |
metadata
|
Optional[SensorMetadata]
|
(Optional) |
None
|
Source code in zendriver/cdp/emulation.py
set_sensor_override_readings(type_, reading)
Updates the sensor readings reported by a sensor type previously overridden by setSensorOverrideEnabled.
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_
|
SensorType
|
|
required |
reading
|
SensorReading
|
|
required |
Source code in zendriver/cdp/emulation.py
set_timezone_override(timezone_id)
Overrides default host system timezone with the specified one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
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. |
required |
Source code in zendriver/cdp/emulation.py
set_touch_emulation_enabled(enabled, max_touch_points=None)
Enables touch on platforms which do not support them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether the touch event emulation should be enabled. |
required |
max_touch_points
|
Optional[int]
|
(Optional) Maximum touch points supported. Defaults to one. |
None
|
Source code in zendriver/cdp/emulation.py
set_user_agent_override(user_agent, accept_language=None, platform=None, user_agent_metadata=None)
Allows overriding user agent with the given string.
userAgentMetadata
must be set for Client Hint headers to be sent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_agent
|
str
|
User agent to use. |
required |
accept_language
|
Optional[str]
|
(Optional) Browser language to emulate. |
None
|
platform
|
Optional[str]
|
(Optional) The platform navigator.platform should return. |
None
|
user_agent_metadata
|
Optional[UserAgentMetadata]
|
(EXPERIMENTAL) (Optional) To be sent in Sec-CH-UA-* headers and returned in navigator.userAgentData |
None
|
Source code in zendriver/cdp/emulation.py
set_virtual_time_policy(policy, budget=None, max_virtual_time_task_starvation_count=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:
Name | Type | Description | Default |
---|---|---|---|
policy
|
VirtualTimePolicy
|
|
required |
budget
|
Optional[float]
|
(Optional) If set, after this many virtual milliseconds have elapsed virtual time will be paused and a virtualTimeBudgetExpired event is sent. |
None
|
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. |
None
|
initial_virtual_time
|
Optional[TimeSinceEpoch]
|
(Optional) If set, base::Time::Now will be overridden to initially return this value. |
None
|
Returns:
Type | Description |
---|---|
Generator[T_JSON_DICT, T_JSON_DICT, float]
|
Absolute timestamp at which virtual time was first enabled (up time in milliseconds). |
Source code in zendriver/cdp/emulation.py
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:: 1.3
EXPERIMENTAL
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
Frame width (DIP). |
required |
height
|
int
|
Frame height (DIP). |
required |