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

//! A domain for letting clients substitute browser's network layer with
//! client code.
//!
//! Types, command parameters and event payloads for the `Fetch`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].

use serde::{Deserialize, Serialize};

/// Unique request identifier. Note that this does not identify individual
/// HTTP requests that are part of a network request.
pub type RequestId = String;

/// Stages of the request to handle. Request will intercept before the request
/// is sent. Response will intercept after the response is received (but
/// before response body is received).
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum RequestStage {
    /// `Request`
    Request,
    /// `Response`
    Response,
    /// 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, Default, PartialEq, Serialize, Deserialize)]
pub struct RequestPattern {
    /// Wildcards (`'*'` -\> zero or more, `'?'` -\> exactly one) are allowed.
    /// Escape character is backslash. Omitting is equivalent to `"*"`.
    #[serde(
        rename = "urlPattern",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub url_pattern: Option<String>,
    /// If set, only requests for matching resource types will be intercepted.
    #[serde(
        rename = "resourceType",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub resource_type: Option<crate::protocol::network::ResourceType>,
    /// Stage at which to begin intercepting requests. Default is Request.
    #[serde(
        rename = "requestStage",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub request_stage: Option<RequestStage>,
}

/// Response HTTP header entry
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct HeaderEntry {
    pub name: String,
    pub value: String,
}

/// Authorization challenge for HTTP status code 401 or 407.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AuthChallenge {
    /// Source of the authentication challenge.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub source: Option<AuthChallengeSource>,
    /// Origin of the challenger.
    pub origin: String,
    /// The authentication scheme used, such as basic or digest
    pub scheme: String,
    /// The realm of the challenge. May be empty.
    pub realm: String,
}

/// The values `source` accepts on `AuthChallenge`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AuthChallengeSource {
    /// `Server`
    Server,
    /// `Proxy`
    Proxy,
    /// 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),
}

/// Response to an AuthChallenge.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AuthChallengeResponse {
    /// The decision on what to do in response to the authorization challenge.
    /// Default means deferring to the default behavior of the net stack, which
    /// will likely either the Cancel authentication or display a popup dialog
    /// box.
    pub response: AuthChallengeResponseResponse,
    /// The username to provide, possibly empty. Should only be set if response is
    /// ProvideCredentials.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,
    /// The password to provide, possibly empty. Should only be set if response is
    /// ProvideCredentials.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub password: Option<String>,
}

/// The values `response` accepts on `AuthChallengeResponse`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AuthChallengeResponseResponse {
    /// `Default`
    Default,
    /// `CancelAuth`
    CancelAuth,
    /// `ProvideCredentials`
    ProvideCredentials,
    /// 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),
}

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

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

/// Enables issuing of requestPaused events. A request will be paused until
/// client calls one of failRequest, fulfillRequest or
/// continueRequest/continueWithAuth.
///
/// Parameters of `Fetch.enable`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EnableParams {
    /// If specified, only requests matching any of these patterns will produce
    /// fetchRequested event and will be paused until clients response. If not
    /// set, all requests will be affected.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub patterns: Option<Vec<RequestPattern>>,
    /// If true, authRequired events will be issued and requests will be paused
    /// expecting a call to continueWithAuth.
    #[serde(
        rename = "handleAuthRequests",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub handle_auth_requests: Option<bool>,
}

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

/// Causes the request to fail with specified reason.
///
/// Parameters of `Fetch.failRequest`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FailRequestParams {
    /// An id the client received in requestPaused event.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// Causes the request to fail with the given reason.
    #[serde(rename = "errorReason")]
    pub error_reason: crate::protocol::network::ErrorReason,
}

impl crate::typed::Command for FailRequestParams {
    const METHOD: &'static str = "Fetch.failRequest";
    type Returns = crate::typed::NoReturns;
}

/// Provides response to the request.
///
/// Parameters of `Fetch.fulfillRequest`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct FulfillRequestParams {
    /// An id the client received in requestPaused event.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// An HTTP response code.
    #[serde(rename = "responseCode")]
    pub response_code: i64,
    /// Response headers.
    #[serde(
        rename = "responseHeaders",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_headers: Option<Vec<HeaderEntry>>,
    /// Alternative way of specifying response headers as a \0-separated series of
    /// name: value pairs. Prefer the above method unless you need to represent
    /// some non-UTF8 values that can't be transmitted over the protocol as text.
    /// (Encoded as a base64 string when passed over JSON)
    #[serde(
        rename = "binaryResponseHeaders",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub binary_response_headers: Option<String>,
    /// A response body. If absent, original response body will be used if the
    /// request is intercepted at the response stage and empty body will be used
    /// if the request is intercepted at the request stage. (Encoded as a base64
    /// string when passed over JSON)
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub body: Option<String>,
    /// A textual representation of responseCode. If absent, a standard phrase
    /// matching responseCode is used.
    #[serde(
        rename = "responsePhrase",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_phrase: Option<String>,
}

