Input#

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 TouchPoint(x, y, radius_x=None, radius_y=None, rotation_angle=None, force=None, tangential_pressure=None, tilt_x=None, tilt_y=None, twist=None, id_=None)[source]#
x: float#

X coordinate of the event relative to the main frame’s viewport in CSS pixels.

y: float#

Y coordinate of the event relative to the main frame’s viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.

radius_x: Optional[float] = None#

1.0).

Type:

X radius of the touch area (default

radius_y: Optional[float] = None#

1.0).

Type:

Y radius of the touch area (default

rotation_angle: Optional[float] = None#

0.0).

Type:

Rotation angle (default

force: Optional[float] = None#

1.0).

Type:

Force (default

tangential_pressure: Optional[float] = None#

0).

Type:

The normalized tangential pressure, which has a range of [-1,1] (default

tilt_x: Optional[float] = None#
Type:

The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default

tilt_y: Optional[float] = None#

0).

Type:

The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default

twist: Optional[int] = None#

0).

Type:

The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default

id_: Optional[float] = None#

Identifier used to track touch sources between events, must be unique within an event.

class GestureSourceType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
DEFAULT = 'default'#
TOUCH = 'touch'#
MOUSE = 'mouse'#
class MouseButton(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
NONE = 'none'#
LEFT = 'left'#
MIDDLE = 'middle'#
RIGHT = 'right'#
BACK = 'back'#
FORWARD = 'forward'#
class TimeSinceEpoch(x=0, /)[source]#

UTC time in seconds, counted from January 1, 1970.

class DragDataItem(mime_type, data, title=None, base_url=None)[source]#
mime_type: str#

Mime type of the dragged data.

data: str#

Depending of the value of mimeType, it contains the dragged link, text, HTML markup or any other data.

title: Optional[str] = None#

Title associated with a link. Only valid when mimeType == “text/uri-list”.

base_url: Optional[str] = None#

Stores the base URL for the contained markup. Only valid when mimeType == “text/html”.

class DragData(items, drag_operations_mask, files=None)[source]#
items: List[DragDataItem]#
drag_operations_mask: int#

Bit field representing allowed drag operations. Copy = 1, Link = 2, Move = 16

files: Optional[List[str]] = None#

List of filenames that should be included when dropping

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.

cancel_dragging()[source]#

Cancels any active dragging in the page.

Return type:

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

dispatch_drag_event(type_, x, y, data, modifiers=None)[source]#

Dispatches a drag event into the page.

EXPERIMENTAL

Parameters:
  • type – Type of the drag event.

  • x (float) – X coordinate of the event relative to the main frame’s viewport in CSS pixels.

  • y (float) – Y coordinate of the event relative to the main frame’s viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.

  • data (DragData) –

  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).

Return type:

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

dispatch_key_event(type_, modifiers=None, timestamp=None, text=None, unmodified_text=None, key_identifier=None, code=None, key=None, windows_virtual_key_code=None, native_virtual_key_code=None, auto_repeat=None, is_keypad=None, is_system_key=None, location=None, commands=None)[source]#

Dispatches a key event to the page.

Parameters:
  • type – Type of the key event.

  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).

  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred.

  • text (Optional[str]) – (Optional) Text as generated by processing a virtual key code with a keyboard layout. Not needed for for `keyUp`` and ``rawKeyDown`` events (default: “”)

  • unmodified_text (Optional[str]) – (Optional) Text that would have been generated by the keyboard if no modifiers were pressed (except for shift). Useful for shortcut (accelerator) key handling (default: “”).

  • key_identifier (Optional[str]) – (Optional) Unique key identifier (e.g., ‘U+0041’) (default: “”).

  • code (Optional[str]) – (Optional) Unique DOM defined string value for each physical key (e.g., ‘KeyA’) (default: “”).

  • key (Optional[str]) – (Optional) Unique DOM defined string value describing the meaning of the key in the context of active modifiers, keyboard layout, etc (e.g., ‘AltGr’) (default: “”).

  • windows_virtual_key_code (Optional[int]) – (Optional) Windows virtual key code (default: 0).

  • native_virtual_key_code (Optional[int]) – (Optional) Native virtual key code (default: 0).

  • auto_repeat (Optional[bool]) – (Optional) Whether the event was generated from auto repeat (default: false).

  • is_keypad (Optional[bool]) – (Optional) Whether the event was generated from the keypad (default: false).

  • is_system_key (Optional[bool]) – (Optional) Whether the event was a system key event (default: false).

  • location (Optional[int]) – (Optional) Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default: 0).

  • commands (Optional[List[str]]) – (EXPERIMENTAL) (Optional) Editing commands to send with the key event (e.g., ‘selectAll’) (default: []). These are related to but not equal the command names used in ``document.execCommand` and NSStandardKeyBindingResponding. See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h for valid command names.

