1#![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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct PageFrameAttachedEventParams {
16 #[serde(rename = "frame")]
17 pub frame: Ref<Frame>,
18}
19
20#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
22pub struct PageFrameDetachedEventParams {
23 #[serde(rename = "frame")]
24 pub frame: Ref<Frame>,
25}
26
27#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
29pub struct PageLocatorHandlerTriggeredEventParams {
30 #[serde(rename = "uid")]
31 pub uid: i64,
32}
33
34#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
36pub struct PageRouteEventParams {
37 #[serde(rename = "route")]
38 pub route: Ref<Route>,
39}
40
41#[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#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
58pub struct PageWebSocketRouteEventParams {
59 #[serde(rename = "webSocketRoute")]
60 pub web_socket_route: Ref<WebSocketRoute>,
61}
62
63#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
65pub struct PageWebSocketEventParams {
66 #[serde(rename = "webSocket")]
67 pub web_socket: Ref<WebSocket>,
68}
69
70#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
72pub struct PageWorkerEventParams {
73 #[serde(rename = "worker")]
74 pub worker: Ref<Worker>,
75}
76
77#[derive(Debug, Clone, PartialEq)]
79pub enum PageEvent {
80 BindingCall(PageBindingCallEventParams),
82 Close,
84 Crash,
86 Download(PageDownloadEventParams),
88 ViewportSizeChanged(PageViewportSizeChangedEventParams),
90 FileChooser(PageFileChooserEventParams),
92 FrameAttached(PageFrameAttachedEventParams),
94 FrameDetached(PageFrameDetachedEventParams),
96 LocatorHandlerTriggered(PageLocatorHandlerTriggeredEventParams),
98 Route(PageRouteEventParams),
100 ScreencastFrame(PageScreencastFrameEventParams),
102 WebSocketRoute(PageWebSocketRouteEventParams),
104 WebSocket(PageWebSocketEventParams),
106 Worker(PageWorkerEventParams),
108 Unknown {
110 method: String,
112 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#[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 pub async fn add_init_script(&self, params: PageAddInitScriptParams) -> Result<PageAddInitScriptResult, ProtocolError> {
166 self.channel.send("addInitScript", ¶ms).await
167 }
168
169 pub async fn close(&self, params: PageCloseParams) -> Result<(), ProtocolError> {
171 self.channel.send_no_result("close", ¶ms).await
172 }
173
174 pub async fn run_before_unload(&self) -> Result<(), ProtocolError> {
176 self.channel.send_no_result("runBeforeUnload", &serde_json::json!({})).await
177 }
178
179 pub async fn clear_console_messages(&self) -> Result<(), ProtocolError> {
181 self.channel.send_no_result("clearConsoleMessages", &serde_json::json!({})).await
182 }
183
184 pub async fn console_messages(&self, params: PageConsoleMessagesParams) -> Result<PageConsoleMessagesResult, ProtocolError> {
186 self.channel.send("consoleMessages", ¶ms).await
187 }
188
189 pub async fn emulate_media(&self, params: PageEmulateMediaParams) -> Result<(), ProtocolError> {
191 self.channel.send_no_result("emulateMedia", ¶ms).await
192 }
193
194 pub async fn expose_binding(&self, params: PageExposeBindingParams) -> Result<PageExposeBindingResult, ProtocolError> {
196 self.channel.send("exposeBinding", ¶ms).await
197 }
198
199 pub async fn go_back(&self, params: PageGoBackParams) -> Result<PageGoBackResult, ProtocolError> {
201 self.channel.send("goBack", ¶ms).await
202 }
203
204 pub async fn go_forward(&self, params: PageGoForwardParams) -> Result<PageGoForwardResult, ProtocolError> {
206 self.channel.send("goForward", ¶ms).await
207 }
208
209 pub async fn request_gc(&self) -> Result<(), ProtocolError> {
211 self.channel.send_no_result("requestGC", &serde_json::json!({})).await
212 }
213
214 pub async fn register_locator_handler(&self, params: PageRegisterLocatorHandlerParams) -> Result<PageRegisterLocatorHandlerResult, ProtocolError> {
216 self.channel.send("registerLocatorHandler", ¶ms).await
217 }
218
219 pub async fn resolve_locator_handler_no_reply(&self, params: PageResolveLocatorHandlerNoReplyParams) -> Result<(), ProtocolError> {
221 self.channel.send_no_result("resolveLocatorHandlerNoReply", ¶ms).await
222 }
223
224 pub async fn unregister_locator_handler(&self, params: PageUnregisterLocatorHandlerParams) -> Result<(), ProtocolError> {
226 self.channel.send_no_result("unregisterLocatorHandler", ¶ms).await
227 }
228
229 pub async fn reload(&self, params: PageReloadParams) -> Result<PageReloadResult, ProtocolError> {
231 self.channel.send("reload", ¶ms).await
232 }
233
234 pub async fn expect_screenshot(&self, params: PageExpectScreenshotParams) -> Result<PageExpectScreenshotResult, ProtocolError> {
236 self.channel.send("expectScreenshot", ¶ms).await
237 }
238
239 pub async fn screenshot(&self, params: PageScreenshotParams) -> Result<PageScreenshotResult, ProtocolError> {
241 self.channel.send("screenshot", ¶ms).await
242 }
243
244 pub async fn set_extra_http_headers(&self, params: PageSetExtraHTTPHeadersParams) -> Result<(), ProtocolError> {
246 self.channel.send_no_result("setExtraHTTPHeaders", ¶ms).await
247 }
248
249 pub async fn set_network_interception_patterns(&self, params: PageSetNetworkInterceptionPatternsParams) -> Result<(), ProtocolError> {
251 self.channel.send_no_result("setNetworkInterceptionPatterns", ¶ms).await
252 }
253
254 pub async fn set_web_socket_interception_patterns(&self, params: PageSetWebSocketInterceptionPatternsParams) -> Result<(), ProtocolError> {
256 self.channel.send_no_result("setWebSocketInterceptionPatterns", ¶ms).await
257 }
258
259 pub async fn set_viewport_size(&self, params: PageSetViewportSizeParams) -> Result<(), ProtocolError> {
261 self.channel.send_no_result("setViewportSize", ¶ms).await
262 }
263
264 pub async fn keyboard_down(&self, params: PageKeyboardDownParams) -> Result<(), ProtocolError> {
266 self.channel.send_no_result("keyboardDown", ¶ms).await
267 }
268
269 pub async fn keyboard_up(&self, params: PageKeyboardUpParams) -> Result<(), ProtocolError> {
271 self.channel.send_no_result("keyboardUp", ¶ms).await
272 }
273
274 pub async fn keyboard_insert_text(&self, params: PageKeyboardInsertTextParams) -> Result<(), ProtocolError> {
276 self.channel.send_no_result("keyboardInsertText", ¶ms).await
277 }
278
279 pub async fn keyboard_type(&self, params: PageKeyboardTypeParams) -> Result<(), ProtocolError> {
281 self.channel.send_no_result("keyboardType", ¶ms).await
282 }
283
284 pub async fn keyboard_press(&self, params: PageKeyboardPressParams) -> Result<(), ProtocolError> {
286 self.channel.send_no_result("keyboardPress", ¶ms).await
287 }
288
289 pub async fn mouse_move(&self, params: PageMouseMoveParams) -> Result<(), ProtocolError> {
291 self.channel.send_no_result("mouseMove", ¶ms).await
292 }
293
294 pub async fn mouse_down(&self, params: PageMouseDownParams) -> Result<(), ProtocolError> {
296 self.channel.send_no_result("mouseDown", ¶ms).await
297 }
298
299 pub async fn mouse_up(&self, params: PageMouseUpParams) -> Result<(), ProtocolError> {
301 self.channel.send_no_result("mouseUp", ¶ms).await
302 }
303
304 pub async fn mouse_click(&self, params: PageMouseClickParams) -> Result<(), ProtocolError> {
306 self.channel.send_no_result("mouseClick", ¶ms).await
307 }
308
309 pub async fn mouse_wheel(&self, params: PageMouseWheelParams) -> Result<(), ProtocolError> {
311 self.channel.send_no_result("mouseWheel", ¶ms).await
312 }
313
314 pub async fn touchscreen_tap(&self, params: PageTouchscreenTapParams) -> Result<(), ProtocolError> {
316 self.channel.send_no_result("touchscreenTap", ¶ms).await
317 }
318
319 pub async fn clear_page_errors(&self) -> Result<(), ProtocolError> {
321 self.channel.send_no_result("clearPageErrors", &serde_json::json!({})).await
322 }
323
324 pub async fn page_errors(&self, params: PagePageErrorsParams) -> Result<PagePageErrorsResult, ProtocolError> {
326 self.channel.send("pageErrors", ¶ms).await
327 }
328
329 pub async fn pdf(&self, params: PagePdfParams) -> Result<PagePdfResult, ProtocolError> {
331 self.channel.send("pdf", ¶ms).await
332 }
333
334 pub async fn requests(&self) -> Result<PageRequestsResult, ProtocolError> {
336 self.channel.send("requests", &serde_json::json!({})).await
337 }
338
339 pub async fn start_js_coverage(&self, params: PageStartJSCoverageParams) -> Result<(), ProtocolError> {
341 self.channel.send_no_result("startJSCoverage", ¶ms).await
342 }
343
344 pub async fn stop_js_coverage(&self) -> Result<PageStopJSCoverageResult, ProtocolError> {
346 self.channel.send("stopJSCoverage", &serde_json::json!({})).await
347 }
348
349 pub async fn start_css_coverage(&self, params: PageStartCSSCoverageParams) -> Result<(), ProtocolError> {
351 self.channel.send_no_result("startCSSCoverage", ¶ms).await
352 }
353
354 pub async fn stop_css_coverage(&self) -> Result<PageStopCSSCoverageResult, ProtocolError> {
356 self.channel.send("stopCSSCoverage", &serde_json::json!({})).await
357 }
358
359 pub async fn bring_to_front(&self) -> Result<(), ProtocolError> {
361 self.channel.send_no_result("bringToFront", &serde_json::json!({})).await
362 }
363
364 pub async fn pick_locator(&self) -> Result<PagePickLocatorResult, ProtocolError> {
366 self.channel.send("pickLocator", &serde_json::json!({})).await
367 }
368
369 pub async fn cancel_pick_locator(&self) -> Result<(), ProtocolError> {
371 self.channel.send_no_result("cancelPickLocator", &serde_json::json!({})).await
372 }
373
374 pub async fn hide_highlight(&self) -> Result<(), ProtocolError> {
376 self.channel.send_no_result("hideHighlight", &serde_json::json!({})).await
377 }
378
379 pub async fn screencast_show_overlay(&self, params: PageScreencastShowOverlayParams) -> Result<PageScreencastShowOverlayResult, ProtocolError> {
381 self.channel.send("screencastShowOverlay", ¶ms).await
382 }
383
384 pub async fn screencast_remove_overlay(&self, params: PageScreencastRemoveOverlayParams) -> Result<(), ProtocolError> {
386 self.channel.send_no_result("screencastRemoveOverlay", ¶ms).await
387 }
388
389 pub async fn screencast_chapter(&self, params: PageScreencastChapterParams) -> Result<(), ProtocolError> {
391 self.channel.send_no_result("screencastChapter", ¶ms).await
392 }
393
394 pub async fn screencast_set_overlay_visible(&self, params: PageScreencastSetOverlayVisibleParams) -> Result<(), ProtocolError> {
396 self.channel.send_no_result("screencastSetOverlayVisible", ¶ms).await
397 }
398
399 pub async fn screencast_show_actions(&self, params: PageScreencastShowActionsParams) -> Result<(), ProtocolError> {
401 self.channel.send_no_result("screencastShowActions", ¶ms).await
402 }
403
404 pub async fn screencast_hide_actions(&self) -> Result<(), ProtocolError> {
406 self.channel.send_no_result("screencastHideActions", &serde_json::json!({})).await
407 }
408
409 pub async fn screencast_start(&self, params: PageScreencastStartParams) -> Result<PageScreencastStartResult, ProtocolError> {
411 self.channel.send("screencastStart", ¶ms).await
412 }
413
414 pub async fn screencast_frame_ack(&self, params: PageScreencastFrameAckParams) -> Result<(), ProtocolError> {
416 self.channel.send_no_result("screencastFrameAck", ¶ms).await
417 }
418
419 pub async fn screencast_stop(&self) -> Result<(), ProtocolError> {
421 self.channel.send_no_result("screencastStop", &serde_json::json!({})).await
422 }
423
424 pub async fn update_subscription(&self, params: PageUpdateSubscriptionParams) -> Result<(), ProtocolError> {
426 self.channel.send_no_result("updateSubscription", ¶ms).await
427 }
428
429 pub async fn set_dock_tile(&self, params: PageSetDockTileParams) -> Result<(), ProtocolError> {
431 self.channel.send_no_result("setDockTile", ¶ms).await
432 }
433
434 pub async fn web_storage_items(&self, params: PageWebStorageItemsParams) -> Result<PageWebStorageItemsResult, ProtocolError> {
436 self.channel.send("webStorageItems", ¶ms).await
437 }
438
439 pub async fn web_storage_get_item(&self, params: PageWebStorageGetItemParams) -> Result<PageWebStorageGetItemResult, ProtocolError> {
441 self.channel.send("webStorageGetItem", ¶ms).await
442 }
443
444 pub async fn web_storage_set_item(&self, params: PageWebStorageSetItemParams) -> Result<(), ProtocolError> {
446 self.channel.send_no_result("webStorageSetItem", ¶ms).await
447 }
448
449 pub async fn web_storage_remove_item(&self, params: PageWebStorageRemoveItemParams) -> Result<(), ProtocolError> {
451 self.channel.send_no_result("webStorageRemoveItem", ¶ms).await
452 }
453
454 pub async fn web_storage_clear(&self, params: PageWebStorageClearParams) -> Result<(), ProtocolError> {
456 self.channel.send_no_result("webStorageClear", ¶ms).await
457 }
458}