1#![allow(clippy::all, missing_docs, unused_imports, non_snake_case)]
5
6use serde_json::Value;
7
8use super::*;
9use crate::puppeteer::bridge::{binary, remote_type, BridgeError, JsFunction, Remote};
10
11remote_type!(
12 Page
17);
18
19impl Page {
20 pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Page, BridgeError> {
26 self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
27 }
28
29 pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<Page, BridgeError> {
35 self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
36 }
37
38 pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
44 self.remote.call("emit", vec![Some(type_), Some(event)]).await
45 }
46
47 pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Page, BridgeError> {
53 self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
54 }
55
56 pub async fn listener_count(&self, type_: Value) -> Result<f64, BridgeError> {
62 self.remote.call("listenerCount", vec![Some(type_)]).await
63 }
64
65 pub async fn remove_all_listeners(&self, type_: Option<Value>) -> Result<Page, BridgeError> {
71 self.remote.call("removeAllListeners", vec![type_]).await
72 }
73
74 pub async fn is_service_worker_bypassed(&self) -> Result<bool, BridgeError> {
80 self.remote.call("isServiceWorkerBypassed", vec![]).await
81 }
82
83 pub async fn is_drag_interception_enabled(&self) -> Result<bool, BridgeError> {
89 self.remote.call("isDragInterceptionEnabled", vec![]).await
90 }
91
92 pub async fn is_java_script_enabled(&self) -> Result<bool, BridgeError> {
98 self.remote.call("isJavaScriptEnabled", vec![]).await
99 }
100
101 pub async fn wait_for_file_chooser(&self, options: Option<Value>) -> Result<FileChooser, BridgeError> {
107 self.remote.call("waitForFileChooser", vec![options]).await
108 }
109
110 pub async fn set_geolocation(&self, options: Value) -> Result<(), BridgeError> {
116 self.remote.call("setGeolocation", vec![Some(options)]).await
117 }
118
119 pub async fn target(&self) -> Result<Target, BridgeError> {
125 self.remote.call("target", vec![]).await
126 }
127
128 pub async fn browser(&self) -> Result<Browser, BridgeError> {
134 self.remote.call("browser", vec![]).await
135 }
136
137 pub async fn browser_context(&self) -> Result<BrowserContext, BridgeError> {
143 self.remote.call("browserContext", vec![]).await
144 }
145
146 pub async fn main_frame(&self) -> Result<Frame, BridgeError> {
152 self.remote.call("mainFrame", vec![]).await
153 }
154
155 pub async fn create_cdp_session(&self) -> Result<CDPSession, BridgeError> {
161 self.remote.call("createCDPSession", vec![]).await
162 }
163
164 pub async fn keyboard(&self) -> Result<Keyboard, BridgeError> {
170 self.remote.get("keyboard").await
171 }
172
173 pub async fn touchscreen(&self) -> Result<Touchscreen, BridgeError> {
179 self.remote.get("touchscreen").await
180 }
181
182 pub async fn coverage(&self) -> Result<Coverage, BridgeError> {
188 self.remote.get("coverage").await
189 }
190
191 pub async fn tracing(&self) -> Result<Tracing, BridgeError> {
197 self.remote.get("tracing").await
198 }
199
200 pub async fn webmcp(&self) -> Result<WebMCP, BridgeError> {
206 self.remote.get("webmcp").await
207 }
208
209 pub async fn accessibility(&self) -> Result<Accessibility, BridgeError> {
215 self.remote.get("accessibility").await
216 }
217
218 pub async fn frames(&self) -> Result<Vec<Frame>, BridgeError> {
224 self.remote.call("frames", vec![]).await
225 }
226
227 pub async fn workers(&self) -> Result<Vec<WebWorker>, BridgeError> {
233 self.remote.call("workers", vec![]).await
234 }
235
236 pub async fn set_request_interception(&self, value: bool) -> Result<(), BridgeError> {
242 self.remote.call("setRequestInterception", vec![Some(Value::from(value))]).await
243 }
244
245 pub async fn set_bypass_service_worker(&self, bypass: bool) -> Result<(), BridgeError> {
251 self.remote.call("setBypassServiceWorker", vec![Some(Value::from(bypass))]).await
252 }
253
254 pub async fn set_drag_interception(&self, enabled: bool) -> Result<(), BridgeError> {
260 self.remote.call("setDragInterception", vec![Some(Value::from(enabled))]).await
261 }
262
263 pub async fn set_offline_mode(&self, enabled: bool) -> Result<(), BridgeError> {
269 self.remote.call("setOfflineMode", vec![Some(Value::from(enabled))]).await
270 }
271
272 pub async fn emulate_network_conditions(&self, network_conditions: Option<Value>) -> Result<(), BridgeError> {
278 self.remote.call("emulateNetworkConditions", vec![Some(network_conditions.unwrap_or(Value::Null))]).await
279 }
280
281 pub async fn set_default_navigation_timeout(&self, timeout: f64) -> Result<(), BridgeError> {
287 self.remote.call("setDefaultNavigationTimeout", vec![Some(Value::from(timeout))]).await
288 }
289
290 pub async fn set_default_timeout(&self, timeout: f64) -> Result<(), BridgeError> {
296 self.remote.call("setDefaultTimeout", vec![Some(Value::from(timeout))]).await
297 }
298
299 pub async fn get_default_timeout(&self) -> Result<f64, BridgeError> {
305 self.remote.call("getDefaultTimeout", vec![]).await
306 }
307
308 pub async fn get_default_navigation_timeout(&self) -> Result<f64, BridgeError> {
314 self.remote.call("getDefaultNavigationTimeout", vec![]).await
315 }
316
317 pub async fn locator(&self, selector: impl Into<JsFunction>) -> Result<Locator, BridgeError> {
324 self.remote.call("locator", vec![Some(selector.into().to_wire())]).await
325 }
326
327 pub async fn query_selector(&self, selector: &str) -> Result<Option<ElementHandle>, BridgeError> {
333 self.remote.call("$", vec![Some(Value::from(selector))]).await
334 }
335
336 pub async fn query_selector_all(&self, selector: &str, options: Option<Value>) -> Result<Vec<ElementHandle>, BridgeError> {
342 self.remote.call("$$", vec![Some(Value::from(selector)), options]).await
343 }
344
345 pub async fn evaluate_handle(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<JSHandle, BridgeError> {
351 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
352 call_args.extend(args.iter().map(|v| Some(v.clone())));
353 self.remote.call("evaluateHandle", call_args).await
354 }
355
356 pub async fn query_objects(&self, prototype_handle: &JSHandle) -> Result<JSHandle, BridgeError> {
362 self.remote.call("queryObjects", vec![Some(prototype_handle.remote().to_wire())]).await
363 }
364
365 pub async fn eval_on_selector(&self, selector: &str, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
371 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector)), Some(page_function.into().to_wire())];
372 call_args.extend(args.iter().map(|v| Some(v.clone())));
373 self.remote.call("$eval", call_args).await
374 }
375
376 pub async fn eval_on_selector_all(&self, selector: &str, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
382 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector)), Some(page_function.into().to_wire())];
383 call_args.extend(args.iter().map(|v| Some(v.clone())));
384 self.remote.call("$$eval", call_args).await
385 }
386
387 pub async fn cookies(&self, urls: &[&str]) -> Result<Vec<Value>, BridgeError> {
393 let mut call_args: Vec<Option<Value>> = vec![];
394 call_args.extend(urls.iter().map(|v| Some(Value::from(*v))));
395 self.remote.call("cookies", call_args).await
396 }
397
398 pub async fn delete_cookie(&self, cookies: &[Value]) -> Result<(), BridgeError> {
404 let mut call_args: Vec<Option<Value>> = vec![];
405 call_args.extend(cookies.iter().map(|v| Some(v.clone())));
406 self.remote.call("deleteCookie", call_args).await
407 }
408
409 pub async fn set_cookie(&self, cookies: &[Value]) -> Result<(), BridgeError> {
415 let mut call_args: Vec<Option<Value>> = vec![];
416 call_args.extend(cookies.iter().map(|v| Some(v.clone())));
417 self.remote.call("setCookie", call_args).await
418 }
419
420 pub async fn add_script_tag(&self, options: Value) -> Result<ElementHandle, BridgeError> {
426 self.remote.call("addScriptTag", vec![Some(options)]).await
427 }
428
429 pub async fn add_style_tag(&self, options: Value) -> Result<ElementHandle, BridgeError> {
436 self.remote.call("addStyleTag", vec![Some(options)]).await
437 }
438
439 pub async fn expose_function(&self, name: &str, pptr_function: Value) -> Result<(), BridgeError> {
445 self.remote.call("exposeFunction", vec![Some(Value::from(name)), Some(pptr_function)]).await
446 }
447
448 pub async fn remove_exposed_function(&self, name: &str) -> Result<(), BridgeError> {
454 self.remote.call("removeExposedFunction", vec![Some(Value::from(name))]).await
455 }
456
457 pub async fn authenticate(&self, credentials: Option<Value>) -> Result<(), BridgeError> {
463 self.remote.call("authenticate", vec![Some(credentials.unwrap_or(Value::Null))]).await
464 }
465
466 pub async fn set_extra_http_headers(&self, headers: Value) -> Result<(), BridgeError> {
472 self.remote.call("setExtraHTTPHeaders", vec![Some(headers)]).await
473 }
474
475 pub async fn set_user_agent(&self, user_agent: Value, user_agent_metadata: Option<Value>) -> Result<(), BridgeError> {
482 self.remote.call("setUserAgent", vec![Some(user_agent), user_agent_metadata]).await
483 }
484
485 pub async fn metrics(&self) -> Result<Value, BridgeError> {
491 self.remote.call("metrics", vec![]).await
492 }
493
494 pub async fn capture_heap_snapshot(&self, options: Value) -> Result<(), BridgeError> {
500 self.remote.call("captureHeapSnapshot", vec![Some(options)]).await
501 }
502
503 pub async fn url(&self) -> Result<String, BridgeError> {
509 self.remote.call("url", vec![]).await
510 }
511
512 pub async fn content(&self) -> Result<String, BridgeError> {
518 self.remote.call("content", vec![]).await
519 }
520
521 pub async fn set_content(&self, html: &str, options: Option<Value>) -> Result<(), BridgeError> {
527 self.remote.call("setContent", vec![Some(Value::from(html)), options]).await
528 }
529
530 pub async fn goto(&self, url: &str, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
536 self.remote.call("goto", vec![Some(Value::from(url)), options]).await
537 }
538
539 pub async fn reload(&self, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
545 self.remote.call("reload", vec![options]).await
546 }
547
548 pub async fn wait_for_navigation(&self, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
554 self.remote.call("waitForNavigation", vec![options]).await
555 }
556
557 pub async fn wait_for_request(&self, url_or_predicate: impl Into<JsFunction>, options: Option<Value>) -> Result<HTTPRequest, BridgeError> {
563 self.remote.call("waitForRequest", vec![Some(url_or_predicate.into().to_wire()), options]).await
564 }
565
566 pub async fn wait_for_response(&self, url_or_predicate: impl Into<JsFunction>, options: Option<Value>) -> Result<HTTPResponse, BridgeError> {
572 self.remote.call("waitForResponse", vec![Some(url_or_predicate.into().to_wire()), options]).await
573 }
574
575 pub async fn wait_for_network_idle(&self, options: Option<Value>) -> Result<(), BridgeError> {
581 self.remote.call("waitForNetworkIdle", vec![options]).await
582 }
583
584 pub async fn wait_for_frame(&self, url_or_predicate: impl Into<JsFunction>, options: Option<Value>) -> Result<Frame, BridgeError> {
590 self.remote.call("waitForFrame", vec![Some(url_or_predicate.into().to_wire()), options]).await
591 }
592
593 pub async fn go_back(&self, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
599 self.remote.call("goBack", vec![options]).await
600 }
601
602 pub async fn go_forward(&self, options: Option<Value>) -> Result<Option<HTTPResponse>, BridgeError> {
608 self.remote.call("goForward", vec![options]).await
609 }
610
611 pub async fn bring_to_front(&self) -> Result<(), BridgeError> {
617 self.remote.call("bringToFront", vec![]).await
618 }
619
620 pub async fn emulate(&self, device: Value) -> Result<(), BridgeError> {
626 self.remote.call("emulate", vec![Some(device)]).await
627 }
628
629 pub async fn set_java_script_enabled(&self, enabled: bool) -> Result<(), BridgeError> {
635 self.remote.call("setJavaScriptEnabled", vec![Some(Value::from(enabled))]).await
636 }
637
638 pub async fn set_bypass_csp(&self, enabled: bool) -> Result<(), BridgeError> {
644 self.remote.call("setBypassCSP", vec![Some(Value::from(enabled))]).await
645 }
646
647 pub async fn emulate_media_type(&self, type_: Option<&str>) -> Result<(), BridgeError> {
653 self.remote.call("emulateMediaType", vec![type_.map(|x| Value::from(x))]).await
654 }
655
656 pub async fn emulate_cpu_throttling(&self, factor: Option<f64>) -> Result<(), BridgeError> {
662 self.remote.call("emulateCPUThrottling", vec![Some(factor.map(|x| Value::from(x)).unwrap_or(Value::Null))]).await
663 }
664
665 pub async fn emulate_media_features(&self, features: Option<Vec<Value>>) -> Result<(), BridgeError> {
671 self.remote.call("emulateMediaFeatures", vec![features.map(|x| Value::Array(x))]).await
672 }
673
674 pub async fn emulate_locale(&self, locale: Option<&str>) -> Result<(), BridgeError> {
680 self.remote.call("emulateLocale", vec![locale.map(|x| Value::from(x))]).await
681 }
682
683 pub async fn emulate_timezone(&self, timezone_id: Option<&str>) -> Result<(), BridgeError> {
689 self.remote.call("emulateTimezone", vec![timezone_id.map(|x| Value::from(x))]).await
690 }
691
692 pub async fn emulate_idle_state(&self, overrides: Option<Value>) -> Result<(), BridgeError> {
698 self.remote.call("emulateIdleState", vec![overrides]).await
699 }
700
701 pub async fn emulate_vision_deficiency(&self, type_: Option<Value>) -> Result<(), BridgeError> {
707 self.remote.call("emulateVisionDeficiency", vec![type_]).await
708 }
709
710 pub async fn set_viewport(&self, viewport: Option<Value>) -> Result<(), BridgeError> {
716 self.remote.call("setViewport", vec![Some(viewport.unwrap_or(Value::Null))]).await
717 }
718
719 pub async fn viewport(&self) -> Result<Option<Value>, BridgeError> {
725 self.remote.call("viewport", vec![]).await
726 }
727
728 pub async fn evaluate(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
734 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
735 call_args.extend(args.iter().map(|v| Some(v.clone())));
736 self.remote.call("evaluate", call_args).await
737 }
738
739 pub async fn evaluate_on_new_document(&self, page_function: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
745 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire())];
746 call_args.extend(args.iter().map(|v| Some(v.clone())));
747 self.remote.call("evaluateOnNewDocument", call_args).await
748 }
749
750 pub async fn remove_script_to_evaluate_on_new_document(&self, identifier: &str) -> Result<(), BridgeError> {
756 self.remote.call("removeScriptToEvaluateOnNewDocument", vec![Some(Value::from(identifier))]).await
757 }
758
759 pub async fn set_cache_enabled(&self, enabled: Option<bool>) -> Result<(), BridgeError> {
765 self.remote.call("setCacheEnabled", vec![enabled.map(|x| Value::from(x))]).await
766 }
767
768 pub async fn screencast(&self, options: Option<Value>) -> Result<ScreenRecorder, BridgeError> {
774 self.remote.call("screencast", vec![options]).await
775 }
776
777 pub async fn record(&self, options: Option<Value>) -> Result<ScreenRecording, BridgeError> {
783 self.remote.call("record", vec![options]).await
784 }
785
786 pub async fn screenshot(&self, options: Option<Value>) -> Result<Value, BridgeError> {
793 self.remote.call("screenshot", vec![options]).await
794 }
795
796 pub async fn emulate_focused_page(&self, enabled: bool) -> Result<(), BridgeError> {
802 self.remote.call("emulateFocusedPage", vec![Some(Value::from(enabled))]).await
803 }
804
805 pub async fn create_pdf_stream(&self, options: Option<Value>) -> Result<Value, BridgeError> {
811 self.remote.call("createPDFStream", vec![options]).await
812 }
813
814 pub async fn pdf(&self, options: Option<Value>) -> Result<Vec<u8>, BridgeError> {
820 self.remote.call("pdf", vec![options]).await
821 }
822
823 pub async fn title(&self) -> Result<String, BridgeError> {
829 self.remote.call("title", vec![]).await
830 }
831
832 pub async fn close(&self, options: Option<Value>) -> Result<(), BridgeError> {
838 self.remote.call("close", vec![options]).await
839 }
840
841 pub async fn is_closed(&self) -> Result<bool, BridgeError> {
847 self.remote.call("isClosed", vec![]).await
848 }
849
850 pub async fn mouse(&self) -> Result<Mouse, BridgeError> {
856 self.remote.get("mouse").await
857 }
858
859 pub async fn click(&self, selector: &str, options: Option<Value>) -> Result<(), BridgeError> {
865 self.remote.call("click", vec![Some(Value::from(selector)), options]).await
866 }
867
868 pub async fn focus(&self, selector: &str) -> Result<(), BridgeError> {
874 self.remote.call("focus", vec![Some(Value::from(selector))]).await
875 }
876
877 pub async fn hover(&self, selector: &str) -> Result<(), BridgeError> {
883 self.remote.call("hover", vec![Some(Value::from(selector))]).await
884 }
885
886 pub async fn select(&self, selector: &str, values: &[&str]) -> Result<Vec<String>, BridgeError> {
892 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(selector))];
893 call_args.extend(values.iter().map(|v| Some(Value::from(*v))));
894 self.remote.call("select", call_args).await
895 }
896
897 pub async fn tap(&self, selector: &str) -> Result<(), BridgeError> {
903 self.remote.call("tap", vec![Some(Value::from(selector))]).await
904 }
905
906 pub async fn r#type(&self, selector: &str, text: &str, options: Option<Value>) -> Result<(), BridgeError> {
912 self.remote.call("type", vec![Some(Value::from(selector)), Some(Value::from(text)), options]).await
913 }
914
915 pub async fn wait_for_selector(&self, selector: &str, options: Option<Value>) -> Result<Option<ElementHandle>, BridgeError> {
921 self.remote.call("waitForSelector", vec![Some(Value::from(selector)), options]).await
922 }
923
924 pub async fn wait_for_function(&self, page_function: impl Into<JsFunction>, options: Option<Value>, args: &[Value]) -> Result<JSHandle, BridgeError> {
930 let mut call_args: Vec<Option<Value>> = vec![Some(page_function.into().to_wire()), options];
931 call_args.extend(args.iter().map(|v| Some(v.clone())));
932 self.remote.call("waitForFunction", call_args).await
933 }
934
935 pub async fn wait_for_device_prompt(&self, options: Option<Value>) -> Result<DeviceRequestPrompt, BridgeError> {
941 self.remote.call("waitForDevicePrompt", vec![options]).await
942 }
943}