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
506
507
508
509
510
511
512
513
514
515
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `Tracing` domain.
//!
//! Types, command parameters and event payloads for the `Tracing`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].

use serde::{Deserialize, Serialize};

/// Configuration for memory dump. Used only when "memory-infra" category is
/// enabled.
///
/// Experimental: may change without notice.
pub type MemoryDumpConfig = serde_json::Value;

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TraceConfig {
    /// Controls how the trace buffer stores data. The default is
    /// `recordUntilFull`.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "recordMode",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub record_mode: Option<TraceConfigRecordMode>,
    /// Size of the trace buffer in kilobytes. If not specified or zero is passed,
    /// a default value of 200 MB would be used.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "traceBufferSizeInKb",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub trace_buffer_size_in_kb: Option<f64>,
    /// Turns on JavaScript stack sampling.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "enableSampling",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub enable_sampling: Option<bool>,
    /// Turns on system tracing.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "enableSystrace",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub enable_systrace: Option<bool>,
    /// Turns on argument filter.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "enableArgumentFilter",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub enable_argument_filter: Option<bool>,
    /// Included category filters.
    #[serde(
        rename = "includedCategories",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub included_categories: Option<Vec<String>>,
    /// Excluded category filters.
    #[serde(
        rename = "excludedCategories",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub excluded_categories: Option<Vec<String>>,
    /// Configuration to synthesize the delays in tracing.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "syntheticDelays",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub synthetic_delays: Option<Vec<String>>,
    /// Configuration for memory dump triggers. Used only when "memory-infra"
    /// category is enabled.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "memoryDumpConfig",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub memory_dump_config: Option<MemoryDumpConfig>,
}

/// The values `recordMode` accepts on `TraceConfig`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TraceConfigRecordMode {
    /// `recordUntilFull`
    #[serde(rename = "recordUntilFull")]
    RecordUntilFull,
    /// `recordContinuously`
    #[serde(rename = "recordContinuously")]
    RecordContinuously,
    /// `recordAsMuchAsPossible`
    #[serde(rename = "recordAsMuchAsPossible")]
    RecordAsMuchAsPossible,
    /// `echoToConsole`
    #[serde(rename = "echoToConsole")]
    EchoToConsole,
    /// 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),
}

/// Data format of a trace. Can be either the legacy JSON format or the
/// protocol buffer format. Note that the JSON format will be deprecated soon.
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StreamFormat {
    /// `json`
    #[serde(rename = "json")]
    Json,
    /// `proto`
    #[serde(rename = "proto")]
    Proto,
    /// 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),
}

/// Compression type to use for traces returned via streams.
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StreamCompression {
    /// `none`
    #[serde(rename = "none")]
    None,
    /// `gzip`
    #[serde(rename = "gzip")]
    Gzip,
    /// 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),
}

/// Details exposed when memory request explicitly declared. Keep consistent
/// with memory_dump_request_args.h and memory_instrumentation.mojom
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MemoryDumpLevelOfDetail {
    /// `background`
    #[serde(rename = "background")]
    Background,
    /// `light`
    #[serde(rename = "light")]
    Light,
    /// `detailed`
    #[serde(rename = "detailed")]
    Detailed,
    /// 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),
}

/// Backend type to use for tracing. `chrome` uses the Chrome-integrated
/// tracing service and is supported on all platforms. `system` is only
/// supported on Chrome OS and uses the Perfetto system tracing service.
/// `auto` chooses `system` when the perfettoConfig provided to Tracing.start
/// specifies at least one non-Chrome data source; otherwise uses `chrome`.
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TracingBackend {
    /// `auto`
    #[serde(rename = "auto")]
    Auto,
    /// `chrome`
    #[serde(rename = "chrome")]
    Chrome,
    /// `system`
    #[serde(rename = "system")]
    System,
    /// 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),
}

/// Stop trace events collection.
///
/// Parameters of `Tracing.end`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EndParams {}

impl crate::typed::Command for EndParams {
    const METHOD: &'static str = "Tracing.end";
    type Returns = crate::typed::NoReturns;
}

/// Gets supported tracing categories.
///
/// Experimental: may change without notice.
///
/// Parameters of `Tracing.getCategories`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetCategoriesParams {}

/// What `Tracing.getCategories` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetCategoriesReturns {
    /// A list of supported tracing categories.
    pub categories: Vec<String>,
}

impl crate::typed::Command for GetCategoriesParams {
    const METHOD: &'static str = "Tracing.getCategories";
    type Returns = GetCategoriesReturns;
}

/// Return a descriptor for all available tracing categories.
///
/// Experimental: may change without notice.
///
/// Parameters of `Tracing.getTrackEventDescriptor`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetTrackEventDescriptorParams {}

/// What `Tracing.getTrackEventDescriptor` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetTrackEventDescriptorReturns {
    /// Base64-encoded serialized perfetto.protos.TrackEventDescriptor protobuf
    /// message. (Encoded as a base64 string when passed over JSON)
    pub descriptor: String,
}

impl crate::typed::Command for GetTrackEventDescriptorParams {
    const METHOD: &'static str = "Tracing.getTrackEventDescriptor";
    type Returns = GetTrackEventDescriptorReturns;
}

/// Record a clock sync marker in the trace.
///
/// Experimental: may change without notice.
///
/// Parameters of `Tracing.recordClockSyncMarker`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RecordClockSyncMarkerParams {
    /// The ID of this clock sync marker
    #[serde(rename = "syncId")]
    pub sync_id: String,
}

impl crate::typed::Command for RecordClockSyncMarkerParams {
    const METHOD: &'static str = "Tracing.recordClockSyncMarker";
    type Returns = crate::typed::NoReturns;
}