impl crate::typed::Command for FulfillRequestParams {
    const METHOD: &'static str = "Fetch.fulfillRequest";
    type Returns = crate::typed::NoReturns;
}

/// Continues the request, optionally modifying some of its parameters.
///
/// Parameters of `Fetch.continueRequest`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ContinueRequestParams {
    /// An id the client received in requestPaused event.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// If set, the request url will be modified in a way that's not observable by
    /// page.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// If set, the request method is overridden.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub method: Option<String>,
    /// If set, overrides the post data in the request. (Encoded as a base64
    /// string when passed over JSON)
    #[serde(rename = "postData", default, skip_serializing_if = "Option::is_none")]
    pub post_data: Option<String>,
    /// If set, overrides the request headers. Note that the overrides do not
    /// extend to subsequent redirect hops, if a redirect happens. Another
    /// override may be applied to a different request produced by a redirect.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub headers: Option<Vec<HeaderEntry>>,
    /// If set, overrides response interception behavior for this request.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "interceptResponse",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub intercept_response: Option<bool>,
}

impl crate::typed::Command for ContinueRequestParams {
    const METHOD: &'static str = "Fetch.continueRequest";
    type Returns = crate::typed::NoReturns;
}

/// Continues a request supplying authChallengeResponse following authRequired
/// event.
///
/// Parameters of `Fetch.continueWithAuth`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ContinueWithAuthParams {
    /// An id the client received in authRequired event.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// Response to with an authChallenge.
    #[serde(rename = "authChallengeResponse")]
    pub auth_challenge_response: AuthChallengeResponse,
}

impl crate::typed::Command for ContinueWithAuthParams {
    const METHOD: &'static str = "Fetch.continueWithAuth";
    type Returns = crate::typed::NoReturns;
}

/// Continues loading of the paused response, optionally modifying the
/// response headers. If either responseCode or headers are modified, all of
/// them must be present.
///
/// Experimental: may change without notice.
///
/// Parameters of `Fetch.continueResponse`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ContinueResponseParams {
    /// An id the client received in requestPaused event.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// An HTTP response code. If absent, original response code will be used.
    #[serde(
        rename = "responseCode",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_code: Option<i64>,
    /// A textual representation of responseCode. If absent, a standard phrase
    /// matching responseCode is used.
    #[serde(
        rename = "responsePhrase",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_phrase: Option<String>,
    /// Response headers. If absent, original response headers will be used.
    #[serde(
        rename = "responseHeaders",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_headers: Option<Vec<HeaderEntry>>,
    /// Alternative way of specifying response headers as a \0-separated series of
    /// name: value pairs. Prefer the above method unless you need to represent
    /// some non-UTF8 values that can't be transmitted over the protocol as text.
    /// (Encoded as a base64 string when passed over JSON)
    #[serde(
        rename = "binaryResponseHeaders",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub binary_response_headers: Option<String>,
}

impl crate::typed::Command for ContinueResponseParams {
    const METHOD: &'static str = "Fetch.continueResponse";
    type Returns = crate::typed::NoReturns;
}

/// Causes the body of the response to be received from the server and
/// returned as a single string. May only be issued for a request that is
/// paused in the Response stage and is mutually exclusive with
/// takeResponseBodyForInterceptionAsStream. Calling other methods that affect
/// the request or disabling fetch domain before body is received results in
/// an undefined behavior. Note that the response body is not available for
/// redirects. Requests paused in the _redirect received_ state may be
/// differentiated by `responseCode` and presence of `location` response
/// header, see comments to `requestPaused` for details.
///
/// Parameters of `Fetch.getResponseBody`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetResponseBodyParams {
    /// Identifier for the intercepted request to get body for.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
}

/// What `Fetch.getResponseBody` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetResponseBodyReturns {
    /// Response body.
    pub body: String,
    /// True, if content was sent as base64.
    #[serde(rename = "base64Encoded")]
    pub base64_encoded: bool,
}

