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
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! The `ServiceWorker` domain.
//!
//! Types, command parameters and event payloads for the `ServiceWorker`
//! 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};

pub type RegistrationId = String;

/// ServiceWorker registration.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerRegistration {
    #[serde(rename = "registrationId")]
    pub registration_id: RegistrationId,
    #[serde(rename = "scopeURL")]
    pub scope_url: String,
    #[serde(rename = "isDeleted")]
    pub is_deleted: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ServiceWorkerVersionRunningStatus {
    /// `stopped`
    #[serde(rename = "stopped")]
    Stopped,
    /// `starting`
    #[serde(rename = "starting")]
    Starting,
    /// `running`
    #[serde(rename = "running")]
    Running,
    /// `stopping`
    #[serde(rename = "stopping")]
    Stopping,
    /// 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),
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ServiceWorkerVersionStatus {
    /// `new`
    #[serde(rename = "new")]
    New,
    /// `installing`
    #[serde(rename = "installing")]
    Installing,
    /// `installed`
    #[serde(rename = "installed")]
    Installed,
    /// `activating`
    #[serde(rename = "activating")]
    Activating,
    /// `activated`
    #[serde(rename = "activated")]
    Activated,
    /// `redundant`
    #[serde(rename = "redundant")]
    Redundant,
    /// 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),
}

/// Mostly corresponds to `RouterCondition` in ServiceWorker spec
/// (<https://www.w3.org/TR/service-workers/#dictdef-routercondition>)
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerRouterCondition {
    /// Plain text, or JSON serialization of URLPatternInit or URLPattern
    #[serde(
        rename = "urlPattern",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub url_pattern: Option<String>,
    #[serde(
        rename = "requestMethod",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub request_method: Option<String>,
    #[serde(
        rename = "requestMode",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub request_mode: Option<String>,
    #[serde(
        rename = "requestDestination",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub request_destination: Option<String>,
    #[serde(
        rename = "runningStatus",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub running_status: Option<ServiceWorkerVersionRunningStatus>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub or: Option<Vec<ServiceWorkerRouterCondition>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub not: Option<Box<ServiceWorkerRouterCondition>>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ServiceWorkerRouterSourceType {
    /// `cache`
    #[serde(rename = "cache")]
    Cache,
    /// `fetchEvent`
    #[serde(rename = "fetchEvent")]
    FetchEvent,
    /// `network`
    #[serde(rename = "network")]
    Network,
    /// `raceNetworkAndFetchHandler`
    #[serde(rename = "raceNetworkAndFetchHandler")]
    RaceNetworkAndFetchHandler,
    /// `raceNetworkAndCache`
    #[serde(rename = "raceNetworkAndCache")]
    RaceNetworkAndCache,
    /// `sourceDict`
    #[serde(rename = "sourceDict")]
    SourceDict,
    /// 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),
}

/// <https://www.w3.org/TR/service-workers/#dictdef-routersourcedict>
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerRouterSourceDict {
    #[serde(rename = "cacheName")]
    pub cache_name: String,
}

/// Corresponds to `RouterSource` in the spec while the representation is
/// different as follows.
/// (<https://www.w3.org/TR/service-workers/#typedefdef-routersource>) -
/// `RouterSourceEnum`: `type` equals `cache`, `sourceDict` is null. -
/// `RouterSourceDict`: `type` equals `sourceDict`, `sourceDict` has valid
/// value.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerRouterSource {
    pub r#type: ServiceWorkerRouterSourceType,
    /// Non-empty iff `type` equals "sourceDict".
    #[serde(
        rename = "sourceDict",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub source_dict: Option<ServiceWorkerRouterSourceDict>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerRouterRule {
    pub condition: ServiceWorkerRouterCondition,
    pub source: ServiceWorkerRouterSource,
    /// Rule ID assigned by the browser. Unique within each ServiceWorkerVersion.
    pub id: i64,
}

/// ServiceWorker version.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerVersion {
    #[serde(rename = "versionId")]
    pub version_id: String,
    #[serde(rename = "registrationId")]
    pub registration_id: RegistrationId,
    #[serde(rename = "scriptURL")]
    pub script_url: String,
    #[serde(rename = "runningStatus")]
    pub running_status: ServiceWorkerVersionRunningStatus,
    pub status: ServiceWorkerVersionStatus,
    /// The Last-Modified header value of the main script.
    #[serde(
        rename = "scriptLastModified",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub script_last_modified: Option<f64>,
    /// The time at which the response headers of the main script were received
    /// from the server. For cached script it is the last time the cache entry was
    /// validated.
    #[serde(
        rename = "scriptResponseTime",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub script_response_time: Option<f64>,
    #[serde(
        rename = "controlledClients",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub controlled_clients: Option<Vec<crate::protocol::target::TargetId>>,
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<crate::protocol::target::TargetId>,
    /// Migration to `typedRouterRules` is in progress. The browser sends either
    /// `routerRules` or `typedRouterRules`. TODO(crbug.com/540469610): Remove
    /// `routerRules` after the migration.
    #[serde(
        rename = "routerRules",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub router_rules: Option<String>,
    #[serde(
        rename = "typedRouterRules",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub typed_router_rules: Option<Vec<ServiceWorkerRouterRule>>,
}

/// ServiceWorker error message.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ServiceWorkerErrorMessage {
    #[serde(rename = "errorMessage")]
    pub error_message: String,
    #[serde(rename = "registrationId")]
    pub registration_id: RegistrationId,
    #[serde(rename = "versionId")]
    pub version_id: String,
    #[serde(rename = "sourceURL")]
    pub source_url: String,
    #[serde(rename = "lineNumber")]
    pub line_number: i64,
    #[serde(rename = "columnNumber")]
    pub column_number: i64,
}