/// Request a global memory dump.
///
/// Experimental: may change without notice.
///
/// Parameters of `Tracing.requestMemoryDump`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestMemoryDumpParams {
    /// Enables more deterministic results by forcing garbage collection
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub deterministic: Option<bool>,
    /// Specifies level of details in memory dump. Defaults to "detailed".
    #[serde(
        rename = "levelOfDetail",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub level_of_detail: Option<MemoryDumpLevelOfDetail>,
}

/// What `Tracing.requestMemoryDump` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestMemoryDumpReturns {
    /// GUID of the resulting global memory dump.
    #[serde(rename = "dumpGuid")]
    pub dump_guid: String,
    /// True iff the global memory dump succeeded.
    pub success: bool,
}

impl crate::typed::Command for RequestMemoryDumpParams {
    const METHOD: &'static str = "Tracing.requestMemoryDump";
    type Returns = RequestMemoryDumpReturns;
}

/// Start trace events collection.
///
/// Parameters of `Tracing.start`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartParams {
    /// Category/tag filter
    ///
    /// Deprecated in the protocol.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub categories: Option<String>,
    /// Tracing options
    ///
    /// Deprecated in the protocol.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub options: Option<String>,
    /// If set, the agent will issue bufferUsage events at this interval,
    /// specified in milliseconds
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "bufferUsageReportingInterval",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub buffer_usage_reporting_interval: Option<f64>,
    /// Whether to report trace events as series of dataCollected events or to
    /// save trace to a stream (defaults to `ReportEvents`).
    #[serde(
        rename = "transferMode",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub transfer_mode: Option<StartTransferMode>,
    /// Trace data format to use. This only applies when using `ReturnAsStream`
    /// transfer mode (defaults to `json`).
    #[serde(
        rename = "streamFormat",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub stream_format: Option<StreamFormat>,
    /// Compression format to use. This only applies when using `ReturnAsStream`
    /// transfer mode (defaults to `none`)
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "streamCompression",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub stream_compression: Option<StreamCompression>,
    #[serde(
        rename = "traceConfig",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub trace_config: Option<TraceConfig>,
    /// Base64-encoded serialized perfetto.protos.TraceConfig protobuf message
    /// When specified, the parameters `categories`, `options`, `traceConfig` are
    /// ignored. (Encoded as a base64 string when passed over JSON)
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "perfettoConfig",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub perfetto_config: Option<String>,
    /// Backend type (defaults to `auto`)
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "tracingBackend",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub tracing_backend: Option<TracingBackend>,
    /// Maximum width and height (in pixels) of each captured screenshot. Only
    /// used when the `disabled-by-default-devtools.screenshot` category is
    /// enabled. Defaults to 500. The combined memory footprint of screenshots
    /// (`screenshotMaxSize` * `screenshotMaxSize` * 4 * `screenshotMaxCount`) is
    /// clamped to the existing per-session budget.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "screenshotMaxSize",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub screenshot_max_size: Option<i64>,
    /// Maximum number of screenshots captured during a single tracing session.
    /// Only used when the `disabled-by-default-devtools.screenshot` category is
    /// enabled. Defaults to 450. Clamped together with `screenshotMaxSize` to
    /// stay within the per-session screenshot memory budget.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "screenshotMaxCount",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub screenshot_max_count: Option<i64>,
}

/// The values `transferMode` accepts on `start`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StartTransferMode {
    /// `ReportEvents`
    ReportEvents,
    /// `ReturnAsStream`
    ReturnAsStream,
    /// 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),
}

impl crate::typed::Command for StartParams {
    const METHOD: &'static str = "Tracing.start";
    type Returns = crate::typed::NoReturns;
}

/// Experimental: may change without notice.
///
/// Payload of the `Tracing.bufferUsage` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BufferUsageEvent {
    /// A number in range \[0..1\] that indicates the used size of event buffer as
    /// a fraction of its total size.
    #[serde(
        rename = "percentFull",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub percent_full: Option<f64>,
    /// An approximate number of events in the trace log.
    #[serde(
        rename = "eventCount",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub event_count: Option<f64>,
    /// A number in range \[0..1\] that indicates the used size of event buffer as
    /// a fraction of its total size.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value: Option<f64>,
}

impl crate::typed::Event for BufferUsageEvent {
    const METHOD: &'static str = "Tracing.bufferUsage";
}

/// Contains a bucket of collected trace events. When tracing is stopped
/// collected events will be sent as a sequence of dataCollected events
/// followed by tracingComplete event.
///
/// Experimental: may change without notice.
///
/// Payload of the `Tracing.dataCollected` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DataCollectedEvent {
    pub value: Vec<serde_json::Value>,
}

impl crate::typed::Event for DataCollectedEvent {
    const METHOD: &'static str = "Tracing.dataCollected";
}

/// Signals that tracing is stopped and there is no trace buffers pending
/// flush, all data were delivered via dataCollected events.
///
/// Payload of the `Tracing.tracingComplete` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TracingCompleteEvent {
    /// Indicates whether some trace data is known to have been lost, e.g. because
    /// the trace ring buffer wrapped around.
    #[serde(rename = "dataLossOccurred")]
    pub data_loss_occurred: bool,
    /// A handle of the stream that holds resulting trace data.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub stream: Option<crate::protocol::io::StreamHandle>,
    /// Trace data format of returned stream.
    #[serde(
        rename = "traceFormat",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub trace_format: Option<StreamFormat>,
    /// Compression format of returned stream.
    #[serde(
        rename = "streamCompression",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub stream_compression: Option<StreamCompression>,
}

impl crate::typed::Event for TracingCompleteEvent {
    const METHOD: &'static str = "Tracing.tracingComplete";
}