Skip to main content

browser_commander/puppeteer/api/
browser.rs

1// @generated by scripts/generate-puppeteer-bindings.mjs from
2// rust/protocol/puppeteer/api.json. Do not edit by hand.
3
4#![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    /// Puppeteer's `Browser` (puppeteer-core 25.10.0), a remote object
13    /// served by `browser-commander serve --stdio`.
14    ///
15    /// Extends [`EventEmitter`]; the inherited methods are repeated here.
16    Browser
17);
18
19impl Browser {
20    /// `EventEmitter.on`
21    ///
22    /// ```text
23    /// on<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
24    /// ```
25    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    /// `EventEmitter.off`
30    ///
31    /// ```text
32    /// off<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler?: Handler<EventsWithWildcard<Events>[Key]>): this
33    /// ```
34    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    /// `EventEmitter.emit`
39    ///
40    /// ```text
41    /// emit<Key extends keyof EventsWithWildcard<Events>>(type: Key, event: EventsWithWildcard<Events>[Key]): boolean
42    /// ```
43    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    /// `EventEmitter.once`
48    ///
49    /// ```text
50    /// once<Key extends keyof EventsWithWildcard<Events>>(type: Key, handler: Handler<EventsWithWildcard<Events>[Key]>): this
51    /// ```
52    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    /// `EventEmitter.listenerCount`
57    ///
58    /// ```text
59    /// listenerCount(type: keyof EventsWithWildcard<Events>): number
60    /// ```
61    pub async fn listener_count(&self, type_: Value) -> Result<f64, BridgeError> {
62        self.remote.call("listenerCount", vec![Some(type_)]).await
63    }
64
65    /// `EventEmitter.removeAllListeners`
66    ///
67    /// ```text
68    /// removeAllListeners(type?: keyof EventsWithWildcard<Events>): this
69    /// ```
70    pub async fn remove_all_listeners(&self, type_: Option<Value>) -> Result<Browser, BridgeError> {
71        self.remote.call("removeAllListeners", vec![type_]).await
72    }
73
74    /// `Browser.process`
75    ///
76    /// ```text
77    /// process(): ChildProcess | null
78    /// ```
79    pub async fn process(&self) -> Result<Option<Value>, BridgeError> {
80        self.remote.call("process", vec![]).await
81    }
82
83    /// `Browser.createBrowserContext`
84    ///
85    /// ```text
86    /// createBrowserContext(options?: BrowserContextOptions): Promise<BrowserContext>
87    /// ```
88    pub async fn create_browser_context(&self, options: Option<Value>) -> Result<BrowserContext, BridgeError> {
89        self.remote.call("createBrowserContext", vec![options]).await
90    }
91
92    /// `Browser.browserContexts`
93    ///
94    /// ```text
95    /// browserContexts(): BrowserContext[]
96    /// ```
97    pub async fn browser_contexts(&self) -> Result<Vec<BrowserContext>, BridgeError> {
98        self.remote.call("browserContexts", vec![]).await
99    }
100
101    /// `Browser.defaultBrowserContext`
102    ///
103    /// ```text
104    /// defaultBrowserContext(): BrowserContext
105    /// ```
106    pub async fn default_browser_context(&self) -> Result<BrowserContext, BridgeError> {
107        self.remote.call("defaultBrowserContext", vec![]).await
108    }
109
110    /// `Browser.wsEndpoint`
111    ///
112    /// ```text
113    /// wsEndpoint(): string
114    /// ```
115    pub async fn ws_endpoint(&self) -> Result<String, BridgeError> {
116        self.remote.call("wsEndpoint", vec![]).await
117    }
118
119    /// `Browser.newPage`
120    ///
121    /// ```text
122    /// newPage(options?: CreatePageOptions): Promise<Page>
123    /// ```
124    pub async fn new_page(&self, options: Option<Value>) -> Result<Page, BridgeError> {
125        self.remote.call("newPage", vec![options]).await
126    }
127
128    /// `Browser.getWindowBounds`
129    ///
130    /// ```text
131    /// getWindowBounds(windowId: WindowId): Promise<WindowBounds>
132    /// ```
133    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    /// `Browser.setWindowBounds`
138    ///
139    /// ```text
140    /// setWindowBounds(windowId: WindowId, windowBounds: WindowBounds): Promise<void>
141    /// ```
142    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    /// `Browser.targets`
147    ///
148    /// ```text
149    /// targets(): Target[]
150    /// ```
151    pub async fn targets(&self) -> Result<Vec<Target>, BridgeError> {
152        self.remote.call("targets", vec![]).await
153    }
154
155    /// `Browser.target`
156    ///
157    /// ```text
158    /// target(): Target
159    /// ```
160    pub async fn target(&self) -> Result<Target, BridgeError> {
161        self.remote.call("target", vec![]).await
162    }
163
164    /// `Browser.waitForTarget`
165    ///
166    /// ```text
167    /// waitForTarget(predicate: (x: Target) => boolean | Promise<boolean>, options?: WaitForTargetOptions): Promise<Target>
168    /// ```
169    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    /// `Browser.pages`
174    ///
175    /// ```text
176    /// pages(includeAll?: boolean): Promise<Page[]>
177    /// ```
178    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    /// `Browser.version`
183    ///
184    /// ```text
185    /// version(): Promise<string>
186    /// ```
187    pub async fn version(&self) -> Result<String, BridgeError> {
188        self.remote.call("version", vec![]).await
189    }
190
191    /// `Browser.userAgent`
192    ///
193    /// ```text
194    /// userAgent(): Promise<string>
195    /// ```
196    pub async fn user_agent(&self) -> Result<String, BridgeError> {
197        self.remote.call("userAgent", vec![]).await
198    }
199
200    /// `Browser.close`
201    ///
202    /// ```text
203    /// close(): Promise<void>
204    /// ```
205    pub async fn close(&self) -> Result<(), BridgeError> {
206        self.remote.call("close", vec![]).await
207    }
208
209    /// `Browser.disconnect`
210    ///
211    /// ```text
212    /// disconnect(): Promise<void>
213    /// ```
214    pub async fn disconnect(&self) -> Result<(), BridgeError> {
215        self.remote.call("disconnect", vec![]).await
216    }
217
218    /// `Browser.cookies`
219    ///
220    /// ```text
221    /// cookies(): Promise<Cookie[]>
222    /// ```
223    pub async fn cookies(&self) -> Result<Vec<Value>, BridgeError> {
224        self.remote.call("cookies", vec![]).await
225    }
226
227    /// `Browser.setCookie`
228    ///
229    /// ```text
230    /// setCookie(...cookies: CookieData[]): Promise<void>
231    /// ```
232    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    /// `Browser.deleteCookie`
239    ///
240    /// ```text
241    /// deleteCookie(...cookies: Cookie[]): Promise<void>
242    /// ```
243    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    /// `Browser.deleteMatchingCookies`
250    ///
251    /// ```text
252    /// deleteMatchingCookies(...filters: DeleteCookiesRequest[]): Promise<void>
253    /// ```
254    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    /// `Browser.setPermission`
261    ///
262    /// ```text
263    /// setPermission(origin: string, ...permissions: Array<{ permission: PermissionDescriptor_2; state: PermissionState_2; }> ): Promise<void>
264    /// ```
265    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    /// `Browser.installExtension`
272    ///
273    /// ```text
274    /// installExtension(path: string, options?: ExtensionInstallOptions): Promise<string>
275    /// ```
276    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    /// `Browser.uninstallExtension`
281    ///
282    /// ```text
283    /// uninstallExtension(id: string): Promise<void>
284    /// ```
285    pub async fn uninstall_extension(&self, id: &str) -> Result<(), BridgeError> {
286        self.remote.call("uninstallExtension", vec![Some(Value::from(id))]).await
287    }
288
289    /// `Browser.installPWA`
290    ///
291    /// ```text
292    /// installPWA(options: InstallPWAOptions): Promise<string>
293    /// ```
294    pub async fn install_pwa(&self, options: Value) -> Result<String, BridgeError> {
295        self.remote.call("installPWA", vec![Some(options)]).await
296    }
297
298    /// `Browser.uninstallPWA`
299    ///
300    /// ```text
301    /// uninstallPWA(options: UninstallPWAOptions): Promise<void>
302    /// ```
303    pub async fn uninstall_pwa(&self, options: Value) -> Result<(), BridgeError> {
304        self.remote.call("uninstallPWA", vec![Some(options)]).await
305    }
306
307    /// `Browser.launchPWA`
308    ///
309    /// ```text
310    /// launchPWA(options: LaunchPWAOptions): Promise<Page>
311    /// ```
312    pub async fn launch_pwa(&self, options: Value) -> Result<Page, BridgeError> {
313        self.remote.call("launchPWA", vec![Some(options)]).await
314    }
315
316    /// `Browser.getPWAState`
317    ///
318    /// ```text
319    /// getPWAState(options: GetPWAStateOptions): Promise<PWAState>
320    /// ```
321    pub async fn get_pwa_state(&self, options: Value) -> Result<Value, BridgeError> {
322        self.remote.call("getPWAState", vec![Some(options)]).await
323    }
324
325    /// `Browser.screens`
326    ///
327    /// ```text
328    /// screens(): Promise<ScreenInfo[]>
329    /// ```
330    pub async fn screens(&self) -> Result<Vec<Value>, BridgeError> {
331        self.remote.call("screens", vec![]).await
332    }
333
334    /// `Browser.addScreen`
335    ///
336    /// ```text
337    /// addScreen(params: AddScreenParams): Promise<ScreenInfo>
338    /// ```
339    pub async fn add_screen(&self, params: Value) -> Result<Value, BridgeError> {
340        self.remote.call("addScreen", vec![Some(params)]).await
341    }
342
343    /// `Browser.removeScreen`
344    ///
345    /// ```text
346    /// removeScreen(screenId: string): Promise<void>
347    /// ```
348    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    /// `Browser.connected`
353    ///
354    /// ```text
355    /// get connected(): boolean
356    /// ```
357    pub async fn connected(&self) -> Result<bool, BridgeError> {
358        self.remote.get("connected").await
359    }
360
361    /// `Browser.debugInfo`
362    ///
363    /// ```text
364    /// get debugInfo(): DebugInfo
365    /// ```
366    pub async fn debug_info(&self) -> Result<Value, BridgeError> {
367        self.remote.get("debugInfo").await
368    }
369
370    /// `Browser.extensions`
371    ///
372    /// ```text
373    /// extensions(): Promise<Map<string, Extension>>
374    /// ```
375    pub async fn extensions(&self) -> Result<Value, BridgeError> {
376        self.remote.call("extensions", vec![]).await
377    }
378}