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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! This domain allows configuring virtual Bluetooth devices to test the
//! web-bluetooth API.
//!
//! Types, command parameters and event payloads for the `BluetoothEmulation`
//! 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};

/// Indicates the various states of Central.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CentralState {
    /// `absent`
    #[serde(rename = "absent")]
    Absent,
    /// `powered-off`
    #[serde(rename = "powered-off")]
    PoweredOff,
    /// `powered-on`
    #[serde(rename = "powered-on")]
    PoweredOn,
    /// 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),
}

/// Indicates the various types of GATT event.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum GattOperationType {
    /// `connection`
    #[serde(rename = "connection")]
    Connection,
    /// `discovery`
    #[serde(rename = "discovery")]
    Discovery,
    /// 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),
}

/// Indicates the various types of characteristic write.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CharacteristicWriteType {
    /// `write-default-deprecated`
    #[serde(rename = "write-default-deprecated")]
    WriteDefaultDeprecated,
    /// `write-with-response`
    #[serde(rename = "write-with-response")]
    WriteWithResponse,
    /// `write-without-response`
    #[serde(rename = "write-without-response")]
    WriteWithoutResponse,
    /// 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),
}

/// Indicates the various types of characteristic operation.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CharacteristicOperationType {
    /// `read`
    #[serde(rename = "read")]
    Read,
    /// `write`
    #[serde(rename = "write")]
    Write,
    /// `subscribe-to-notifications`
    #[serde(rename = "subscribe-to-notifications")]
    SubscribeToNotifications,
    /// `unsubscribe-from-notifications`
    #[serde(rename = "unsubscribe-from-notifications")]
    UnsubscribeFromNotifications,
    /// 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),
}

/// Indicates the various types of descriptor operation.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DescriptorOperationType {
    /// `read`
    #[serde(rename = "read")]
    Read,
    /// `write`
    #[serde(rename = "write")]
    Write,
    /// 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),
}

/// Stores the manufacturer data
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ManufacturerData {
    /// Company identifier
    /// <https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml>
    /// <https://usb.org/developers>
    pub key: i64,
    /// Manufacturer-specific data (Encoded as a base64 string when passed over
    /// JSON)
    pub data: String,
}

/// Stores the byte data of the advertisement packet sent by a Bluetooth
/// device.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ScanRecord {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub uuids: Option<Vec<String>>,
    /// Stores the external appearance description of the device.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub appearance: Option<i64>,
    /// Stores the transmission power of a broadcasting device.
    #[serde(rename = "txPower", default, skip_serializing_if = "Option::is_none")]
    pub tx_power: Option<i64>,
    /// Key is the company identifier and the value is an array of bytes of
    /// manufacturer specific data.
    #[serde(
        rename = "manufacturerData",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub manufacturer_data: Option<Vec<ManufacturerData>>,
}

/// Stores the advertisement packet information that is sent by a Bluetooth
/// device.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ScanEntry {
    #[serde(rename = "deviceAddress")]
    pub device_address: String,
    pub rssi: i64,
    #[serde(rename = "scanRecord")]
    pub scan_record: ScanRecord,
}

/// Describes the properties of a characteristic. This follows Bluetooth Core
/// Specification BT 4.2 Vol 3 Part G 3.3.1. Characteristic Properties.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CharacteristicProperties {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub broadcast: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub read: Option<bool>,
    #[serde(
        rename = "writeWithoutResponse",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub write_without_response: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub write: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub notify: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub indicate: Option<bool>,
    #[serde(
        rename = "authenticatedSignedWrites",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub authenticated_signed_writes: Option<bool>,
    #[serde(
        rename = "extendedProperties",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub extended_properties: Option<bool>,
}

/// Enable the BluetoothEmulation domain.
///
/// Parameters of `BluetoothEmulation.enable`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {
    /// State of the simulated central.
    pub state: CentralState,
    /// If the simulated central supports low-energy.
    #[serde(rename = "leSupported")]
    pub le_supported: bool,
}

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

/// Set the state of the simulated central.
///
/// Parameters of `BluetoothEmulation.setSimulatedCentralState`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SetSimulatedCentralStateParams {
    /// State of the simulated central.
    pub state: CentralState,
}

impl crate::typed::Command for SetSimulatedCentralStateParams {
    const METHOD: &'static str = "BluetoothEmulation.setSimulatedCentralState";
    type Returns = crate::typed::NoReturns;
}

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

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

