Skip to main content

browser_commander/playwright/protocol/
page_2.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Payload of the `Page.frameAttached` event.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct PageFrameAttachedEventParams {
16    #[serde(rename = "frame")]
17    pub frame: Ref<Frame>,
18}
19
20/// Payload of the `Page.frameDetached` event.
21#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct PageFrameDetachedEventParams {
23    #[serde(rename = "frame")]
24    pub frame: Ref<Frame>,
25}
26
27/// Payload of the `Page.locatorHandlerTriggered` event.
28#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct PageLocatorHandlerTriggeredEventParams {
30    #[serde(rename = "uid")]
31    pub uid: i64,
32}
33
34/// Payload of the `Page.route` event.
35#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct PageRouteEventParams {
37    #[serde(rename = "route")]
38    pub route: Ref<Route>,
39}
40
41/// Payload of the `Page.screencastFrame` event.
42#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
43pub struct PageScreencastFrameEventParams {
44    #[serde(rename = "frameId")]
45    pub frame_id: i64,
46    #[serde(rename = "data")]
47    pub data: Binary,
48    #[serde(rename = "timestamp")]
49    pub timestamp: f64,
50    #[serde(rename = "viewportWidth")]
51    pub viewport_width: i64,
52    #[serde(rename = "viewportHeight")]
53    pub viewport_height: i64,
54}
55
56/// Payload of the `Page.webSocketRoute` event.
57#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
58pub struct PageWebSocketRouteEventParams {
59    #[serde(rename = "webSocketRoute")]
60    pub web_socket_route: Ref<WebSocketRoute>,
61}
62
63/// Payload of the `Page.webSocket` event.
64#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65pub struct PageWebSocketEventParams {
66    #[serde(rename = "webSocket")]
67    pub web_socket: Ref<WebSocket>,
68}
69
70/// Payload of the `Page.worker` event.
71#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
72pub struct PageWorkerEventParams {
73    #[serde(rename = "worker")]
74    pub worker: Ref<Worker>,
75}
76
77/// Events a `Page` channel can emit.
78#[derive(Debug, Clone, PartialEq)]
79pub enum PageEvent {
80    /// `Page.bindingCall`
81    BindingCall(PageBindingCallEventParams),
82    /// `Page.close`
83    Close,
84    /// `Page.crash`
85    Crash,
86    /// `Page.download`
87    Download(PageDownloadEventParams),
88    /// `Page.viewportSizeChanged`
89    ViewportSizeChanged(PageViewportSizeChangedEventParams),
90    /// `Page.fileChooser`
91    FileChooser(PageFileChooserEventParams),
92    /// `Page.frameAttached`
93    FrameAttached(PageFrameAttachedEventParams),
94    /// `Page.frameDetached`
95    FrameDetached(PageFrameDetachedEventParams),
96    /// `Page.locatorHandlerTriggered`
97    LocatorHandlerTriggered(PageLocatorHandlerTriggeredEventParams),
98    /// `Page.route`
99    Route(PageRouteEventParams),
100    /// `Page.screencastFrame`
101    ScreencastFrame(PageScreencastFrameEventParams),
102    /// `Page.webSocketRoute`
103    WebSocketRoute(PageWebSocketRouteEventParams),
104    /// `Page.webSocket`
105    WebSocket(PageWebSocketEventParams),
106    /// `Page.worker`
107    Worker(PageWorkerEventParams),
108    /// An event this binding does not know (a newer driver).
109    Unknown {
110        /// Event name.
111        method: String,
112        /// Raw event parameters.
113        params: serde_json::Value,
114    },
115}
116
117impl ProtocolEvent for PageEvent {
118    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
119        match method {
120            "bindingCall" => Ok(Self::BindingCall(serde_json::from_value(params)?)),
121            "close" => Ok(Self::Close),
122            "crash" => Ok(Self::Crash),
123            "download" => Ok(Self::Download(serde_json::from_value(params)?)),
124            "viewportSizeChanged" => Ok(Self::ViewportSizeChanged(serde_json::from_value(params)?)),
125            "fileChooser" => Ok(Self::FileChooser(serde_json::from_value(params)?)),
126            "frameAttached" => Ok(Self::FrameAttached(serde_json::from_value(params)?)),
127            "frameDetached" => Ok(Self::FrameDetached(serde_json::from_value(params)?)),
128            "locatorHandlerTriggered" => Ok(Self::LocatorHandlerTriggered(serde_json::from_value(params)?)),
129            "route" => Ok(Self::Route(serde_json::from_value(params)?)),
130            "screencastFrame" => Ok(Self::ScreencastFrame(serde_json::from_value(params)?)),
131            "webSocketRoute" => Ok(Self::WebSocketRoute(serde_json::from_value(params)?)),
132            "webSocket" => Ok(Self::WebSocket(serde_json::from_value(params)?)),
133            "worker" => Ok(Self::Worker(serde_json::from_value(params)?)),
134            _ => Ok(Self::Unknown { method: method.to_string(), params }),
135        }
136    }
137}
138
139/// Channel for the `Page` interface (`page.yml`).
140#[derive(Debug, Clone)]
141pub struct Page {
142    channel: Channel,
143}
144
145impl ChannelType for Page {
146    const INTERFACE: &'static str = "Page";
147    type Initializer = PageInitializer;
148    type Event = PageEvent;
149
150    fn accepts(interface: &str) -> bool {
151        matches!(interface, "Page")
152    }
153
154    fn from_channel(channel: Channel) -> Self {
155        Self { channel }
156    }
157
158    fn channel(&self) -> &Channel {
159        &self.channel
160    }
161}
162
163impl Page {
164    /// `Page.addInitScript` ("Add init script").
165    pub async fn add_init_script(&self, params: PageAddInitScriptParams) -> Result<PageAddInitScriptResult, ProtocolError> {
166        self.channel.send("addInitScript", &params).await
167    }
168
169    /// `Page.close` ("Close page").
170    pub async fn close(&self, params: PageCloseParams) -> Result<(), ProtocolError> {
171        self.channel.send_no_result("close", &params).await
172    }
173
174    /// `Page.runBeforeUnload` ("Run beforeunload").
175    pub async fn run_before_unload(&self) -> Result<(), ProtocolError> {
176        self.channel.send_no_result("runBeforeUnload", &serde_json::json!({})).await
177    }
178
179    /// `Page.clearConsoleMessages` ("Clear console messages").
180    pub async fn clear_console_messages(&self) -> Result<(), ProtocolError> {
181        self.channel.send_no_result("clearConsoleMessages", &serde_json::json!({})).await
182    }
183
184    /// `Page.consoleMessages` ("Get console messages").
185    pub async fn console_messages(&self, params: PageConsoleMessagesParams) -> Result<PageConsoleMessagesResult, ProtocolError> {
186        self.channel.send("consoleMessages", &params).await
187    }
188
189    /// `Page.emulateMedia` ("Emulate media").
190    pub async fn emulate_media(&self, params: PageEmulateMediaParams) -> Result<(), ProtocolError> {
191        self.channel.send_no_result("emulateMedia", &params).await
192    }
193
194    /// `Page.exposeBinding` ("Expose binding").
195    pub async fn expose_binding(&self, params: PageExposeBindingParams) -> Result<PageExposeBindingResult, ProtocolError> {
196        self.channel.send("exposeBinding", &params).await
197    }
198
199    /// `Page.goBack` ("Go back").
200    pub async fn go_back(&self, params: PageGoBackParams) -> Result<PageGoBackResult, ProtocolError> {
201        self.channel.send("goBack", &params).await
202    }
203
204    /// `Page.goForward` ("Go forward").
205    pub async fn go_forward(&self, params: PageGoForwardParams) -> Result<PageGoForwardResult, ProtocolError> {
206        self.channel.send("goForward", &params).await
207    }
208
209    /// `Page.requestGC` ("Request garbage collection").
210    pub async fn request_gc(&self) -> Result<(), ProtocolError> {
211        self.channel.send_no_result("requestGC", &serde_json::json!({})).await
212    }
213
214    /// `Page.registerLocatorHandler` ("Register locator handler").
215    pub async fn register_locator_handler(&self, params: PageRegisterLocatorHandlerParams) -> Result<PageRegisterLocatorHandlerResult, ProtocolError> {
216        self.channel.send("registerLocatorHandler", &params).await
217    }
218
219    /// `Page.resolveLocatorHandlerNoReply` (internal).
220    pub async fn resolve_locator_handler_no_reply(&self, params: PageResolveLocatorHandlerNoReplyParams) -> Result<(), ProtocolError> {
221        self.channel.send_no_result("resolveLocatorHandlerNoReply", &params).await
222    }
223
224    /// `Page.unregisterLocatorHandler` ("Unregister locator handler").
225    pub async fn unregister_locator_handler(&self, params: PageUnregisterLocatorHandlerParams) -> Result<(), ProtocolError> {
226        self.channel.send_no_result("unregisterLocatorHandler", &params).await
227    }
228
229    /// `Page.reload` ("Reload").
230    pub async fn reload(&self, params: PageReloadParams) -> Result<PageReloadResult, ProtocolError> {
231        self.channel.send("reload", &params).await
232    }
233
234    /// `Page.expectScreenshot` ("Expect screenshot").
235    pub async fn expect_screenshot(&self, params: PageExpectScreenshotParams) -> Result<PageExpectScreenshotResult, ProtocolError> {
236        self.channel.send("expectScreenshot", &params).await
237    }
238
239    /// `Page.screenshot` ("Screenshot").
240    pub async fn screenshot(&self, params: PageScreenshotParams) -> Result<PageScreenshotResult, ProtocolError> {
241        self.channel.send("screenshot", &params).await
242    }
243
244    /// `Page.setExtraHTTPHeaders` ("Set extra HTTP headers").
245    pub async fn set_extra_http_headers(&self, params: PageSetExtraHTTPHeadersParams) -> Result<(), ProtocolError> {
246        self.channel.send_no_result("setExtraHTTPHeaders", &params).await
247    }
248
249    /// `Page.setNetworkInterceptionPatterns` ("Route requests").
250    pub async fn set_network_interception_patterns(&self, params: PageSetNetworkInterceptionPatternsParams) -> Result<(), ProtocolError> {
251        self.channel.send_no_result("setNetworkInterceptionPatterns", &params).await
252    }
253
254    /// `Page.setWebSocketInterceptionPatterns` ("Route WebSockets").
255    pub async fn set_web_socket_interception_patterns(&self, params: PageSetWebSocketInterceptionPatternsParams) -> Result<(), ProtocolError> {
256        self.channel.send_no_result("setWebSocketInterceptionPatterns", &params).await
257    }
258
259    /// `Page.setViewportSize` ("Set viewport size").
260    pub async fn set_viewport_size(&self, params: PageSetViewportSizeParams) -> Result<(), ProtocolError> {
261        self.channel.send_no_result("setViewportSize", &params).await
262    }
263
264    /// `Page.keyboardDown` ("Key down "{key}"").
265    pub async fn keyboard_down(&self, params: PageKeyboardDownParams) -> Result<(), ProtocolError> {
266        self.channel.send_no_result("keyboardDown", &params).await
267    }
268
269    /// `Page.keyboardUp` ("Key up "{key}"").
270    pub async fn keyboard_up(&self, params: PageKeyboardUpParams) -> Result<(), ProtocolError> {
271        self.channel.send_no_result("keyboardUp", &params).await
272    }
273
274    /// `Page.keyboardInsertText` ("Insert "{text}"").
275    pub async fn keyboard_insert_text(&self, params: PageKeyboardInsertTextParams) -> Result<(), ProtocolError> {
276        self.channel.send_no_result("keyboardInsertText", &params).await
277    }
278
279    /// `Page.keyboardType` ("Type "{text}"").
280    pub async fn keyboard_type(&self, params: PageKeyboardTypeParams) -> Result<(), ProtocolError> {
281        self.channel.send_no_result("keyboardType", &params).await
282    }
283
284    /// `Page.keyboardPress` ("Press "{key}"").
285    pub async fn keyboard_press(&self, params: PageKeyboardPressParams) -> Result<(), ProtocolError> {
286        self.channel.send_no_result("keyboardPress", &params).await
287    }
288
289    /// `Page.mouseMove` ("Mouse move").
290    pub async fn mouse_move(&self, params: PageMouseMoveParams) -> Result<(), ProtocolError> {
291        self.channel.send_no_result("mouseMove", &params).await
292    }
293
294    /// `Page.mouseDown` ("Mouse down").
295    pub async fn mouse_down(&self, params: PageMouseDownParams) -> Result<(), ProtocolError> {
296        self.channel.send_no_result("mouseDown", &params).await
297    }
298
299    /// `Page.mouseUp` ("Mouse up").
300    pub async fn mouse_up(&self, params: PageMouseUpParams) -> Result<(), ProtocolError> {
301        self.channel.send_no_result("mouseUp", &params).await
302    }
303
304    /// `Page.mouseClick` ("Click").
305    pub async fn mouse_click(&self, params: PageMouseClickParams) -> Result<(), ProtocolError> {
306        self.channel.send_no_result("mouseClick", &params).await
307    }
308
309    /// `Page.mouseWheel` ("Mouse wheel").
310    pub async fn mouse_wheel(&self, params: PageMouseWheelParams) -> Result<(), ProtocolError> {
311        self.channel.send_no_result("mouseWheel", &params).await
312    }
313
314    /// `Page.touchscreenTap` ("Tap").
315    pub async fn touchscreen_tap(&self, params: PageTouchscreenTapParams) -> Result<(), ProtocolError> {
316        self.channel.send_no_result("touchscreenTap", &params).await
317    }
318
319    /// `Page.clearPageErrors` ("Clear page errors").
320    pub async fn clear_page_errors(&self) -> Result<(), ProtocolError> {
321        self.channel.send_no_result("clearPageErrors", &serde_json::json!({})).await
322    }
323
324    /// `Page.pageErrors` ("Get page errors").
325    pub async fn page_errors(&self, params: PagePageErrorsParams) -> Result<PagePageErrorsResult, ProtocolError> {
326        self.channel.send("pageErrors", &params).await
327    }
328
329    /// `Page.pdf` ("PDF").
330    pub async fn pdf(&self, params: PagePdfParams) -> Result<PagePdfResult, ProtocolError> {
331        self.channel.send("pdf", &params).await
332    }
333
334    /// `Page.requests` ("Get network requests").
335    pub async fn requests(&self) -> Result<PageRequestsResult, ProtocolError> {
336        self.channel.send("requests", &serde_json::json!({})).await
337    }
338
339    /// `Page.startJSCoverage` ("Start JS coverage").
340    pub async fn start_js_coverage(&self, params: PageStartJSCoverageParams) -> Result<(), ProtocolError> {
341        self.channel.send_no_result("startJSCoverage", &params).await
342    }
343
344    /// `Page.stopJSCoverage` ("Stop JS coverage").
345    pub async fn stop_js_coverage(&self) -> Result<PageStopJSCoverageResult, ProtocolError> {
346        self.channel.send("stopJSCoverage", &serde_json::json!({})).await
347    }
348
349    /// `Page.startCSSCoverage` ("Start CSS coverage").
350    pub async fn start_css_coverage(&self, params: PageStartCSSCoverageParams) -> Result<(), ProtocolError> {
351        self.channel.send_no_result("startCSSCoverage", &params).await
352    }
353
354    /// `Page.stopCSSCoverage` ("Stop CSS coverage").
355    pub async fn stop_css_coverage(&self) -> Result<PageStopCSSCoverageResult, ProtocolError> {
356        self.channel.send("stopCSSCoverage", &serde_json::json!({})).await
357    }
358
359    /// `Page.bringToFront` ("Bring to front").
360    pub async fn bring_to_front(&self) -> Result<(), ProtocolError> {
361        self.channel.send_no_result("bringToFront", &serde_json::json!({})).await
362    }
363
364    /// `Page.pickLocator` ("Pick locator").
365    pub async fn pick_locator(&self) -> Result<PagePickLocatorResult, ProtocolError> {
366        self.channel.send("pickLocator", &serde_json::json!({})).await
367    }
368
369    /// `Page.cancelPickLocator` ("Cancel pick locator").
370    pub async fn cancel_pick_locator(&self) -> Result<(), ProtocolError> {
371        self.channel.send_no_result("cancelPickLocator", &serde_json::json!({})).await
372    }
373
374    /// `Page.hideHighlight` ("Hide all element highlights").
375    pub async fn hide_highlight(&self) -> Result<(), ProtocolError> {
376        self.channel.send_no_result("hideHighlight", &serde_json::json!({})).await
377    }
378
379    /// `Page.screencastShowOverlay` ("Show overlay").
380    pub async fn screencast_show_overlay(&self, params: PageScreencastShowOverlayParams) -> Result<PageScreencastShowOverlayResult, ProtocolError> {
381        self.channel.send("screencastShowOverlay", &params).await
382    }
383
384    /// `Page.screencastRemoveOverlay` ("Remove overlay").
385    pub async fn screencast_remove_overlay(&self, params: PageScreencastRemoveOverlayParams) -> Result<(), ProtocolError> {
386        self.channel.send_no_result("screencastRemoveOverlay", &params).await
387    }
388
389    /// `Page.screencastChapter` ("Show chapter overlay").
390    pub async fn screencast_chapter(&self, params: PageScreencastChapterParams) -> Result<(), ProtocolError> {
391        self.channel.send_no_result("screencastChapter", &params).await
392    }
393
394    /// `Page.screencastSetOverlayVisible` ("Set overlay visibility").
395    pub async fn screencast_set_overlay_visible(&self, params: PageScreencastSetOverlayVisibleParams) -> Result<(), ProtocolError> {
396        self.channel.send_no_result("screencastSetOverlayVisible", &params).await
397    }
398
399    /// `Page.screencastShowActions` ("Show actions").
400    pub async fn screencast_show_actions(&self, params: PageScreencastShowActionsParams) -> Result<(), ProtocolError> {
401        self.channel.send_no_result("screencastShowActions", &params).await
402    }
403
404    /// `Page.screencastHideActions` ("Remove actions").
405    pub async fn screencast_hide_actions(&self) -> Result<(), ProtocolError> {
406        self.channel.send_no_result("screencastHideActions", &serde_json::json!({})).await
407    }
408
409    /// `Page.screencastStart` ("Start screencast").
410    pub async fn screencast_start(&self, params: PageScreencastStartParams) -> Result<PageScreencastStartResult, ProtocolError> {
411        self.channel.send("screencastStart", &params).await
412    }
413
414    /// `Page.screencastFrameAck` (internal).
415    pub async fn screencast_frame_ack(&self, params: PageScreencastFrameAckParams) -> Result<(), ProtocolError> {
416        self.channel.send_no_result("screencastFrameAck", &params).await
417    }
418
419    /// `Page.screencastStop` ("Stop screencast").
420    pub async fn screencast_stop(&self) -> Result<(), ProtocolError> {
421        self.channel.send_no_result("screencastStop", &serde_json::json!({})).await
422    }
423
424    /// `Page.updateSubscription` (internal).
425    pub async fn update_subscription(&self, params: PageUpdateSubscriptionParams) -> Result<(), ProtocolError> {
426        self.channel.send_no_result("updateSubscription", &params).await
427    }
428
429    /// `Page.setDockTile` (internal).
430    pub async fn set_dock_tile(&self, params: PageSetDockTileParams) -> Result<(), ProtocolError> {
431        self.channel.send_no_result("setDockTile", &params).await
432    }
433
434    /// `Page.webStorageItems` ("Get WebStorage items").
435    pub async fn web_storage_items(&self, params: PageWebStorageItemsParams) -> Result<PageWebStorageItemsResult, ProtocolError> {
436        self.channel.send("webStorageItems", &params).await
437    }
438
439    /// `Page.webStorageGetItem` ("Get WebStorage item").
440    pub async fn web_storage_get_item(&self, params: PageWebStorageGetItemParams) -> Result<PageWebStorageGetItemResult, ProtocolError> {
441        self.channel.send("webStorageGetItem", &params).await
442    }
443
444    /// `Page.webStorageSetItem` ("Set WebStorage item").
445    pub async fn web_storage_set_item(&self, params: PageWebStorageSetItemParams) -> Result<(), ProtocolError> {
446        self.channel.send_no_result("webStorageSetItem", &params).await
447    }
448
449    /// `Page.webStorageRemoveItem` ("Remove WebStorage item").
450    pub async fn web_storage_remove_item(&self, params: PageWebStorageRemoveItemParams) -> Result<(), ProtocolError> {
451        self.channel.send_no_result("webStorageRemoveItem", &params).await
452    }
453
454    /// `Page.webStorageClear` ("Clear WebStorage").
455    pub async fn web_storage_clear(&self, params: PageWebStorageClearParams) -> Result<(), ProtocolError> {
456        self.channel.send_no_result("webStorageClear", &params).await
457    }
458}