Return type:

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

dispatch_mouse_event(type_, x, y, modifiers=None, timestamp=None, button=None, buttons=None, click_count=None, force=None, tangential_pressure=None, tilt_x=None, tilt_y=None, twist=None, delta_x=None, delta_y=None, pointer_type=None)[source]#

Dispatches a mouse event to the page.

Parameters:
  • type – Type of the mouse event.

  • x (float) – X coordinate of the event relative to the main frame’s viewport in CSS pixels.

  • y (float) – Y coordinate of the event relative to the main frame’s viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.

  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).

  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred.

  • button (Optional[MouseButton]) – (Optional) Mouse button (default: “none”).

  • buttons (Optional[int]) – (Optional) A number indicating which buttons are pressed on the mouse when a mouse event is triggered. Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.

  • click_count (Optional[int]) – (Optional) Number of times the mouse button was clicked (default: 0).

  • force (Optional[float]) – (EXPERIMENTAL) (Optional) The normalized pressure, which has a range of [0,1] (default: 0).

  • tangential_pressure (Optional[float]) – (EXPERIMENTAL) (Optional) The normalized tangential pressure, which has a range of [-1,1] (default: 0).

  • tilt_x (Optional[float]) – (Optional) The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0).

  • tilt_y (Optional[float]) – (Optional) The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0).

  • twist (Optional[int]) – (EXPERIMENTAL) (Optional) The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0).

  • delta_x (Optional[float]) – (Optional) X delta in CSS pixels for mouse wheel event (default: 0).

  • delta_y (Optional[float]) – (Optional) Y delta in CSS pixels for mouse wheel event (default: 0).

  • pointer_type (Optional[str]) – (Optional) Pointer type (default: “mouse”).

Return type:

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

dispatch_touch_event(type_, touch_points, modifiers=None, timestamp=None)[source]#

Dispatches a touch event to the page.

Parameters:
  • type – Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while TouchStart and TouchMove must contains at least one.

  • touch_points (List[TouchPoint]) – Active touch points on the touch device. One event per any changed point (compared to previous touch event in a sequence) is generated, emulating pressing/moving/releasing points one by one.

  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).

  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred.

Return type:

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

emulate_touch_from_mouse_event(type_, x, y, button, timestamp=None, delta_x=None, delta_y=None, modifiers=None, click_count=None)[source]#

Emulates touch event from the mouse event parameters.

EXPERIMENTAL

Parameters:
  • type – Type of the mouse event.

  • x (int) – X coordinate of the mouse pointer in DIP.

  • y (int) – Y coordinate of the mouse pointer in DIP.

  • button (MouseButton) – Mouse button. Only “none”, “left”, “right” are supported.

  • timestamp (Optional[TimeSinceEpoch]) – (Optional) Time at which the event occurred (default: current time).

  • delta_x (Optional[float]) – (Optional) X delta in DIP for mouse wheel event (default: 0).

  • delta_y (Optional[float]) – (Optional) Y delta in DIP for mouse wheel event (default: 0).

  • modifiers (Optional[int]) – (Optional) Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0).

  • click_count (Optional[int]) – (Optional) Number of times the mouse button was clicked (default: 0).

Return type:

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

ime_set_composition(text, selection_start, selection_end, replacement_start=None, replacement_end=None)[source]#

This method sets the current candidate text for IME. Use imeCommitComposition to commit the final text. Use imeSetComposition with empty string as text to cancel composition.

EXPERIMENTAL

Parameters:
  • text (str) – The text to insert

  • selection_start (int) – selection start

  • selection_end (int) – selection end

  • replacement_start (Optional[int]) – (Optional) replacement start

  • replacement_end (Optional[int]) – (Optional) replacement end