/// Simulates a peripheral with |address|, |name| and |knownServiceUuids| that
/// has already been connected to the system.
///
/// Parameters of `BluetoothEmulation.simulatePreconnectedPeripheral`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SimulatePreconnectedPeripheralParams {
    pub address: String,
    pub name: String,
    #[serde(rename = "manufacturerData")]
    pub manufacturer_data: Vec<ManufacturerData>,
    #[serde(rename = "knownServiceUuids")]
    pub known_service_uuids: Vec<String>,
}

impl crate::typed::Command for SimulatePreconnectedPeripheralParams {
    const METHOD: &'static str = "BluetoothEmulation.simulatePreconnectedPeripheral";
    type Returns = crate::typed::NoReturns;
}

/// Simulates an advertisement packet described in |entry| being received by
/// the central.
///
/// Parameters of `BluetoothEmulation.simulateAdvertisement`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SimulateAdvertisementParams {
    pub entry: ScanEntry,
}

impl crate::typed::Command for SimulateAdvertisementParams {
    const METHOD: &'static str = "BluetoothEmulation.simulateAdvertisement";
    type Returns = crate::typed::NoReturns;
}

/// Simulates the response code from the peripheral with |address| for a GATT
/// operation of |type|. The |code| value follows the HCI Error Codes from
/// Bluetooth Core Specification Vol 2 Part D 1.3 List Of Error Codes.
///
/// Parameters of `BluetoothEmulation.simulateGATTOperationResponse`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SimulateGattOperationResponseParams {
    pub address: String,
    pub r#type: GattOperationType,
    pub code: i64,
}

impl crate::typed::Command for SimulateGattOperationResponseParams {
    const METHOD: &'static str = "BluetoothEmulation.simulateGATTOperationResponse";
    type Returns = crate::typed::NoReturns;
}

/// Simulates the response from the characteristic with |characteristicId| for
/// a characteristic operation of |type|. The |code| value follows the Error
/// Codes from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error
/// Response. The |data| is expected to exist when simulating a successful
/// read operation response.
///
/// Parameters of `BluetoothEmulation.simulateCharacteristicOperationResponse`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SimulateCharacteristicOperationResponseParams {
    #[serde(rename = "characteristicId")]
    pub characteristic_id: String,
    pub r#type: CharacteristicOperationType,
    pub code: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
}

impl crate::typed::Command for SimulateCharacteristicOperationResponseParams {
    const METHOD: &'static str = "BluetoothEmulation.simulateCharacteristicOperationResponse";
    type Returns = crate::typed::NoReturns;
}

/// Simulates the response from the descriptor with |descriptorId| for a
/// descriptor operation of |type|. The |code| value follows the Error Codes
/// from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error Response. The
/// |data| is expected to exist when simulating a successful read operation
/// response.
///
/// Parameters of `BluetoothEmulation.simulateDescriptorOperationResponse`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SimulateDescriptorOperationResponseParams {
    #[serde(rename = "descriptorId")]
    pub descriptor_id: String,
    pub r#type: DescriptorOperationType,
    pub code: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
}

impl crate::typed::Command for SimulateDescriptorOperationResponseParams {
    const METHOD: &'static str = "BluetoothEmulation.simulateDescriptorOperationResponse";
    type Returns = crate::typed::NoReturns;
}

/// Adds a service with |serviceUuid| to the peripheral with |address|.
///
/// Parameters of `BluetoothEmulation.addService`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddServiceParams {
    pub address: String,
    #[serde(rename = "serviceUuid")]
    pub service_uuid: String,
}

/// What `BluetoothEmulation.addService` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddServiceReturns {
    /// An identifier that uniquely represents this service.
    #[serde(rename = "serviceId")]
    pub service_id: String,
}

impl crate::typed::Command for AddServiceParams {
    const METHOD: &'static str = "BluetoothEmulation.addService";
    type Returns = AddServiceReturns;
}

/// Removes the service respresented by |serviceId| from the simulated
/// central.
///
/// Parameters of `BluetoothEmulation.removeService`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoveServiceParams {
    #[serde(rename = "serviceId")]
    pub service_id: String,
}

impl crate::typed::Command for RemoveServiceParams {
    const METHOD: &'static str = "BluetoothEmulation.removeService";
    type Returns = crate::typed::NoReturns;
}

