browser-commander 0.19.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

/// Payload of the `Page.frameAttached` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageFrameAttachedEventParams {
    #[serde(rename = "frame")]
    pub frame: Ref<Frame>,
}

/// Payload of the `Page.frameDetached` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageFrameDetachedEventParams {
    #[serde(rename = "frame")]
    pub frame: Ref<Frame>,
}

/// Payload of the `Page.locatorHandlerTriggered` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageLocatorHandlerTriggeredEventParams {
    #[serde(rename = "uid")]
    pub uid: i64,
}

/// Payload of the `Page.route` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageRouteEventParams {
    #[serde(rename = "route")]
    pub route: Ref<Route>,
}

/// Payload of the `Page.screencastFrame` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageScreencastFrameEventParams {
    #[serde(rename = "frameId")]
    pub frame_id: i64,
    #[serde(rename = "data")]
    pub data: Binary,
    #[serde(rename = "timestamp")]
    pub timestamp: f64,
    #[serde(rename = "viewportWidth")]
    pub viewport_width: i64,
    #[serde(rename = "viewportHeight")]
    pub viewport_height: i64,
}

/// Payload of the `Page.webSocketRoute` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageWebSocketRouteEventParams {
    #[serde(rename = "webSocketRoute")]
    pub web_socket_route: Ref<WebSocketRoute>,
}

/// Payload of the `Page.webSocket` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageWebSocketEventParams {
    #[serde(rename = "webSocket")]
    pub web_socket: Ref<WebSocket>,
}

/// Payload of the `Page.worker` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct PageWorkerEventParams {
    #[serde(rename = "worker")]
    pub worker: Ref<Worker>,
}

/// Events a `Page` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum PageEvent {
    /// `Page.bindingCall`
    BindingCall(PageBindingCallEventParams),
    /// `Page.close`
    Close,
    /// `Page.crash`
    Crash,
    /// `Page.download`
    Download(PageDownloadEventParams),
    /// `Page.viewportSizeChanged`
    ViewportSizeChanged(PageViewportSizeChangedEventParams),
    /// `Page.fileChooser`
    FileChooser(PageFileChooserEventParams),
    /// `Page.frameAttached`
    FrameAttached(PageFrameAttachedEventParams),
    /// `Page.frameDetached`
    FrameDetached(PageFrameDetachedEventParams),
    /// `Page.locatorHandlerTriggered`
    LocatorHandlerTriggered(PageLocatorHandlerTriggeredEventParams),
    /// `Page.route`
    Route(PageRouteEventParams),
    /// `Page.screencastFrame`
    ScreencastFrame(PageScreencastFrameEventParams),
    /// `Page.webSocketRoute`
    WebSocketRoute(PageWebSocketRouteEventParams),
    /// `Page.webSocket`
    WebSocket(PageWebSocketEventParams),
    /// `Page.worker`
    Worker(PageWorkerEventParams),
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        params: serde_json::Value,
    },
}

impl ProtocolEvent for PageEvent {
    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
        match method {
            "bindingCall" => Ok(Self::BindingCall(serde_json::from_value(params)?)),
            "close" => Ok(Self::Close),
            "crash" => Ok(Self::Crash),
            "download" => Ok(Self::Download(serde_json::from_value(params)?)),
            "viewportSizeChanged" => Ok(Self::ViewportSizeChanged(serde_json::from_value(params)?)),
            "fileChooser" => Ok(Self::FileChooser(serde_json::from_value(params)?)),
            "frameAttached" => Ok(Self::FrameAttached(serde_json::from_value(params)?)),
            "frameDetached" => Ok(Self::FrameDetached(serde_json::from_value(params)?)),
            "locatorHandlerTriggered" => Ok(Self::LocatorHandlerTriggered(serde_json::from_value(params)?)),
            "route" => Ok(Self::Route(serde_json::from_value(params)?)),
            "screencastFrame" => Ok(Self::ScreencastFrame(serde_json::from_value(params)?)),
            "webSocketRoute" => Ok(Self::WebSocketRoute(serde_json::from_value(params)?)),
            "webSocket" => Ok(Self::WebSocket(serde_json::from_value(params)?)),
            "worker" => Ok(Self::Worker(serde_json::from_value(params)?)),
            _ => Ok(Self::Unknown { method: method.to_string(), params }),
        }
    }
}

