browser-commander 0.14.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 `Browser` (puppeteer-core 25.10.0), a remote object
    /// served by `browser-commander serve --stdio`.
    ///
    /// Extends [`EventEmitter`]; the inherited methods are repeated here.
    Browser
);

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

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

    /// `EventEmitter.emit`
    ///
    /// ```text
    /// emit<Key extends keyof EventsWithWildcard<Events>>(type: Key, event: EventsWithWildcard<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
    }

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

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

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

    /// `Browser.process`
    ///
    /// ```text
    /// process(): ChildProcess | null
    /// ```
    pub async fn process(&self) -> Result<Option<Value>, BridgeError> {
        self.remote.call("process", vec![]).await
    }

    /// `Browser.createBrowserContext`
    ///
    /// ```text
    /// createBrowserContext(options?: BrowserContextOptions): Promise<BrowserContext>
    /// ```
    pub async fn create_browser_context(&self, options: Option<Value>) -> Result<BrowserContext, BridgeError> {
        self.remote.call("createBrowserContext", vec![options]).await
    }

    /// `Browser.browserContexts`
    ///
    /// ```text
    /// browserContexts(): BrowserContext[]
    /// ```
    pub async fn browser_contexts(&self) -> Result<Vec<BrowserContext>, BridgeError> {
        self.remote.call("browserContexts", vec![]).await
    }

    /// `Browser.defaultBrowserContext`
    ///
    /// ```text
    /// defaultBrowserContext(): BrowserContext
    /// ```
    pub async fn default_browser_context(&self) -> Result<BrowserContext, BridgeError> {
        self.remote.call("defaultBrowserContext", vec![]).await
    }

    /// `Browser.wsEndpoint`
    ///
    /// ```text
    /// wsEndpoint(): string
    /// ```
    pub async fn ws_endpoint(&self) -> Result<String, BridgeError> {
        self.remote.call("wsEndpoint", vec![]).await
    }

    /// `Browser.newPage`
    ///
    /// ```text
    /// newPage(options?: CreatePageOptions): Promise<Page>
    /// ```
    pub async fn new_page(&self, options: Option<Value>) -> Result<Page, BridgeError> {
        self.remote.call("newPage", vec![options]).await
    }

    /// `Browser.getWindowBounds`
    ///
    /// ```text
    /// getWindowBounds(windowId: WindowId): Promise<WindowBounds>
    /// ```
    pub async fn get_window_bounds(&self, window_id: &str) -> Result<Value, BridgeError> {
        self.remote.call("getWindowBounds", vec![Some(Value::from(window_id))]).await
    }

    /// `Browser.setWindowBounds`
    ///
    /// ```text
    /// setWindowBounds(windowId: WindowId, windowBounds: WindowBounds): Promise<void>
    /// ```
    pub async fn set_window_bounds(&self, window_id: &str, window_bounds: Value) -> Result<(), BridgeError> {
        self.remote.call("setWindowBounds", vec![Some(Value::from(window_id)), Some(window_bounds)]).await
    }

    /// `Browser.targets`
    ///
    /// ```text
    /// targets(): Target[]
    /// ```
    pub async fn targets(&self) -> Result<Vec<Target>, BridgeError> {
        self.remote.call("targets", vec![]).await
    }

    /// `Browser.target`
    ///
    /// ```text
    /// target(): Target
    /// ```
    pub async fn target(&self) -> Result<Target, BridgeError> {
        self.remote.call("target", vec![]).await
    }

    /// `Browser.waitForTarget`
    ///
    /// ```text
    /// waitForTarget(predicate: (x: Target) => boolean | Promise<boolean>, options?: WaitForTargetOptions): Promise<Target>
    /// ```
    pub async fn wait_for_target(&self, predicate: impl Into<JsFunction>, options: Option<Value>) -> Result<Target, BridgeError> {
        self.remote.call("waitForTarget", vec![Some(predicate.into().to_wire()), options]).await
    }

    /// `Browser.pages`
    ///
    /// ```text
    /// pages(includeAll?: boolean): Promise<Page[]>
    /// ```
    pub async fn pages(&self, include_all: Option<bool>) -> Result<Vec<Page>, BridgeError> {
        self.remote.call("pages", vec![include_all.map(|x| Value::from(x))]).await
    }

    /// `Browser.version`
    ///
    /// ```text
    /// version(): Promise<string>
    /// ```
    pub async fn version(&self) -> Result<String, BridgeError> {
        self.remote.call("version", vec![]).await
    }

    /// `Browser.userAgent`
    ///
    /// ```text
    /// userAgent(): Promise<string>
    /// ```
    pub async fn user_agent(&self) -> Result<String, BridgeError> {
        self.remote.call("userAgent", vec![]).await
    }

    /// `Browser.close`
    ///
    /// ```text
    /// close(): Promise<void>
    /// ```
    pub async fn close(&self) -> Result<(), BridgeError> {
        self.remote.call("close", vec![]).await
    }

    /// `Browser.disconnect`
    ///
    /// ```text
    /// disconnect(): Promise<void>
    /// ```
    pub async fn disconnect(&self) -> Result<(), BridgeError> {
        self.remote.call("disconnect", vec![]).await
    }

    /// `Browser.cookies`
    ///
    /// ```text
    /// cookies(): Promise<Cookie[]>
    /// ```
    pub async fn cookies(&self) -> Result<Vec<Value>, BridgeError> {
        self.remote.call("cookies", vec![]).await
    }

    /// `Browser.setCookie`
    ///
    /// ```text
    /// setCookie(...cookies: CookieData[]): Promise<void>
    /// ```
    pub async fn set_cookie(&self, cookies: &[Value]) -> Result<(), BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![];
        call_args.extend(cookies.iter().map(|v| Some(v.clone())));
        self.remote.call("setCookie", call_args).await
    }

    /// `Browser.deleteCookie`
    ///
    /// ```text
    /// deleteCookie(...cookies: Cookie[]): Promise<void>
    /// ```
    pub async fn delete_cookie(&self, cookies: &[Value]) -> Result<(), BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![];
        call_args.extend(cookies.iter().map(|v| Some(v.clone())));
        self.remote.call("deleteCookie", call_args).await
    }

    /// `Browser.deleteMatchingCookies`
    ///
    /// ```text
    /// deleteMatchingCookies(...filters: DeleteCookiesRequest[]): Promise<void>
    /// ```
    pub async fn delete_matching_cookies(&self, filters: &[Value]) -> Result<(), BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![];
        call_args.extend(filters.iter().map(|v| Some(v.clone())));
        self.remote.call("deleteMatchingCookies", call_args).await
    }

    /// `Browser.setPermission`
    ///
    /// ```text
    /// setPermission(origin: string, ...permissions: Array<{ permission: PermissionDescriptor_2; state: PermissionState_2; }> ): Promise<void>
    /// ```
    pub async fn set_permission(&self, origin: &str, permissions: &[Value]) -> Result<(), BridgeError> {
        let mut call_args: Vec<Option<Value>> = vec![Some(Value::from(origin))];
        call_args.extend(permissions.iter().map(|v| Some(v.clone())));
        self.remote.call("setPermission", call_args).await
    }

    /// `Browser.installExtension`
    ///
    /// ```text
    /// installExtension(path: string, options?: ExtensionInstallOptions): Promise<string>
    /// ```
    pub async fn install_extension(&self, path: &str, options: Option<Value>) -> Result<String, BridgeError> {
        self.remote.call("installExtension", vec![Some(Value::from(path)), options]).await
    }

    /// `Browser.uninstallExtension`
    ///
    /// ```text
    /// uninstallExtension(id: string): Promise<void>
    /// ```
    pub async fn uninstall_extension(&self, id: &str) -> Result<(), BridgeError> {
        self.remote.call("uninstallExtension", vec![Some(Value::from(id))]).await
    }

    /// `Browser.installPWA`
    ///
    /// ```text
    /// installPWA(options: InstallPWAOptions): Promise<string>
    /// ```
    pub async fn install_pwa(&self, options: Value) -> Result<String, BridgeError> {
        self.remote.call("installPWA", vec![Some(options)]).await
    }

    /// `Browser.uninstallPWA`
    ///
    /// ```text
    /// uninstallPWA(options: UninstallPWAOptions): Promise<void>
    /// ```
    pub async fn uninstall_pwa(&self, options: Value) -> Result<(), BridgeError> {
        self.remote.call("uninstallPWA", vec![Some(options)]).await
    }

    /// `Browser.launchPWA`
    ///
    /// ```text
    /// launchPWA(options: LaunchPWAOptions): Promise<Page>
    /// ```
    pub async fn launch_pwa(&self, options: Value) -> Result<Page, BridgeError> {
        self.remote.call("launchPWA", vec![Some(options)]).await
    }

    /// `Browser.getPWAState`
    ///
    /// ```text
    /// getPWAState(options: GetPWAStateOptions): Promise<PWAState>
    /// ```
    pub async fn get_pwa_state(&self, options: Value) -> Result<Value, BridgeError> {
        self.remote.call("getPWAState", vec![Some(options)]).await
    }

    /// `Browser.screens`
    ///
    /// ```text
    /// screens(): Promise<ScreenInfo[]>
    /// ```
    pub async fn screens(&self) -> Result<Vec<Value>, BridgeError> {
        self.remote.call("screens", vec![]).await
    }

    /// `Browser.addScreen`
    ///
    /// ```text
    /// addScreen(params: AddScreenParams): Promise<ScreenInfo>
    /// ```
    pub async fn add_screen(&self, params: Value) -> Result<Value, BridgeError> {
        self.remote.call("addScreen", vec![Some(params)]).await
    }

    /// `Browser.removeScreen`
    ///
    /// ```text
    /// removeScreen(screenId: string): Promise<void>
    /// ```
    pub async fn remove_screen(&self, screen_id: &str) -> Result<(), BridgeError> {
        self.remote.call("removeScreen", vec![Some(Value::from(screen_id))]).await
    }

    /// `Browser.connected`
    ///
    /// ```text
    /// get connected(): boolean
    /// ```
    pub async fn connected(&self) -> Result<bool, BridgeError> {
        self.remote.get("connected").await
    }

    /// `Browser.debugInfo`
    ///
    /// ```text
    /// get debugInfo(): DebugInfo
    /// ```
    pub async fn debug_info(&self) -> Result<Value, BridgeError> {
        self.remote.get("debugInfo").await
    }

    /// `Browser.extensions`
    ///
    /// ```text
    /// extensions(): Promise<Map<string, Extension>>
    /// ```
    pub async fn extensions(&self) -> Result<Value, BridgeError> {
        self.remote.call("extensions", vec![]).await
    }
}