browser_commander/puppeteer/api/cdp_session.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 `CDPSession` (puppeteer-core 25.12.0), a remote object
13 /// served by `browser-commander serve --stdio`.
14 ///
15 /// Extends [`EventEmitter`]; the inherited methods are repeated here.
16 CDPSession
17);
18
19impl CDPSession {
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<CDPSession, 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<CDPSession, 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<CDPSession, 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<CDPSession, BridgeError> {
71 self.remote.call("removeAllListeners", vec![type_]).await
72 }
73
74 /// `CDPSession.connection`
75 ///
76 /// ```text
77 /// connection(): Connection | undefined
78 /// ```
79 pub async fn connection(&self) -> Result<Option<Connection>, BridgeError> {
80 self.remote.call("connection", vec![]).await
81 }
82
83 /// `CDPSession.detached`
84 ///
85 /// ```text
86 /// get detached(): boolean
87 /// ```
88 pub async fn detached(&self) -> Result<bool, BridgeError> {
89 self.remote.get("detached").await
90 }
91
92 /// `CDPSession.send`
93 ///
94 /// ```text
95 /// send<T extends keyof ProtocolMapping.Commands>(method: T, params?: ProtocolMapping.Commands[T]['paramsType'][0], options?: CommandOptions): Promise<ProtocolMapping.Commands[T]['returnType']>
96 /// ```
97 pub async fn send(&self, method: Value, params: Option<Value>, options: Option<Value>) -> Result<Value, BridgeError> {
98 self.remote.call("send", vec![Some(method), params, options]).await
99 }
100
101 /// `CDPSession.detach`
102 ///
103 /// ```text
104 /// detach(): Promise<void>
105 /// ```
106 pub async fn detach(&self) -> Result<(), BridgeError> {
107 self.remote.call("detach", vec![]).await
108 }
109
110 /// `CDPSession.id`
111 ///
112 /// ```text
113 /// id(): string
114 /// ```
115 pub async fn id(&self) -> Result<String, BridgeError> {
116 self.remote.call("id", vec![]).await
117 }
118}