/// Adds a characteristic with |characteristicUuid| and |properties| to the
/// service represented by |serviceId|.
///
/// Parameters of `BluetoothEmulation.addCharacteristic`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddCharacteristicParams {
    #[serde(rename = "serviceId")]
    pub service_id: String,
    #[serde(rename = "characteristicUuid")]
    pub characteristic_uuid: String,
    pub properties: CharacteristicProperties,
}

/// What `BluetoothEmulation.addCharacteristic` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddCharacteristicReturns {
    /// An identifier that uniquely represents this characteristic.
    #[serde(rename = "characteristicId")]
    pub characteristic_id: String,
}

impl crate::typed::Command for AddCharacteristicParams {
    const METHOD: &'static str = "BluetoothEmulation.addCharacteristic";
    type Returns = AddCharacteristicReturns;
}

/// Removes the characteristic respresented by |characteristicId| from the
/// simulated central.
///
/// Parameters of `BluetoothEmulation.removeCharacteristic`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoveCharacteristicParams {
    #[serde(rename = "characteristicId")]
    pub characteristic_id: String,
}

impl crate::typed::Command for RemoveCharacteristicParams {
    const METHOD: &'static str = "BluetoothEmulation.removeCharacteristic";
    type Returns = crate::typed::NoReturns;
}

/// Adds a descriptor with |descriptorUuid| to the characteristic respresented
/// by |characteristicId|.
///
/// Parameters of `BluetoothEmulation.addDescriptor`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddDescriptorParams {
    #[serde(rename = "characteristicId")]
    pub characteristic_id: String,
    #[serde(rename = "descriptorUuid")]
    pub descriptor_uuid: String,
}

/// What `BluetoothEmulation.addDescriptor` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AddDescriptorReturns {
    /// An identifier that uniquely represents this descriptor.
    #[serde(rename = "descriptorId")]
    pub descriptor_id: String,
}

impl crate::typed::Command for AddDescriptorParams {
    const METHOD: &'static str = "BluetoothEmulation.addDescriptor";
    type Returns = AddDescriptorReturns;
}

/// Removes the descriptor with |descriptorId| from the simulated central.
///
/// Parameters of `BluetoothEmulation.removeDescriptor`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoveDescriptorParams {
    #[serde(rename = "descriptorId")]
    pub descriptor_id: String,
}

impl crate::typed::Command for RemoveDescriptorParams {
    const METHOD: &'static str = "BluetoothEmulation.removeDescriptor";
    type Returns = crate::typed::NoReturns;
}

/// Simulates a GATT disconnection from the peripheral with |address|.
///
/// Parameters of `BluetoothEmulation.simulateGATTDisconnection`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SimulateGattDisconnectionParams {
    pub address: String,
}

impl crate::typed::Command for SimulateGattDisconnectionParams {
    const METHOD: &'static str = "BluetoothEmulation.simulateGATTDisconnection";
    type Returns = crate::typed::NoReturns;
}

/// Event for when a GATT operation of |type| to the peripheral with |address|
/// happened.
///
/// Payload of the `BluetoothEmulation.gattOperationReceived` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GattOperationReceivedEvent {
    pub address: String,
    pub r#type: GattOperationType,
}

impl crate::typed::Event for GattOperationReceivedEvent {
    const METHOD: &'static str = "BluetoothEmulation.gattOperationReceived";
}

/// Event for when a characteristic operation of |type| to the characteristic
/// respresented by |characteristicId| happened. |data| and |writeType| is
/// expected to exist when |type| is write.
///
/// Payload of the `BluetoothEmulation.characteristicOperationReceived` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CharacteristicOperationReceivedEvent {
    #[serde(rename = "characteristicId")]
    pub characteristic_id: String,
    pub r#type: CharacteristicOperationType,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
    #[serde(rename = "writeType", default, skip_serializing_if = "Option::is_none")]
    pub write_type: Option<CharacteristicWriteType>,
}

impl crate::typed::Event for CharacteristicOperationReceivedEvent {
    const METHOD: &'static str = "BluetoothEmulation.characteristicOperationReceived";
}

/// Event for when a descriptor operation of |type| to the descriptor
/// respresented by |descriptorId| happened. |data| is expected to exist when
/// |type| is write.
///
/// Payload of the `BluetoothEmulation.descriptorOperationReceived` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DescriptorOperationReceivedEvent {
    #[serde(rename = "descriptorId")]
    pub descriptor_id: String,
    pub r#type: DescriptorOperationType,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data: Option<String>,
}

impl crate::typed::Event for DescriptorOperationReceivedEvent {
    const METHOD: &'static str = "BluetoothEmulation.descriptorOperationReceived";
}