/// Channel for the `Page` interface (`page.yml`).
#[derive(Debug, Clone)]
pub struct Page {
    channel: Channel,
}

impl ChannelType for Page {
    const INTERFACE: &'static str = "Page";
    type Initializer = PageInitializer;
    type Event = PageEvent;

    fn accepts(interface: &str) -> bool {
        matches!(interface, "Page")
    }

    fn from_channel(channel: Channel) -> Self {
        Self { channel }
    }

    fn channel(&self) -> &Channel {
        &self.channel
    }
}

impl Page {
    /// `Page.addInitScript` ("Add init script").
    pub async fn add_init_script(&self, params: PageAddInitScriptParams) -> Result<PageAddInitScriptResult, ProtocolError> {
        self.channel.send("addInitScript", &params).await
    }

    /// `Page.close` ("Close page").
    pub async fn close(&self, params: PageCloseParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("close", &params).await
    }

    /// `Page.runBeforeUnload` ("Run beforeunload").
    pub async fn run_before_unload(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("runBeforeUnload", &serde_json::json!({})).await
    }

    /// `Page.clearConsoleMessages` ("Clear console messages").
    pub async fn clear_console_messages(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clearConsoleMessages", &serde_json::json!({})).await
    }

    /// `Page.consoleMessages` ("Get console messages").
    pub async fn console_messages(&self, params: PageConsoleMessagesParams) -> Result<PageConsoleMessagesResult, ProtocolError> {
        self.channel.send("consoleMessages", &params).await
    }

    /// `Page.emulateMedia` ("Emulate media").
    pub async fn emulate_media(&self, params: PageEmulateMediaParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("emulateMedia", &params).await
    }

    /// `Page.exposeBinding` ("Expose binding").
    pub async fn expose_binding(&self, params: PageExposeBindingParams) -> Result<PageExposeBindingResult, ProtocolError> {
        self.channel.send("exposeBinding", &params).await
    }

    /// `Page.goBack` ("Go back").
    pub async fn go_back(&self, params: PageGoBackParams) -> Result<PageGoBackResult, ProtocolError> {
        self.channel.send("goBack", &params).await
    }

    /// `Page.goForward` ("Go forward").
    pub async fn go_forward(&self, params: PageGoForwardParams) -> Result<PageGoForwardResult, ProtocolError> {
        self.channel.send("goForward", &params).await
    }

    /// `Page.requestGC` ("Request garbage collection").
    pub async fn request_gc(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("requestGC", &serde_json::json!({})).await
    }

    /// `Page.registerLocatorHandler` ("Register locator handler").
    pub async fn register_locator_handler(&self, params: PageRegisterLocatorHandlerParams) -> Result<PageRegisterLocatorHandlerResult, ProtocolError> {
        self.channel.send("registerLocatorHandler", &params).await
    }

    /// `Page.resolveLocatorHandlerNoReply` (internal).
    pub async fn resolve_locator_handler_no_reply(&self, params: PageResolveLocatorHandlerNoReplyParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("resolveLocatorHandlerNoReply", &params).await
    }

    /// `Page.unregisterLocatorHandler` ("Unregister locator handler").
    pub async fn unregister_locator_handler(&self, params: PageUnregisterLocatorHandlerParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("unregisterLocatorHandler", &params).await
    }

    /// `Page.reload` ("Reload").
    pub async fn reload(&self, params: PageReloadParams) -> Result<PageReloadResult, ProtocolError> {
        self.channel.send("reload", &params).await
    }

    /// `Page.expectScreenshot` ("Expect screenshot").
    pub async fn expect_screenshot(&self, params: PageExpectScreenshotParams) -> Result<PageExpectScreenshotResult, ProtocolError> {
        self.channel.send("expectScreenshot", &params).await
    }

    /// `Page.screenshot` ("Screenshot").
    pub async fn screenshot(&self, params: PageScreenshotParams) -> Result<PageScreenshotResult, ProtocolError> {
        self.channel.send("screenshot", &params).await
    }

    /// `Page.setExtraHTTPHeaders` ("Set extra HTTP headers").
    pub async fn set_extra_http_headers(&self, params: PageSetExtraHTTPHeadersParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setExtraHTTPHeaders", &params).await
    }

