Skip to main content

browser_commander/puppeteer/api/
common_event_emitter.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 `CommonEventEmitter` (puppeteer-core 25.10.0), a remote object
13    /// served by `browser-commander serve --stdio`.
14    CommonEventEmitter
15);
16
17impl CommonEventEmitter {
18    /// `CommonEventEmitter.on`
19    ///
20    /// ```text
21    /// on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): this
22    /// ```
23    pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
24        self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
25    }
26
27    /// `CommonEventEmitter.off`
28    ///
29    /// ```text
30    /// off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): this
31    /// ```
32    pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
33        self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
34    }
35
36    /// `CommonEventEmitter.emit`
37    ///
38    /// ```text
39    /// emit<Key extends keyof Events>(type: Key, event: Events[Key]): boolean
40    /// ```
41    pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
42        self.remote.call("emit", vec![Some(type_), Some(event)]).await
43    }
44
45    /// `CommonEventEmitter.once`
46    ///
47    /// ```text
48    /// once<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): this
49    /// ```
50    pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
51        self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
52    }
53
54    /// `CommonEventEmitter.listenerCount`
55    ///
56    /// ```text
57    /// listenerCount(event: keyof Events): number
58    /// ```
59    pub async fn listener_count(&self, event: Value) -> Result<f64, BridgeError> {
60        self.remote.call("listenerCount", vec![Some(event)]).await
61    }
62
63    /// `CommonEventEmitter.removeAllListeners`
64    ///
65    /// ```text
66    /// removeAllListeners(event?: keyof Events): this
67    /// ```
68    pub async fn remove_all_listeners(&self, event: Option<Value>) -> Result<CommonEventEmitter, BridgeError> {
69        self.remote.call("removeAllListeners", vec![event]).await
70    }
71}