browser-commander 0.16.0

Universal browser automation library that supports multiple browser engines with a unified API
Documentation
// @generated by scripts/generate-puppeteer-bindings.mjs from
// rust/protocol/puppeteer/api.json. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports, non_snake_case)]

use serde_json::Value;

use super::*;
use crate::puppeteer::bridge::{binary, remote_type, BridgeError, JsFunction, Remote};

remote_type!(
    /// Puppeteer's `CommonEventEmitter` (puppeteer-core 25.10.0), a remote object
    /// served by `browser-commander serve --stdio`.
    CommonEventEmitter
);

impl CommonEventEmitter {
    /// `CommonEventEmitter.on`
    ///
    /// ```text
    /// on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): this
    /// ```
    pub async fn on(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
        self.remote.call("on", vec![Some(type_), Some(handler.into().to_wire())]).await
    }

    /// `CommonEventEmitter.off`
    ///
    /// ```text
    /// off<Key extends keyof Events>(type: Key, handler?: Handler<Events[Key]>): this
    /// ```
    pub async fn off(&self, type_: Value, handler: Option<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
        self.remote.call("off", vec![Some(type_), handler.map(|x| x.to_wire())]).await
    }

    /// `CommonEventEmitter.emit`
    ///
    /// ```text
    /// emit<Key extends keyof Events>(type: Key, event: Events[Key]): boolean
    /// ```
    pub async fn emit(&self, type_: Value, event: Value) -> Result<bool, BridgeError> {
        self.remote.call("emit", vec![Some(type_), Some(event)]).await
    }

    /// `CommonEventEmitter.once`
    ///
    /// ```text
    /// once<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): this
    /// ```
    pub async fn once(&self, type_: Value, handler: impl Into<JsFunction>) -> Result<CommonEventEmitter, BridgeError> {
        self.remote.call("once", vec![Some(type_), Some(handler.into().to_wire())]).await
    }

    /// `CommonEventEmitter.listenerCount`
    ///
    /// ```text
    /// listenerCount(event: keyof Events): number
    /// ```
    pub async fn listener_count(&self, event: Value) -> Result<f64, BridgeError> {
        self.remote.call("listenerCount", vec![Some(event)]).await
    }

    /// `CommonEventEmitter.removeAllListeners`
    ///
    /// ```text
    /// removeAllListeners(event?: keyof Events): this
    /// ```
    pub async fn remove_all_listeners(&self, event: Option<Value>) -> Result<CommonEventEmitter, BridgeError> {
        self.remote.call("removeAllListeners", vec![event]).await
    }
}