    /// `Page.setNetworkInterceptionPatterns` ("Route requests").
    pub async fn set_network_interception_patterns(&self, params: PageSetNetworkInterceptionPatternsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setNetworkInterceptionPatterns", &params).await
    }

    /// `Page.setWebSocketInterceptionPatterns` ("Route WebSockets").
    pub async fn set_web_socket_interception_patterns(&self, params: PageSetWebSocketInterceptionPatternsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setWebSocketInterceptionPatterns", &params).await
    }

    /// `Page.setViewportSize` ("Set viewport size").
    pub async fn set_viewport_size(&self, params: PageSetViewportSizeParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setViewportSize", &params).await
    }

    /// `Page.keyboardDown` ("Key down "{key}"").
    pub async fn keyboard_down(&self, params: PageKeyboardDownParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("keyboardDown", &params).await
    }

    /// `Page.keyboardUp` ("Key up "{key}"").
    pub async fn keyboard_up(&self, params: PageKeyboardUpParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("keyboardUp", &params).await
    }

    /// `Page.keyboardInsertText` ("Insert "{text}"").
    pub async fn keyboard_insert_text(&self, params: PageKeyboardInsertTextParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("keyboardInsertText", &params).await
    }

    /// `Page.keyboardType` ("Type "{text}"").
    pub async fn keyboard_type(&self, params: PageKeyboardTypeParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("keyboardType", &params).await
    }

    /// `Page.keyboardPress` ("Press "{key}"").
    pub async fn keyboard_press(&self, params: PageKeyboardPressParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("keyboardPress", &params).await
    }

    /// `Page.mouseMove` ("Mouse move").
    pub async fn mouse_move(&self, params: PageMouseMoveParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("mouseMove", &params).await
    }

    /// `Page.mouseDown` ("Mouse down").
    pub async fn mouse_down(&self, params: PageMouseDownParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("mouseDown", &params).await
    }

    /// `Page.mouseUp` ("Mouse up").
    pub async fn mouse_up(&self, params: PageMouseUpParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("mouseUp", &params).await
    }

    /// `Page.mouseClick` ("Click").
    pub async fn mouse_click(&self, params: PageMouseClickParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("mouseClick", &params).await
    }

    /// `Page.mouseWheel` ("Mouse wheel").
    pub async fn mouse_wheel(&self, params: PageMouseWheelParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("mouseWheel", &params).await
    }

    /// `Page.touchscreenTap` ("Tap").
    pub async fn touchscreen_tap(&self, params: PageTouchscreenTapParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("touchscreenTap", &params).await
    }

    /// `Page.clearPageErrors` ("Clear page errors").
    pub async fn clear_page_errors(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clearPageErrors", &serde_json::json!({})).await
    }

    /// `Page.pageErrors` ("Get page errors").
    pub async fn page_errors(&self, params: PagePageErrorsParams) -> Result<PagePageErrorsResult, ProtocolError> {
        self.channel.send("pageErrors", &params).await
    }

    /// `Page.pdf` ("PDF").
    pub async fn pdf(&self, params: PagePdfParams) -> Result<PagePdfResult, ProtocolError> {
        self.channel.send("pdf", &params).await
    }

    /// `Page.requests` ("Get network requests").
    pub async fn requests(&self) -> Result<PageRequestsResult, ProtocolError> {
        self.channel.send("requests", &serde_json::json!({})).await
    }

    /// `Page.startJSCoverage` ("Start JS coverage").
    pub async fn start_js_coverage(&self, params: PageStartJSCoverageParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("startJSCoverage", &params).await
    }

    /// `Page.stopJSCoverage` ("Stop JS coverage").
    pub async fn stop_js_coverage(&self) -> Result<PageStopJSCoverageResult, ProtocolError> {
        self.channel.send("stopJSCoverage", &serde_json::json!({})).await
    }

    /// `Page.startCSSCoverage` ("Start CSS coverage").
    pub async fn start_css_coverage(&self, params: PageStartCSSCoverageParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("startCSSCoverage", &params).await
    }

