cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! This domain allows inspection of Web Audio API.
//! <https://webaudio.github.io/web-audio-api/>
//!
//! Types, command parameters and event payloads for the `WebAudio`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].
//!
//! This domain is experimental and may change without notice.

use serde::{Deserialize, Serialize};

/// An unique ID for a graph object (AudioContext, AudioNode, AudioParam) in
/// Web Audio API
pub type GraphObjectId = String;

/// Enum of BaseAudioContext types
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ContextType {
    /// `realtime`
    #[serde(rename = "realtime")]
    Realtime,
    /// `offline`
    #[serde(rename = "offline")]
    Offline,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Enum of AudioContextState from the spec
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ContextState {
    /// `suspended`
    #[serde(rename = "suspended")]
    Suspended,
    /// `running`
    #[serde(rename = "running")]
    Running,
    /// `closed`
    #[serde(rename = "closed")]
    Closed,
    /// `interrupted`
    #[serde(rename = "interrupted")]
    Interrupted,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Enum of AudioNode types
pub type NodeType = String;

/// Enum of AudioNode::ChannelCountMode from the spec
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ChannelCountMode {
    /// `clamped-max`
    #[serde(rename = "clamped-max")]
    ClampedMax,
    /// `explicit`
    #[serde(rename = "explicit")]
    Explicit,
    /// `max`
    #[serde(rename = "max")]
    Max,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Enum of AudioNode::ChannelInterpretation from the spec
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ChannelInterpretation {
    /// `discrete`
    #[serde(rename = "discrete")]
    Discrete,
    /// `speakers`
    #[serde(rename = "speakers")]
    Speakers,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Enum of AudioParam types
pub type ParamType = String;

/// Enum of AudioParam::AutomationRate from the spec
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AutomationRate {
    /// `a-rate`
    #[serde(rename = "a-rate")]
    ARate,
    /// `k-rate`
    #[serde(rename = "k-rate")]
    KRate,
    /// A value this vendored schema does not list. Chrome adds values ahead of
    /// the published protocol, so an unrecognised one is kept as it arrived
    /// rather than failing the payload it came in.
    #[serde(untagged)]
    Unrecognized(String),
}

/// Fields in AudioContext that change in real-time.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ContextRealtimeData {
    /// The current context time in second in BaseAudioContext.
    #[serde(rename = "currentTime")]
    pub current_time: f64,
    /// The time spent on rendering graph divided by render quantum duration, and
    /// multiplied by 100. 100 means the audio renderer reached the full capacity
    /// and glitch may occur.
    #[serde(rename = "renderCapacity")]
    pub render_capacity: f64,
    /// A running mean of callback interval.
    #[serde(rename = "callbackIntervalMean")]
    pub callback_interval_mean: f64,
    /// A running variance of callback interval.
    #[serde(rename = "callbackIntervalVariance")]
    pub callback_interval_variance: f64,
}

/// Protocol object for BaseAudioContext
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BaseAudioContext {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "contextType")]
    pub context_type: ContextType,
    #[serde(rename = "contextState")]
    pub context_state: ContextState,
    #[serde(
        rename = "realtimeData",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub realtime_data: Option<ContextRealtimeData>,
    /// Platform-dependent callback buffer size.
    #[serde(rename = "callbackBufferSize")]
    pub callback_buffer_size: f64,
    /// Number of output channels supported by audio hardware in use.
    #[serde(rename = "maxOutputChannelCount")]
    pub max_output_channel_count: f64,
    /// Context sample rate.
    #[serde(rename = "sampleRate")]
    pub sample_rate: f64,
    #[serde(rename = "renderQuantumSize")]
    pub render_quantum_size: f64,
}

/// Protocol object for AudioListener
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AudioListener {
    #[serde(rename = "listenerId")]
    pub listener_id: GraphObjectId,
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
}

/// Protocol object for AudioNode
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AudioNode {
    #[serde(rename = "nodeId")]
    pub node_id: GraphObjectId,
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "nodeType")]
    pub node_type: NodeType,
    #[serde(rename = "numberOfInputs")]
    pub number_of_inputs: f64,
    #[serde(rename = "numberOfOutputs")]
    pub number_of_outputs: f64,
    #[serde(rename = "channelCount")]
    pub channel_count: f64,
    #[serde(rename = "channelCountMode")]
    pub channel_count_mode: ChannelCountMode,
    #[serde(rename = "channelInterpretation")]
    pub channel_interpretation: ChannelInterpretation,
}

