Skip to main content

browser_commander/puppeteer/api/
web_worker.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 `WebWorker` (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    WebWorker
17);
18
19impl WebWorker {
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<WebWorker, 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<WebWorker, 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<WebWorker, 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<WebWorker, BridgeError> {
71        self.remote.call("removeAllListeners", vec![type_]).await
72    }
73
74    /// `WebWorker.url`
75    ///
76    /// ```text
77    /// url(): string
78    /// ```
79    pub async fn url(&self) -> Result<String, BridgeError> {
80        self.remote.call("url", vec![]).await
81    }
82
83    /// `WebWorker.client`
84    ///
85    /// ```text
86    /// get client(): CDPSession
87    /// ```
88    pub async fn client(&self) -> Result<CDPSession, BridgeError> {
89        self.remote.get("client").await
90    }
91
92    /// `WebWorker.evaluate`
93    ///
94    /// ```text
95    /// evaluate<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(func: Func | string, ...args: Params): Promise<Awaited<ReturnType<Func>>>
96    /// ```
97    pub async fn evaluate(&self, func: impl Into<JsFunction>, args: &[Value]) -> Result<Value, BridgeError> {
98        let mut call_args: Vec<Option<Value>> = vec![Some(func.into().to_wire())];
99        call_args.extend(args.iter().map(|v| Some(v.clone())));
100        self.remote.call("evaluate", call_args).await
101    }
102
103    /// `WebWorker.evaluateHandle`
104    ///
105    /// ```text
106    /// evaluateHandle<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(func: Func | string, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
107    /// ```
108    pub async fn evaluate_handle(&self, func: impl Into<JsFunction>, args: &[Value]) -> Result<JSHandle, BridgeError> {
109        let mut call_args: Vec<Option<Value>> = vec![Some(func.into().to_wire())];
110        call_args.extend(args.iter().map(|v| Some(v.clone())));
111        self.remote.call("evaluateHandle", call_args).await
112    }
113
114    /// `WebWorker.waitForFunction`
115    ///
116    /// ```text
117    /// waitForFunction<Params extends unknown[], Func extends EvaluateFunc<Params> = EvaluateFunc<Params>>(workerFunction: Func | string, options?: { polling?: number; timeout?: number; signal?: AbortSignal; }, ...args: Params ): Promise<HandleFor<Awaited<ReturnType<Func>>>>
118    /// ```
119    pub async fn wait_for_function(&self, worker_function: impl Into<JsFunction>, options: Option<Value>, args: &[Value]) -> Result<JSHandle, BridgeError> {
120        let mut call_args: Vec<Option<Value>> = vec![Some(worker_function.into().to_wire()), options];
121        call_args.extend(args.iter().map(|v| Some(v.clone())));
122        self.remote.call("waitForFunction", call_args).await
123    }
124
125    /// `WebWorker.close`
126    ///
127    /// ```text
128    /// close(): Promise<void>
129    /// ```
130    pub async fn close(&self) -> Result<(), BridgeError> {
131        self.remote.call("close", vec![]).await
132    }
133}