    /// `Page.stopCSSCoverage` ("Stop CSS coverage").
    pub async fn stop_css_coverage(&self) -> Result<PageStopCSSCoverageResult, ProtocolError> {
        self.channel.send("stopCSSCoverage", &serde_json::json!({})).await
    }

    /// `Page.bringToFront` ("Bring to front").
    pub async fn bring_to_front(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("bringToFront", &serde_json::json!({})).await
    }

    /// `Page.pickLocator` ("Pick locator").
    pub async fn pick_locator(&self) -> Result<PagePickLocatorResult, ProtocolError> {
        self.channel.send("pickLocator", &serde_json::json!({})).await
    }

    /// `Page.cancelPickLocator` ("Cancel pick locator").
    pub async fn cancel_pick_locator(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("cancelPickLocator", &serde_json::json!({})).await
    }

    /// `Page.hideHighlight` ("Hide all element highlights").
    pub async fn hide_highlight(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("hideHighlight", &serde_json::json!({})).await
    }

    /// `Page.screencastShowOverlay` ("Show overlay").
    pub async fn screencast_show_overlay(&self, params: PageScreencastShowOverlayParams) -> Result<PageScreencastShowOverlayResult, ProtocolError> {
        self.channel.send("screencastShowOverlay", &params).await
    }

    /// `Page.screencastRemoveOverlay` ("Remove overlay").
    pub async fn screencast_remove_overlay(&self, params: PageScreencastRemoveOverlayParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastRemoveOverlay", &params).await
    }

    /// `Page.screencastChapter` ("Show chapter overlay").
    pub async fn screencast_chapter(&self, params: PageScreencastChapterParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastChapter", &params).await
    }

    /// `Page.screencastSetOverlayVisible` ("Set overlay visibility").
    pub async fn screencast_set_overlay_visible(&self, params: PageScreencastSetOverlayVisibleParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastSetOverlayVisible", &params).await
    }

    /// `Page.screencastShowActions` ("Show actions").
    pub async fn screencast_show_actions(&self, params: PageScreencastShowActionsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastShowActions", &params).await
    }

    /// `Page.screencastHideActions` ("Remove actions").
    pub async fn screencast_hide_actions(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastHideActions", &serde_json::json!({})).await
    }

    /// `Page.screencastStart` ("Start screencast").
    pub async fn screencast_start(&self, params: PageScreencastStartParams) -> Result<PageScreencastStartResult, ProtocolError> {
        self.channel.send("screencastStart", &params).await
    }

    /// `Page.screencastFrameAck` (internal).
    pub async fn screencast_frame_ack(&self, params: PageScreencastFrameAckParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastFrameAck", &params).await
    }

    /// `Page.screencastStop` ("Stop screencast").
    pub async fn screencast_stop(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("screencastStop", &serde_json::json!({})).await
    }

    /// `Page.updateSubscription` (internal).
    pub async fn update_subscription(&self, params: PageUpdateSubscriptionParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("updateSubscription", &params).await
    }

    /// `Page.setDockTile` (internal).
    pub async fn set_dock_tile(&self, params: PageSetDockTileParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setDockTile", &params).await
    }

    /// `Page.webStorageItems` ("Get WebStorage items").
    pub async fn web_storage_items(&self, params: PageWebStorageItemsParams) -> Result<PageWebStorageItemsResult, ProtocolError> {
        self.channel.send("webStorageItems", &params).await
    }

    /// `Page.webStorageGetItem` ("Get WebStorage item").
    pub async fn web_storage_get_item(&self, params: PageWebStorageGetItemParams) -> Result<PageWebStorageGetItemResult, ProtocolError> {
        self.channel.send("webStorageGetItem", &params).await
    }

    /// `Page.webStorageSetItem` ("Set WebStorage item").
    pub async fn web_storage_set_item(&self, params: PageWebStorageSetItemParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("webStorageSetItem", &params).await
    }

    /// `Page.webStorageRemoveItem` ("Remove WebStorage item").
    pub async fn web_storage_remove_item(&self, params: PageWebStorageRemoveItemParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("webStorageRemoveItem", &params).await
    }

    /// `Page.webStorageClear` ("Clear WebStorage").
    pub async fn web_storage_clear(&self, params: PageWebStorageClearParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("webStorageClear", &params).await
    }
}