browser_commander/puppeteer/api/
browser.rs1#![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 Browser
17);
18
19impl Browser {
20 pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<Browser, 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<Browser, 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<Browser, 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<Browser, BridgeError> {
71 self.remote.call("removeAllListeners", vec![type_]).await
72 }
73
74 pub async fn process(&self) -> Result<Option<Value>, BridgeError> {
80 self.remote.call("process", vec![]).await
81 }
82
83 pub async fn create_browser_context(&self, options: Option<Value>) -> Result<BrowserContext, BridgeError> {
89 self.remote.call("createBrowserContext", vec![options]).await
90 }
91
92 pub async fn browser_contexts(&self) -> Result<Vec<BrowserContext>, BridgeError> {
98 self.remote.call("browserContexts", vec![]).await
99 }
100
101 pub async fn default_browser_context(&self) -> Result<BrowserContext, BridgeError> {
107 self.remote.call("defaultBrowserContext", vec![]).await
108 }
109
110 pub async fn ws_endpoint(&self) -> Result<String, BridgeError> {
116 self.remote.call("wsEndpoint", vec![]).await
117 }
118
119 pub async fn new_page(&self, options: Option<Value>) -> Result<Page, BridgeError> {
125 self.remote.call("newPage", vec![options]).await
126 }
127
128 pub async fn get_window_bounds(&self, window_id: &str) -> Result<Value, BridgeError> {
134 self.remote.call("getWindowBounds", vec![Some(Value::from(window_id))]).await
135 }
136
137 pub async fn set_window_bounds(&self, window_id: &str, window_bounds: Value) -> Result<(), BridgeError> {
143 self.remote.call("setWindowBounds", vec![Some(Value::from(window_id)), Some(window_bounds)]).await
144 }
145
146 pub async fn targets(&self) -> Result<Vec<Target>, BridgeError> {
152 self.remote.call("targets", vec![]).await
153 }
154
155 pub async fn target(&self) -> Result<Target, BridgeError> {
161 self.remote.call("target", vec![]).await
162 }
163
164 pub async fn wait_for_target(&self, predicate: impl Into<JsFunction>, options: Option<Value>) -> Result<Target, BridgeError> {
170 self.remote.call("waitForTarget", vec![Some(predicate.into().to_wire()), options]).await
171 }
172
173 pub async fn pages(&self, include_all: Option<bool>) -> Result<Vec<Page>, BridgeError> {
179 self.remote.call("pages", vec![include_all.map(|x| Value::from(x))]).await
180 }
181
182 pub async fn version(&self) -> Result<String, BridgeError> {
188 self.remote.call("version", vec![]).await
189 }
190
191 pub async fn user_agent(&self) -> Result<String, BridgeError> {
197 self.remote.call("userAgent", vec![]).await
198 }
199
200 pub async fn close(&self) -> Result<(), BridgeError> {
206 self.remote.call("close", vec![]).await
207 }
208
209 pub async fn disconnect(&self) -> Result<(), BridgeError> {
215 self.remote.call("disconnect", vec![]).await
216 }
217
218 pub async fn cookies(&self) -> Result<Vec<Value>, BridgeError> {
224 self.remote.call("cookies", vec![]).await
225 }
226
227 pub async fn set_cookie(&self, cookies: &[Value]) -> Result<(), BridgeError> {
233 let mut call_args: Vec<Option<Value>> = vec![];
234 call_args.extend(cookies.iter().map(|v| Some(v.clone())));
235 self.remote.call("setCookie", call_args).await
236 }
237
238 pub async fn delete_cookie(&self, cookies: &[Value]) -> Result<(), BridgeError> {
244 let mut call_args: Vec<Option<Value>> = vec![];
245 call_args.extend(cookies.iter().map(|v| Some(v.clone())));
246 self.remote.call("deleteCookie", call_args).await
247 }
248
249 pub async fn delete_matching_cookies(&self, filters: &[Value]) -> Result<(), BridgeError> {
255 let mut call_args: Vec<Option<Value>> = vec![];
256 call_args.extend(filters.iter().map(|v| Some(v.clone())));
257 self.remote.call("deleteMatchingCookies", call_args).await
258 }
259
260 pub async fn set_permission(&self, origin: &str, permissions: &[Value]) -> Result<(), BridgeError> {
266 let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(origin))];
267 call_args.extend(permissions.iter().map(|v| Some(v.clone())));
268 self.remote.call("setPermission", call_args).await
269 }
270
271 pub async fn install_extension(&self, path: &str, options: Option<Value>) -> Result<String, BridgeError> {
277 self.remote.call("installExtension", vec![Some(Value::from(path)), options]).await
278 }
279
280 pub async fn uninstall_extension(&self, id: &str) -> Result<(), BridgeError> {
286 self.remote.call("uninstallExtension", vec![Some(Value::from(id))]).await
287 }
288
289 pub async fn install_pwa(&self, options: Value) -> Result<String, BridgeError> {
295 self.remote.call("installPWA", vec![Some(options)]).await
296 }
297
298 pub async fn uninstall_pwa(&self, options: Value) -> Result<(), BridgeError> {
304 self.remote.call("uninstallPWA", vec![Some(options)]).await
305 }
306
307 pub async fn launch_pwa(&self, options: Value) -> Result<Page, BridgeError> {
313 self.remote.call("launchPWA", vec![Some(options)]).await
314 }
315
316 pub async fn get_pwa_state(&self, options: Value) -> Result<Value, BridgeError> {
322 self.remote.call("getPWAState", vec![Some(options)]).await
323 }
324
325 pub async fn screens(&self) -> Result<Vec<Value>, BridgeError> {
331 self.remote.call("screens", vec![]).await
332 }
333
334 pub async fn add_screen(&self, params: Value) -> Result<Value, BridgeError> {
340 self.remote.call("addScreen", vec![Some(params)]).await
341 }
342
343 pub async fn remove_screen(&self, screen_id: &str) -> Result<(), BridgeError> {
349 self.remote.call("removeScreen", vec![Some(Value::from(screen_id))]).await
350 }
351
352 pub async fn connected(&self) -> Result<bool, BridgeError> {
358 self.remote.get("connected").await
359 }
360
361 pub async fn debug_info(&self) -> Result<Value, BridgeError> {
367 self.remote.get("debugInfo").await
368 }
369
370 pub async fn extensions(&self) -> Result<Value, BridgeError> {
376 self.remote.call("extensions", vec![]).await
377 }
378}