/// Protocol object for AudioParam
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AudioParam {
    #[serde(rename = "paramId")]
    pub param_id: GraphObjectId,
    #[serde(rename = "nodeId")]
    pub node_id: GraphObjectId,
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "paramType")]
    pub param_type: ParamType,
    pub rate: AutomationRate,
    #[serde(rename = "defaultValue")]
    pub default_value: f64,
    #[serde(rename = "minValue")]
    pub min_value: f64,
    #[serde(rename = "maxValue")]
    pub max_value: f64,
}

/// Enables the WebAudio domain and starts sending context lifetime events.
///
/// Parameters of `WebAudio.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

impl crate::typed::Command for EnableParams {
    const METHOD: &'static str = "WebAudio.enable";
    type Returns = crate::typed::NoReturns;
}

/// Disables the WebAudio domain.
///
/// Parameters of `WebAudio.disable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisableParams {}

impl crate::typed::Command for DisableParams {
    const METHOD: &'static str = "WebAudio.disable";
    type Returns = crate::typed::NoReturns;
}

/// Fetch the realtime data from the registered contexts.
///
/// Parameters of `WebAudio.getRealtimeData`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetRealtimeDataParams {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
}

/// What `WebAudio.getRealtimeData` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetRealtimeDataReturns {
    #[serde(rename = "realtimeData")]
    pub realtime_data: ContextRealtimeData,
}

impl crate::typed::Command for GetRealtimeDataParams {
    const METHOD: &'static str = "WebAudio.getRealtimeData";
    type Returns = GetRealtimeDataReturns;
}

/// Notifies that a new BaseAudioContext has been created.
///
/// Payload of the `WebAudio.contextCreated` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ContextCreatedEvent {
    pub context: BaseAudioContext,
}

impl crate::typed::Event for ContextCreatedEvent {
    const METHOD: &'static str = "WebAudio.contextCreated";
}

/// Notifies that an existing BaseAudioContext will be destroyed.
///
/// Payload of the `WebAudio.contextWillBeDestroyed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ContextWillBeDestroyedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
}

impl crate::typed::Event for ContextWillBeDestroyedEvent {
    const METHOD: &'static str = "WebAudio.contextWillBeDestroyed";
}

/// Notifies that existing BaseAudioContext has changed some properties (id
/// stays the same)..
///
/// Payload of the `WebAudio.contextChanged` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ContextChangedEvent {
    pub context: BaseAudioContext,
}

impl crate::typed::Event for ContextChangedEvent {
    const METHOD: &'static str = "WebAudio.contextChanged";
}

/// Notifies that the construction of an AudioListener has finished.
///
/// Payload of the `WebAudio.audioListenerCreated` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AudioListenerCreatedEvent {
    pub listener: AudioListener,
}

impl crate::typed::Event for AudioListenerCreatedEvent {
    const METHOD: &'static str = "WebAudio.audioListenerCreated";
}

/// Notifies that a new AudioListener has been created.
///
/// Payload of the `WebAudio.audioListenerWillBeDestroyed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AudioListenerWillBeDestroyedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "listenerId")]
    pub listener_id: GraphObjectId,
}

impl crate::typed::Event for AudioListenerWillBeDestroyedEvent {
    const METHOD: &'static str = "WebAudio.audioListenerWillBeDestroyed";
}

/// Notifies that a new AudioNode has been created.
///
/// Payload of the `WebAudio.audioNodeCreated` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AudioNodeCreatedEvent {
    pub node: AudioNode,
}

