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