Skip to main content

browser_protocol/input/
mod.rs

1use serde::{Serialize, Deserialize};
2use serde_json::Value as JsonValue;
3
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6#[serde(rename_all = "camelCase")]
7pub struct TouchPoint {
8    /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
9
10    pub x: f64,
11    /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
12    /// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
13
14    pub y: f64,
15    /// X radius of the touch area (default: 1.0).
16
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub radiusX: Option<f64>,
19    /// Y radius of the touch area (default: 1.0).
20
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub radiusY: Option<f64>,
23    /// Rotation angle (default: 0.0).
24
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub rotationAngle: Option<f64>,
27    /// Force (default: 1.0).
28
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub force: Option<f64>,
31    /// The normalized tangential pressure, which has a range of [-1,1] (default: 0).
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub tangentialPressure: Option<f64>,
35    /// 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)
36
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub tiltX: Option<f64>,
39    /// 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).
40
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub tiltY: Option<f64>,
43    /// The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0).
44
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub twist: Option<i64>,
47    /// Identifier used to track touch sources between events, must be unique within an event.
48
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub id: Option<f64>,
51}
52
53
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
55pub enum GestureSourceType {
56    #[default]
57    Default,
58    Touch,
59    Mouse,
60}
61
62
63#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
64pub enum MouseButton {
65    #[default]
66    None,
67    Left,
68    Middle,
69    Right,
70    Back,
71    Forward,
72}
73
74/// UTC time in seconds, counted from January 1, 1970.
75
76pub type TimeSinceEpoch = f64;
77
78
79#[derive(Debug, Clone, Serialize, Deserialize, Default)]
80#[serde(rename_all = "camelCase")]
81pub struct DragDataItem {
82    /// Mime type of the dragged data.
83
84    pub mimeType: String,
85    /// Depending of the value of 'mimeType', it contains the dragged link,
86    /// text, HTML markup or any other data.
87
88    pub data: String,
89    /// Title associated with a link. Only valid when 'mimeType' == "text/uri-list".
90
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub title: Option<String>,
93    /// Stores the base URL for the contained markup. Only valid when 'mimeType'
94    /// == "text/html".
95
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub baseURL: Option<String>,
98}
99
100
101#[derive(Debug, Clone, Serialize, Deserialize, Default)]
102#[serde(rename_all = "camelCase")]
103pub struct DragData {
104
105    pub items: Vec<DragDataItem>,
106    /// List of filenames that should be included when dropping
107
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub files: Option<Vec<String>>,
110    /// Bit field representing allowed drag operations. Copy = 1, Link = 2, Move = 16
111
112    pub dragOperationsMask: i64,
113}
114
115/// Dispatches a drag event into the page.
116
117#[derive(Debug, Clone, Serialize, Deserialize, Default)]
118#[serde(rename_all = "camelCase")]
119pub struct DispatchDragEventParams {
120    /// Type of the drag event.
121
122    #[serde(rename = "type")]
123    pub type_: String,
124    /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
125
126    pub x: f64,
127    /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
128    /// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
129
130    pub y: f64,
131
132    pub data: DragData,
133    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
134    /// (default: 0).
135
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub modifiers: Option<i64>,
138}
139
140impl DispatchDragEventParams { pub const METHOD: &'static str = "Input.dispatchDragEvent"; }
141
142impl crate::CdpCommand for DispatchDragEventParams {
143    const METHOD: &'static str = "Input.dispatchDragEvent";
144    type Response = crate::EmptyReturns;
145}
146
147/// Dispatches a key event to the page.
148
149#[derive(Debug, Clone, Serialize, Deserialize, Default)]
150#[serde(rename_all = "camelCase")]
151pub struct DispatchKeyEventParams {
152    /// Type of the key event.
153
154    #[serde(rename = "type")]
155    pub type_: String,
156    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
157    /// (default: 0).
158
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub modifiers: Option<i64>,
161    /// Time at which the event occurred.
162
163    #[serde(skip_serializing_if = "Option::is_none")]
164    pub timestamp: Option<TimeSinceEpoch>,
165    /// Text as generated by processing a virtual key code with a keyboard layout. Not needed for
166    /// for 'keyUp' and 'rawKeyDown' events (default: "")
167
168    #[serde(skip_serializing_if = "Option::is_none")]
169    pub text: Option<String>,
170    /// Text that would have been generated by the keyboard if no modifiers were pressed (except for
171    /// shift). Useful for shortcut (accelerator) key handling (default: "").
172
173    #[serde(skip_serializing_if = "Option::is_none")]
174    pub unmodifiedText: Option<String>,
175    /// Unique key identifier (e.g., 'U+0041') (default: "").
176
177    #[serde(skip_serializing_if = "Option::is_none")]
178    pub keyIdentifier: Option<String>,
179    /// Unique DOM defined string value for each physical key (e.g., 'KeyA') (default: "").
180
181    #[serde(skip_serializing_if = "Option::is_none")]
182    pub code: Option<String>,
183    /// Unique DOM defined string value describing the meaning of the key in the context of active
184    /// modifiers, keyboard layout, etc (e.g., 'AltGr') (default: "").
185
186    #[serde(skip_serializing_if = "Option::is_none")]
187    pub key: Option<String>,
188    /// Windows virtual key code (default: 0).
189
190    #[serde(skip_serializing_if = "Option::is_none")]
191    pub windowsVirtualKeyCode: Option<i64>,
192    /// Native virtual key code (default: 0).
193
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub nativeVirtualKeyCode: Option<i64>,
196    /// Whether the event was generated from auto repeat (default: false).
197
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub autoRepeat: Option<bool>,
200    /// Whether the event was generated from the keypad (default: false).
201
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub isKeypad: Option<bool>,
204    /// Whether the event was a system key event (default: false).
205
206    #[serde(skip_serializing_if = "Option::is_none")]
207    pub isSystemKey: Option<bool>,
208    /// Whether the event was from the left or right side of the keyboard. 1=Left, 2=Right (default:
209    /// 0).
210
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub location: Option<i64>,
213    /// Editing commands to send with the key event (e.g., 'selectAll') (default: []).
214    /// These are related to but not equal the command names used in 'document.execCommand' and NSStandardKeyBindingResponding.
215    /// See https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/commands/editor_command_names.h for valid command names.
216
217    #[serde(skip_serializing_if = "Option::is_none")]
218    pub commands: Option<Vec<String>>,
219}
220
221impl DispatchKeyEventParams { pub const METHOD: &'static str = "Input.dispatchKeyEvent"; }
222
223impl crate::CdpCommand for DispatchKeyEventParams {
224    const METHOD: &'static str = "Input.dispatchKeyEvent";
225    type Response = crate::EmptyReturns;
226}
227
228/// This method emulates inserting text that doesn't come from a key press,
229/// for example an emoji keyboard or an IME.
230
231#[derive(Debug, Clone, Serialize, Deserialize, Default)]
232#[serde(rename_all = "camelCase")]
233pub struct InsertTextParams {
234    /// The text to insert.
235
236    pub text: String,
237}
238
239impl InsertTextParams { pub const METHOD: &'static str = "Input.insertText"; }
240
241impl crate::CdpCommand for InsertTextParams {
242    const METHOD: &'static str = "Input.insertText";
243    type Response = crate::EmptyReturns;
244}
245
246/// This method sets the current candidate text for IME.
247/// Use imeCommitComposition to commit the final text.
248/// Use imeSetComposition with empty string as text to cancel composition.
249
250#[derive(Debug, Clone, Serialize, Deserialize, Default)]
251#[serde(rename_all = "camelCase")]
252pub struct ImeSetCompositionParams {
253    /// The text to insert
254
255    pub text: String,
256    /// selection start
257
258    pub selectionStart: i64,
259    /// selection end
260
261    pub selectionEnd: i64,
262    /// replacement start
263
264    #[serde(skip_serializing_if = "Option::is_none")]
265    pub replacementStart: Option<i64>,
266    /// replacement end
267
268    #[serde(skip_serializing_if = "Option::is_none")]
269    pub replacementEnd: Option<i64>,
270}
271
272impl ImeSetCompositionParams { pub const METHOD: &'static str = "Input.imeSetComposition"; }
273
274impl crate::CdpCommand for ImeSetCompositionParams {
275    const METHOD: &'static str = "Input.imeSetComposition";
276    type Response = crate::EmptyReturns;
277}
278
279/// Dispatches a mouse event to the page.
280
281#[derive(Debug, Clone, Serialize, Deserialize, Default)]
282#[serde(rename_all = "camelCase")]
283pub struct DispatchMouseEventParams {
284    /// Type of the mouse event.
285
286    #[serde(rename = "type")]
287    pub type_: String,
288    /// X coordinate of the event relative to the main frame's viewport in CSS pixels.
289
290    pub x: f64,
291    /// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to
292    /// the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
293
294    pub y: f64,
295    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
296    /// (default: 0).
297
298    #[serde(skip_serializing_if = "Option::is_none")]
299    pub modifiers: Option<i64>,
300    /// Time at which the event occurred.
301
302    #[serde(skip_serializing_if = "Option::is_none")]
303    pub timestamp: Option<TimeSinceEpoch>,
304    /// Mouse button (default: "none").
305
306    #[serde(skip_serializing_if = "Option::is_none")]
307    pub button: Option<MouseButton>,
308    /// A number indicating which buttons are pressed on the mouse when a mouse event is triggered.
309    /// Left=1, Right=2, Middle=4, Back=8, Forward=16, None=0.
310
311    #[serde(skip_serializing_if = "Option::is_none")]
312    pub buttons: Option<i64>,
313    /// Number of times the mouse button was clicked (default: 0).
314
315    #[serde(skip_serializing_if = "Option::is_none")]
316    pub clickCount: Option<u64>,
317    /// The normalized pressure, which has a range of [0,1] (default: 0).
318
319    #[serde(skip_serializing_if = "Option::is_none")]
320    pub force: Option<f64>,
321    /// The normalized tangential pressure, which has a range of [-1,1] (default: 0).
322
323    #[serde(skip_serializing_if = "Option::is_none")]
324    pub tangentialPressure: Option<f64>,
325    /// 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).
326
327    #[serde(skip_serializing_if = "Option::is_none")]
328    pub tiltX: Option<f64>,
329    /// 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).
330
331    #[serde(skip_serializing_if = "Option::is_none")]
332    pub tiltY: Option<f64>,
333    /// The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0).
334
335    #[serde(skip_serializing_if = "Option::is_none")]
336    pub twist: Option<i64>,
337    /// X delta in CSS pixels for mouse wheel event (default: 0).
338
339    #[serde(skip_serializing_if = "Option::is_none")]
340    pub deltaX: Option<f64>,
341    /// Y delta in CSS pixels for mouse wheel event (default: 0).
342
343    #[serde(skip_serializing_if = "Option::is_none")]
344    pub deltaY: Option<f64>,
345    /// Pointer type (default: "mouse").
346
347    #[serde(skip_serializing_if = "Option::is_none")]
348    pub pointerType: Option<String>,
349}
350
351impl DispatchMouseEventParams { pub const METHOD: &'static str = "Input.dispatchMouseEvent"; }
352
353impl crate::CdpCommand for DispatchMouseEventParams {
354    const METHOD: &'static str = "Input.dispatchMouseEvent";
355    type Response = crate::EmptyReturns;
356}
357
358/// Dispatches a touch event to the page.
359
360#[derive(Debug, Clone, Serialize, Deserialize, Default)]
361#[serde(rename_all = "camelCase")]
362pub struct DispatchTouchEventParams {
363    /// Type of the touch event. TouchEnd and TouchCancel must not contain any touch points, while
364    /// TouchStart and TouchMove must contains at least one.
365
366    #[serde(rename = "type")]
367    pub type_: String,
368    /// Active touch points on the touch device. One event per any changed point (compared to
369    /// previous touch event in a sequence) is generated, emulating pressing/moving/releasing points
370    /// one by one.
371
372    pub touchPoints: Vec<TouchPoint>,
373    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
374    /// (default: 0).
375
376    #[serde(skip_serializing_if = "Option::is_none")]
377    pub modifiers: Option<i64>,
378    /// Time at which the event occurred.
379
380    #[serde(skip_serializing_if = "Option::is_none")]
381    pub timestamp: Option<TimeSinceEpoch>,
382}
383
384impl DispatchTouchEventParams { pub const METHOD: &'static str = "Input.dispatchTouchEvent"; }
385
386impl crate::CdpCommand for DispatchTouchEventParams {
387    const METHOD: &'static str = "Input.dispatchTouchEvent";
388    type Response = crate::EmptyReturns;
389}
390
391#[derive(Debug, Clone, Serialize, Deserialize, Default)]
392pub struct CancelDraggingParams {}
393
394impl CancelDraggingParams { pub const METHOD: &'static str = "Input.cancelDragging"; }
395
396impl crate::CdpCommand for CancelDraggingParams {
397    const METHOD: &'static str = "Input.cancelDragging";
398    type Response = crate::EmptyReturns;
399}
400
401/// Emulates touch event from the mouse event parameters.
402
403#[derive(Debug, Clone, Serialize, Deserialize, Default)]
404#[serde(rename_all = "camelCase")]
405pub struct EmulateTouchFromMouseEventParams {
406    /// Type of the mouse event.
407
408    #[serde(rename = "type")]
409    pub type_: String,
410    /// X coordinate of the mouse pointer in DIP.
411
412    pub x: i32,
413    /// Y coordinate of the mouse pointer in DIP.
414
415    pub y: i32,
416    /// Mouse button. Only "none", "left", "right" are supported.
417
418    pub button: MouseButton,
419    /// Time at which the event occurred (default: current time).
420
421    #[serde(skip_serializing_if = "Option::is_none")]
422    pub timestamp: Option<TimeSinceEpoch>,
423    /// X delta in DIP for mouse wheel event (default: 0).
424
425    #[serde(skip_serializing_if = "Option::is_none")]
426    pub deltaX: Option<f64>,
427    /// Y delta in DIP for mouse wheel event (default: 0).
428
429    #[serde(skip_serializing_if = "Option::is_none")]
430    pub deltaY: Option<f64>,
431    /// Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8
432    /// (default: 0).
433
434    #[serde(skip_serializing_if = "Option::is_none")]
435    pub modifiers: Option<i64>,
436    /// Number of times the mouse button was clicked (default: 0).
437
438    #[serde(skip_serializing_if = "Option::is_none")]
439    pub clickCount: Option<u64>,
440}
441
442impl EmulateTouchFromMouseEventParams { pub const METHOD: &'static str = "Input.emulateTouchFromMouseEvent"; }
443
444impl crate::CdpCommand for EmulateTouchFromMouseEventParams {
445    const METHOD: &'static str = "Input.emulateTouchFromMouseEvent";
446    type Response = crate::EmptyReturns;
447}
448
449/// Ignores input events (useful while auditing page).
450
451#[derive(Debug, Clone, Serialize, Deserialize, Default)]
452#[serde(rename_all = "camelCase")]
453pub struct SetIgnoreInputEventsParams {
454    /// Ignores input events processing when set to true.
455
456    pub ignore: bool,
457}
458
459impl SetIgnoreInputEventsParams { pub const METHOD: &'static str = "Input.setIgnoreInputEvents"; }
460
461impl crate::CdpCommand for SetIgnoreInputEventsParams {
462    const METHOD: &'static str = "Input.setIgnoreInputEvents";
463    type Response = crate::EmptyReturns;
464}
465
466/// Prevents default drag and drop behavior and instead emits 'Input.dragIntercepted' events.
467/// Drag and drop behavior can be directly controlled via 'Input.dispatchDragEvent'.
468
469#[derive(Debug, Clone, Serialize, Deserialize, Default)]
470#[serde(rename_all = "camelCase")]
471pub struct SetInterceptDragsParams {
472
473    pub enabled: bool,
474}
475
476impl SetInterceptDragsParams { pub const METHOD: &'static str = "Input.setInterceptDrags"; }
477
478impl crate::CdpCommand for SetInterceptDragsParams {
479    const METHOD: &'static str = "Input.setInterceptDrags";
480    type Response = crate::EmptyReturns;
481}
482
483/// Synthesizes a pinch gesture over a time period by issuing appropriate touch events.
484
485#[derive(Debug, Clone, Serialize, Deserialize, Default)]
486#[serde(rename_all = "camelCase")]
487pub struct SynthesizePinchGestureParams {
488    /// X coordinate of the start of the gesture in CSS pixels.
489
490    pub x: f64,
491    /// Y coordinate of the start of the gesture in CSS pixels.
492
493    pub y: f64,
494    /// Relative scale factor after zooming (>1.0 zooms in, <1.0 zooms out).
495
496    pub scaleFactor: f64,
497    /// Relative pointer speed in pixels per second (default: 800).
498
499    #[serde(skip_serializing_if = "Option::is_none")]
500    pub relativeSpeed: Option<i64>,
501    /// Which type of input events to be generated (default: 'default', which queries the platform
502    /// for the preferred input type).
503
504    #[serde(skip_serializing_if = "Option::is_none")]
505    pub gestureSourceType: Option<GestureSourceType>,
506}
507
508impl SynthesizePinchGestureParams { pub const METHOD: &'static str = "Input.synthesizePinchGesture"; }
509
510impl crate::CdpCommand for SynthesizePinchGestureParams {
511    const METHOD: &'static str = "Input.synthesizePinchGesture";
512    type Response = crate::EmptyReturns;
513}
514
515/// Synthesizes a scroll gesture over a time period by issuing appropriate touch events.
516
517#[derive(Debug, Clone, Serialize, Deserialize, Default)]
518#[serde(rename_all = "camelCase")]
519pub struct SynthesizeScrollGestureParams {
520    /// X coordinate of the start of the gesture in CSS pixels.
521
522    pub x: f64,
523    /// Y coordinate of the start of the gesture in CSS pixels.
524
525    pub y: f64,
526    /// The distance to scroll along the X axis (positive to scroll left).
527
528    #[serde(skip_serializing_if = "Option::is_none")]
529    pub xDistance: Option<f64>,
530    /// The distance to scroll along the Y axis (positive to scroll up).
531
532    #[serde(skip_serializing_if = "Option::is_none")]
533    pub yDistance: Option<f64>,
534    /// The number of additional pixels to scroll back along the X axis, in addition to the given
535    /// distance.
536
537    #[serde(skip_serializing_if = "Option::is_none")]
538    pub xOverscroll: Option<f64>,
539    /// The number of additional pixels to scroll back along the Y axis, in addition to the given
540    /// distance.
541
542    #[serde(skip_serializing_if = "Option::is_none")]
543    pub yOverscroll: Option<f64>,
544    /// Prevent fling (default: true).
545
546    #[serde(skip_serializing_if = "Option::is_none")]
547    pub preventFling: Option<bool>,
548    /// Swipe speed in pixels per second (default: 800).
549
550    #[serde(skip_serializing_if = "Option::is_none")]
551    pub speed: Option<i64>,
552    /// Which type of input events to be generated (default: 'default', which queries the platform
553    /// for the preferred input type).
554
555    #[serde(skip_serializing_if = "Option::is_none")]
556    pub gestureSourceType: Option<GestureSourceType>,
557    /// The number of times to repeat the gesture (default: 0).
558
559    #[serde(skip_serializing_if = "Option::is_none")]
560    pub repeatCount: Option<u64>,
561    /// The number of milliseconds delay between each repeat. (default: 250).
562
563    #[serde(skip_serializing_if = "Option::is_none")]
564    pub repeatDelayMs: Option<i64>,
565    /// The name of the interaction markers to generate, if not empty (default: "").
566
567    #[serde(skip_serializing_if = "Option::is_none")]
568    pub interactionMarkerName: Option<String>,
569}
570
571impl SynthesizeScrollGestureParams { pub const METHOD: &'static str = "Input.synthesizeScrollGesture"; }
572
573impl crate::CdpCommand for SynthesizeScrollGestureParams {
574    const METHOD: &'static str = "Input.synthesizeScrollGesture";
575    type Response = crate::EmptyReturns;
576}
577
578/// Synthesizes a tap gesture over a time period by issuing appropriate touch events.
579
580#[derive(Debug, Clone, Serialize, Deserialize, Default)]
581#[serde(rename_all = "camelCase")]
582pub struct SynthesizeTapGestureParams {
583    /// X coordinate of the start of the gesture in CSS pixels.
584
585    pub x: f64,
586    /// Y coordinate of the start of the gesture in CSS pixels.
587
588    pub y: f64,
589    /// Duration between touchdown and touchup events in ms (default: 50).
590
591    #[serde(skip_serializing_if = "Option::is_none")]
592    pub duration: Option<i64>,
593    /// Number of times to perform the tap (e.g. 2 for double tap, default: 1).
594
595    #[serde(skip_serializing_if = "Option::is_none")]
596    pub tapCount: Option<u64>,
597    /// Which type of input events to be generated (default: 'default', which queries the platform
598    /// for the preferred input type).
599
600    #[serde(skip_serializing_if = "Option::is_none")]
601    pub gestureSourceType: Option<GestureSourceType>,
602}
603
604impl SynthesizeTapGestureParams { pub const METHOD: &'static str = "Input.synthesizeTapGesture"; }
605
606impl crate::CdpCommand for SynthesizeTapGestureParams {
607    const METHOD: &'static str = "Input.synthesizeTapGesture";
608    type Response = crate::EmptyReturns;
609}