impl crate::typed::Event for AudioNodeCreatedEvent {
    const METHOD: &'static str = "WebAudio.audioNodeCreated";
}

/// Notifies that an existing AudioNode has been destroyed.
///
/// Payload of the `WebAudio.audioNodeWillBeDestroyed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AudioNodeWillBeDestroyedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "nodeId")]
    pub node_id: GraphObjectId,
}

impl crate::typed::Event for AudioNodeWillBeDestroyedEvent {
    const METHOD: &'static str = "WebAudio.audioNodeWillBeDestroyed";
}

/// Notifies that a new AudioParam has been created.
///
/// Payload of the `WebAudio.audioParamCreated` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AudioParamCreatedEvent {
    pub param: AudioParam,
}

impl crate::typed::Event for AudioParamCreatedEvent {
    const METHOD: &'static str = "WebAudio.audioParamCreated";
}

/// Notifies that an existing AudioParam has been destroyed.
///
/// Payload of the `WebAudio.audioParamWillBeDestroyed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AudioParamWillBeDestroyedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "nodeId")]
    pub node_id: GraphObjectId,
    #[serde(rename = "paramId")]
    pub param_id: GraphObjectId,
}

impl crate::typed::Event for AudioParamWillBeDestroyedEvent {
    const METHOD: &'static str = "WebAudio.audioParamWillBeDestroyed";
}

/// Notifies that two AudioNodes are connected.
///
/// Payload of the `WebAudio.nodesConnected` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct NodesConnectedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "sourceId")]
    pub source_id: GraphObjectId,
    #[serde(rename = "destinationId")]
    pub destination_id: GraphObjectId,
    #[serde(
        rename = "sourceOutputIndex",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub source_output_index: Option<f64>,
    #[serde(
        rename = "destinationInputIndex",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub destination_input_index: Option<f64>,
}

impl crate::typed::Event for NodesConnectedEvent {
    const METHOD: &'static str = "WebAudio.nodesConnected";
}

/// Notifies that AudioNodes are disconnected. The destination can be null,
/// and it means all the outgoing connections from the source are
/// disconnected.
///
/// Payload of the `WebAudio.nodesDisconnected` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct NodesDisconnectedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "sourceId")]
    pub source_id: GraphObjectId,
    #[serde(rename = "destinationId")]
    pub destination_id: GraphObjectId,
    #[serde(
        rename = "sourceOutputIndex",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub source_output_index: Option<f64>,
    #[serde(
        rename = "destinationInputIndex",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub destination_input_index: Option<f64>,
}

impl crate::typed::Event for NodesDisconnectedEvent {
    const METHOD: &'static str = "WebAudio.nodesDisconnected";
}

/// Notifies that an AudioNode is connected to an AudioParam.
///
/// Payload of the `WebAudio.nodeParamConnected` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct NodeParamConnectedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "sourceId")]
    pub source_id: GraphObjectId,
    #[serde(rename = "destinationId")]
    pub destination_id: GraphObjectId,
    #[serde(
        rename = "sourceOutputIndex",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub source_output_index: Option<f64>,
}

impl crate::typed::Event for NodeParamConnectedEvent {
    const METHOD: &'static str = "WebAudio.nodeParamConnected";
}

/// Notifies that an AudioNode is disconnected to an AudioParam.
///
/// Payload of the `WebAudio.nodeParamDisconnected` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct NodeParamDisconnectedEvent {
    #[serde(rename = "contextId")]
    pub context_id: GraphObjectId,
    #[serde(rename = "sourceId")]
    pub source_id: GraphObjectId,
    #[serde(rename = "destinationId")]
    pub destination_id: GraphObjectId,
    #[serde(
        rename = "sourceOutputIndex",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub source_output_index: Option<f64>,
}

impl crate::typed::Event for NodeParamDisconnectedEvent {
    const METHOD: &'static str = "WebAudio.nodeParamDisconnected";
}