Return type:

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

insert_text(text)[source]#

This method emulates inserting text that doesn’t come from a key press, for example an emoji keyboard or an IME.

EXPERIMENTAL

Parameters:

text (str) – The text to insert.

Return type:

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

set_ignore_input_events(ignore)[source]#

Ignores input events (useful while auditing page).

Parameters:

ignore (bool) – Ignores input events processing when set to true.

Return type:

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

set_intercept_drags(enabled)[source]#

Prevents default drag and drop behavior and instead emits Input.dragIntercepted events. Drag and drop behavior can be directly controlled via Input.dispatchDragEvent.

EXPERIMENTAL

Parameters:

enabled (bool) –

Return type:

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

synthesize_pinch_gesture(x, y, scale_factor, relative_speed=None, gesture_source_type=None)[source]#

Synthesizes a pinch gesture over a time period by issuing appropriate touch events.

EXPERIMENTAL

Parameters:
  • x (float) – X coordinate of the start of the gesture in CSS pixels.

  • y (float) – Y coordinate of the start of the gesture in CSS pixels.

  • scale_factor (float) – Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).

  • relative_speed (Optional[int]) – (Optional) Relative pointer speed in pixels per second (default: 800).

  • gesture_source_type (Optional[GestureSourceType]) – (Optional) Which type of input events to be generated (default: ‘default’, which queries the platform for the preferred input type).

Return type:

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

synthesize_scroll_gesture(x, y, x_distance=None, y_distance=None, x_overscroll=None, y_overscroll=None, prevent_fling=None, speed=None, gesture_source_type=None, repeat_count=None, repeat_delay_ms=None, interaction_marker_name=None)[source]#

Synthesizes a scroll gesture over a time period by issuing appropriate touch events.

EXPERIMENTAL

Parameters:
  • x (float) – X coordinate of the start of the gesture in CSS pixels.

  • y (float) – Y coordinate of the start of the gesture in CSS pixels.

  • x_distance (Optional[float]) – (Optional) The distance to scroll along the X axis (positive to scroll left).

  • y_distance (Optional[float]) – (Optional) The distance to scroll along the Y axis (positive to scroll up).

  • x_overscroll (Optional[float]) – (Optional) The number of additional pixels to scroll back along the X axis, in addition to the given distance.

  • y_overscroll (Optional[float]) – (Optional) The number of additional pixels to scroll back along the Y axis, in addition to the given distance.

  • prevent_fling (Optional[bool]) – (Optional) Prevent fling (default: true).

  • speed (Optional[int]) – (Optional) Swipe speed in pixels per second (default: 800).

  • gesture_source_type (Optional[GestureSourceType]) – (Optional) Which type of input events to be generated (default: ‘default’, which queries the platform for the preferred input type).

  • repeat_count (Optional[int]) – (Optional) The number of times to repeat the gesture (default: 0).

  • repeat_delay_ms (Optional[int]) – (Optional) The number of milliseconds delay between each repeat. (default: 250).

  • interaction_marker_name (Optional[str]) – (Optional) The name of the interaction markers to generate, if not empty (default: “”).

Return type:

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

synthesize_tap_gesture(x, y, duration=None, tap_count=None, gesture_source_type=None)[source]#

Synthesizes a tap gesture over a time period by issuing appropriate touch events.

EXPERIMENTAL

Parameters:
  • x (float) – X coordinate of the start of the gesture in CSS pixels.

  • y (float) – Y coordinate of the start of the gesture in CSS pixels.

  • duration (Optional[int]) – (Optional) Duration between touchdown and touchup events in ms (default: 50).

  • tap_count (Optional[int]) – (Optional) Number of times to perform the tap (e.g. 2 for double tap, default: 1).

  • gesture_source_type (Optional[GestureSourceType]) – (Optional) Which type of input events to be generated (default: ‘default’, which queries the platform for the preferred input type).

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 DragIntercepted(data)[source]#

EXPERIMENTAL

Emitted only when Input.setInterceptDrags is enabled. Use this data with Input.dispatchDragEvent to restore normal drag and drop behavior.

data: DragData#