browser_commander/puppeteer/api/connection.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 `Connection` (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 Connection
17);
18
19impl Connection {
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<Connection, 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<Connection, 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<Connection, 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<Connection, BridgeError> {
71 self.remote.call("removeAllListeners", vec![type_]).await
72 }
73
74 /// `Connection.timeout`
75 ///
76 /// ```text
77 /// get timeout(): number
78 /// ```
79 pub async fn timeout(&self) -> Result<f64, BridgeError> {
80 self.remote.get("timeout").await
81 }
82
83 /// `Connection.session`
84 ///
85 /// ```text
86 /// session(sessionId: string): CDPSession | null
87 /// ```
88 pub async fn session(&self, session_id: &str) -> Result<Option<CDPSession>, BridgeError> {
89 self.remote.call("session", vec![Some(Value::from(session_id))]).await
90 }
91
92 /// `Connection.url`
93 ///
94 /// ```text
95 /// url(): string
96 /// ```
97 pub async fn url(&self) -> Result<String, BridgeError> {
98 self.remote.call("url", vec![]).await
99 }
100
101 /// `Connection.send`
102 ///
103 /// ```text
104 /// send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0], options?: CommandOptions): Promise<ProtocolMapping.Commands[T]['returnType']>
105 /// ```
106 pub async fn send(&self, method: Value, params: Option<Value>, options: Option<Value>) -> Result<Value, BridgeError> {
107 self.remote.call("send", vec![Some(method), params, options]).await
108 }
109
110 /// `Connection.dispose`
111 ///
112 /// ```text
113 /// dispose(): void
114 /// ```
115 pub async fn dispose(&self) -> Result<(), BridgeError> {
116 self.remote.call("dispose", vec![]).await
117 }
118
119 /// `Connection.createSession`
120 ///
121 /// ```text
122 /// createSession(targetInfo: Protocol.Target.TargetInfo): Promise<CDPSession>
123 /// ```
124 pub async fn create_session(&self, target_info: Value) -> Result<CDPSession, BridgeError> {
125 self.remote.call("createSession", vec![Some(target_info)]).await
126 }
127}