Skip to main content

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