impl crate::typed::Command for GetResponseBodyParams {
    const METHOD: &'static str = "Fetch.getResponseBody";
    type Returns = GetResponseBodyReturns;
}

/// Returns a handle to the stream representing the response body. The request
/// must be paused in the HeadersReceived stage. Note that after this command
/// the request can't be continued as is -- client either needs to cancel it
/// or to provide the response body. The stream only supports sequential read,
/// IO.read will fail if the position is specified. This method is mutually
/// exclusive with getResponseBody. Calling other methods that affect the
/// request or disabling fetch domain before body is received results in an
/// undefined behavior.
///
/// Parameters of `Fetch.takeResponseBodyAsStream`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TakeResponseBodyAsStreamParams {
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
}

/// What `Fetch.takeResponseBodyAsStream` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TakeResponseBodyAsStreamReturns {
    pub stream: crate::protocol::io::StreamHandle,
}

impl crate::typed::Command for TakeResponseBodyAsStreamParams {
    const METHOD: &'static str = "Fetch.takeResponseBodyAsStream";
    type Returns = TakeResponseBodyAsStreamReturns;
}

/// Issued when the domain is enabled and the request URL matches the
/// specified filter. The request is paused until the client responds with one
/// of continueRequest, failRequest or fulfillRequest. The stage of the
/// request can be determined by presence of responseErrorReason and
/// responseStatusCode -- the request is at the response stage if either of
/// these fields is present and in the request stage otherwise. Redirect
/// responses and subsequent requests are reported similarly to regular
/// responses and requests. Redirect responses may be distinguished by the
/// value of `responseStatusCode` (which is one of 301, 302, 303, 307, 308)
/// along with presence of the `location` header. Requests resulting from a
/// redirect will have `redirectedRequestId` field set.
///
/// Payload of the `Fetch.requestPaused` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RequestPausedEvent {
    /// Each request the page makes will have a unique id.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// The details of the request.
    pub request: crate::protocol::network::Request,
    /// The id of the frame that initiated the request.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// How the requested resource will be used.
    #[serde(rename = "resourceType")]
    pub resource_type: crate::protocol::network::ResourceType,
    /// Response error if intercepted at response stage.
    #[serde(
        rename = "responseErrorReason",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_error_reason: Option<crate::protocol::network::ErrorReason>,
    /// Response code if intercepted at response stage.
    #[serde(
        rename = "responseStatusCode",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_status_code: Option<i64>,
    /// Response status text if intercepted at response stage.
    #[serde(
        rename = "responseStatusText",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_status_text: Option<String>,
    /// Response headers if intercepted at the response stage.
    #[serde(
        rename = "responseHeaders",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub response_headers: Option<Vec<HeaderEntry>>,
    /// If the intercepted request had a corresponding Network.requestWillBeSent
    /// event fired for it, then this networkId will be the same as the requestId
    /// present in the requestWillBeSent event.
    #[serde(rename = "networkId", default, skip_serializing_if = "Option::is_none")]
    pub network_id: Option<crate::protocol::network::RequestId>,
    /// If the request is due to a redirect response from the server, the id of
    /// the request that has caused the redirect.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "redirectedRequestId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub redirected_request_id: Option<RequestId>,
}

impl crate::typed::Event for RequestPausedEvent {
    const METHOD: &'static str = "Fetch.requestPaused";
}

/// Issued when the domain is enabled with handleAuthRequests set to true. The
/// request is paused until client responds with continueWithAuth.
///
/// Payload of the `Fetch.authRequired` event.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AuthRequiredEvent {
    /// Each request the page makes will have a unique id.
    #[serde(rename = "requestId")]
    pub request_id: RequestId,
    /// The details of the request.
    pub request: crate::protocol::network::Request,
    /// The id of the frame that initiated the request.
    #[serde(rename = "frameId")]
    pub frame_id: crate::protocol::page::FrameId,
    /// How the requested resource will be used.
    #[serde(rename = "resourceType")]
    pub resource_type: crate::protocol::network::ResourceType,
    /// Details of the Authorization Challenge encountered. If this is set, client
    /// should respond with continueRequest that contains AuthChallengeResponse.
    #[serde(rename = "authChallenge")]
    pub auth_challenge: AuthChallenge,
}

impl crate::typed::Event for AuthRequiredEvent {
    const METHOD: &'static str = "Fetch.authRequired";
}