/// Parameters of `ServiceWorker.deliverPushMessage`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DeliverPushMessageParams {
    pub origin: String,
    #[serde(rename = "registrationId")]
    pub registration_id: RegistrationId,
    pub data: String,
}

impl crate::typed::Command for DeliverPushMessageParams {
    const METHOD: &'static str = "ServiceWorker.deliverPushMessage";
    type Returns = crate::typed::NoReturns;
}

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

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

/// Parameters of `ServiceWorker.dispatchSyncEvent`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DispatchSyncEventParams {
    pub origin: String,
    #[serde(rename = "registrationId")]
    pub registration_id: RegistrationId,
    pub tag: String,
    #[serde(rename = "lastChance")]
    pub last_chance: bool,
}

impl crate::typed::Command for DispatchSyncEventParams {
    const METHOD: &'static str = "ServiceWorker.dispatchSyncEvent";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.dispatchPeriodicSyncEvent`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DispatchPeriodicSyncEventParams {
    pub origin: String,
    #[serde(rename = "registrationId")]
    pub registration_id: RegistrationId,
    pub tag: String,
}

impl crate::typed::Command for DispatchPeriodicSyncEventParams {
    const METHOD: &'static str = "ServiceWorker.dispatchPeriodicSyncEvent";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {}

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

/// Parameters of `ServiceWorker.setForceUpdateOnPageLoad`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetForceUpdateOnPageLoadParams {
    #[serde(rename = "forceUpdateOnPageLoad")]
    pub force_update_on_page_load: bool,
}

impl crate::typed::Command for SetForceUpdateOnPageLoadParams {
    const METHOD: &'static str = "ServiceWorker.setForceUpdateOnPageLoad";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.skipWaiting`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SkipWaitingParams {
    #[serde(rename = "scopeURL")]
    pub scope_url: String,
}

impl crate::typed::Command for SkipWaitingParams {
    const METHOD: &'static str = "ServiceWorker.skipWaiting";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.startWorker`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StartWorkerParams {
    #[serde(rename = "scopeURL")]
    pub scope_url: String,
}

impl crate::typed::Command for StartWorkerParams {
    const METHOD: &'static str = "ServiceWorker.startWorker";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.stopAllWorkers`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopAllWorkersParams {}

impl crate::typed::Command for StopAllWorkersParams {
    const METHOD: &'static str = "ServiceWorker.stopAllWorkers";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.stopWorker`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StopWorkerParams {
    #[serde(rename = "versionId")]
    pub version_id: String,
}

impl crate::typed::Command for StopWorkerParams {
    const METHOD: &'static str = "ServiceWorker.stopWorker";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.unregister`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct UnregisterParams {
    #[serde(rename = "scopeURL")]
    pub scope_url: String,
}

impl crate::typed::Command for UnregisterParams {
    const METHOD: &'static str = "ServiceWorker.unregister";
    type Returns = crate::typed::NoReturns;
}

/// Parameters of `ServiceWorker.updateRegistration`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct UpdateRegistrationParams {
    #[serde(rename = "scopeURL")]
    pub scope_url: String,
}

impl crate::typed::Command for UpdateRegistrationParams {
    const METHOD: &'static str = "ServiceWorker.updateRegistration";
    type Returns = crate::typed::NoReturns;
}

/// Payload of the `ServiceWorker.workerErrorReported` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct WorkerErrorReportedEvent {
    #[serde(rename = "errorMessage")]
    pub error_message: ServiceWorkerErrorMessage,
}

impl crate::typed::Event for WorkerErrorReportedEvent {
    const METHOD: &'static str = "ServiceWorker.workerErrorReported";
}

/// Payload of the `ServiceWorker.workerRegistrationUpdated` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct WorkerRegistrationUpdatedEvent {
    pub registrations: Vec<ServiceWorkerRegistration>,
}

impl crate::typed::Event for WorkerRegistrationUpdatedEvent {
    const METHOD: &'static str = "ServiceWorker.workerRegistrationUpdated";
}

/// Payload of the `ServiceWorker.workerVersionUpdated` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct WorkerVersionUpdatedEvent {
    pub versions: Vec<ServiceWorkerVersion>,
}

impl crate::typed::Event for WorkerVersionUpdatedEvent {
    const METHOD: &'static str = "ServiceWorker.workerVersionUpdated";
}