webdriverbidi 0.2.2

WebDriver BiDi client implementation in Rust.
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
use serde::{Deserialize, Serialize};

use crate::model::browser::UserContext;
use crate::model::browsing_context::{BrowsingContext, Navigation};
use crate::model::common::{Extensible, JsInt, JsUint};
use crate::model::script::StackTrace;

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum NetworkCommand {
    AddDataCollector(AddDataCollector),
    AddIntercept(AddIntercept),
    ContinueRequest(ContinueRequest),
    ContinueResponse(ContinueResponse),
    ContinueWithAuth(ContinueWithAuth),
    DisownData(DisownData),
    FailRequest(FailRequest),
    GetData(GetData),
    ProvideResponse(ProvideResponse),
    RemoveDataCollector(RemoveDataCollector),
    RemoveIntercept(RemoveIntercept),
    SetCacheBehavior(SetCacheBehavior),
}

#[derive(Serialize, Deserialize, Debug)]
pub enum NetworkResult {
    AddInterceptResult(AddInterceptResult),
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum NetworkEvent {
    AuthRequired(AuthRequired),
    BeforeRequestSent(BeforeRequestSent),
    FetchError(FetchError),
    ResponseCompleted(ResponseCompleted),
    ResponseStarted(ResponseStarted),
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthChallenge {
    pub scheme: String,
    pub realm: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AuthCredentials {
    #[serde(rename = "type")]
    pub auth_credentials_type: String,
    pub username: String,
    pub password: String,
}

impl AuthCredentials {
    pub fn new(username: String, password: String) -> Self {
        Self {
            auth_credentials_type: "password".to_string(),
            username,
            password,
        }
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct BaseParameters {
    pub context: Option<BrowsingContext>,
    pub is_blocked: bool,
    pub navigation: Option<Navigation>,
    pub redirect_count: JsUint,
    pub request: RequestData,
    pub timestamp: JsUint,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub intercepts: Option<Vec<Intercept>>,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum BytesValue {
    StringValue(StringValue),
    Base64Value(Base64Value),
}

#[derive(Serialize, Deserialize, Debug)]
pub struct StringValue {
    #[serde(rename = "type")]
    pub value_type: String,
    pub value: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Base64Value {
    #[serde(rename = "type")]
    pub value_type: String,
    pub value: String,
}

pub type Collector = String;
pub type CollectorType = String;

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum SameSite {
    Strict,
    Lax,
    None,
    Default,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Cookie {
    pub name: String,
    pub value: BytesValue,
    pub domain: String,
    pub path: String,
    pub size: JsUint,
    #[serde(rename = "httpOnly")]
    pub http_only: bool,
    pub secure: bool,
    #[serde(rename = "sameSite")]
    pub same_site: SameSite,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expiry: Option<JsUint>,
    #[serde(flatten)]
    pub extensible: Extensible,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CookieHeader {
    pub name: String,
    pub value: BytesValue,
}

impl CookieHeader {
    pub fn new(name: String, value: BytesValue) -> Self {
        Self { name, value }
    }
}

pub type DataType = String;

#[derive(Serialize, Deserialize, Debug)]
pub struct FetchTimingInfo {
    #[serde(rename = "timeOrigin")]
    pub time_origin: f64,
    #[serde(rename = "requestTime")]
    pub request_time: f64,
    #[serde(rename = "redirectStart")]
    pub redirect_start: f64,
    #[serde(rename = "redirectEnd")]
    pub redirect_end: f64,
    #[serde(rename = "fetchStart")]
    pub fetch_start: f64,
    #[serde(rename = "dnsStart")]
    pub dns_start: f64,
    #[serde(rename = "dnsEnd")]
    pub dns_end: f64,
    #[serde(rename = "connectStart")]
    pub connect_start: f64,
    #[serde(rename = "connectEnd")]
    pub connect_end: f64,
    #[serde(rename = "tlsStart")]
    pub tls_start: f64,
    #[serde(rename = "requestStart")]
    pub request_start: f64,
    #[serde(rename = "responseStart")]
    pub response_start: f64,
    #[serde(rename = "responseEnd")]
    pub response_end: f64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Header {
    pub name: String,
    pub value: BytesValue,
}

impl Header {
    pub fn new(name: String, value: BytesValue) -> Self {
        Self { name, value }
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Initiator {
    #[serde(rename = "columnNumber", skip_serializing_if = "Option::is_none")]
    pub column_number: Option<JsUint>,
    #[serde(rename = "lineNumber", skip_serializing_if = "Option::is_none")]
    pub line_number: Option<JsUint>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub request: Option<Request>,
    #[serde(rename = "stackTrace", skip_serializing_if = "Option::is_none")]
    pub stack_trace: Option<StackTrace>,
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub initiator_type: Option<String>,
}

pub type Intercept = String;
pub type Request = String;

#[derive(Serialize, Deserialize, Debug)]
pub struct RequestData {
    pub request: Request,
    pub url: String,
    pub method: String,
    pub headers: Vec<Header>,
    pub cookies: Vec<Cookie>,
    #[serde(rename = "headersSize")]
    pub headers_size: JsUint,
    #[serde(rename = "bodySize")]
    pub body_size: Option<JsUint>,
    pub destination: String,
    #[serde(rename = "initiatorType")]
    pub initiator_type: Option<String>,
    pub timings: FetchTimingInfo,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseContent {
    pub size: JsUint,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseData {
    pub url: String,
    pub protocol: String,
    pub status: JsUint,
    #[serde(rename = "statusText")]
    pub status_text: String,
    #[serde(rename = "fromCache")]
    pub from_cache: bool,
    pub headers: Vec<Header>,
    #[serde(rename = "mimeType")]
    pub mime_type: String,
    #[serde(rename = "bytesReceived")]
    pub bytes_received: JsUint,
    #[serde(rename = "headersSize")]
    pub headers_size: Option<JsUint>,
    #[serde(rename = "bodySize")]
    pub body_size: Option<JsUint>,
    pub content: ResponseContent,
    #[serde(rename = "authChallenges", skip_serializing_if = "Option::is_none")]
    pub auth_challenges: Option<Vec<AuthChallenge>>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetCookieHeader {
    pub name: String,
    pub value: BytesValue,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub domain: Option<String>,
    #[serde(rename = "httpOnly", skip_serializing_if = "Option::is_none")]
    pub http_only: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expiry: Option<String>,
    #[serde(rename = "maxAge", skip_serializing_if = "Option::is_none")]
    pub max_age: Option<JsInt>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
    #[serde(rename = "sameSite", skip_serializing_if = "Option::is_none")]
    pub same_site: Option<SameSite>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub secure: Option<bool>,
}

impl SetCookieHeader {
    pub fn new(
        name: String,
        value: BytesValue,
        domain: Option<String>,
        http_only: Option<bool>,
        expiry: Option<String>,
        max_age: Option<JsInt>,
        path: Option<String>,
        same_site: Option<SameSite>,
        secure: Option<bool>,
    ) -> Self {
        Self {
            name,
            value,
            domain,
            http_only,
            expiry,
            max_age,
            path,
            same_site,
            secure,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UrlPattern {
    UrlPatternPattern(UrlPatternPattern),
    UrlPatternString(UrlPatternString),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct UrlPatternPattern {
    #[serde(rename = "type")]
    pub url_pattern_pattern_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub protocol: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hostname: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub port: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pathname: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
}

impl UrlPatternPattern {
    pub fn new(
        protocol: Option<String>,
        hostname: Option<String>,
        port: Option<String>,
        pathname: Option<String>,
        search: Option<String>,
    ) -> Self {
        Self {
            url_pattern_pattern_type: "pattern".to_string(),
            protocol,
            hostname,
            port,
            pathname,
            search,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct UrlPatternString {
    #[serde(rename = "type")]
    pub url_pattern_string_type: String,
    pub pattern: String,
}

impl UrlPatternString {
    pub fn new(pattern: String) -> Self {
        Self {
            url_pattern_string_type: "string".to_string(),
            pattern,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AddDataCollector {
    pub method: String,
    pub params: AddDataCollectorParameters,
}

impl AddDataCollector {
    pub fn new(params: AddDataCollectorParameters) -> Self {
        Self {
            method: "network.addDataCollector".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AddDataCollectorParameters {
    #[serde(rename = "dataTypes")]
    pub data_types: Vec<DataType>,
    #[serde(rename = "maxEncodedDataSize")]
    pub max_encoded_data_size: JsUint,
    #[serde(
        rename = "collectorType",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub collector_type: Option<CollectorType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contexts: Option<Vec<BrowsingContext>>,
    #[serde(rename = "userContexts", skip_serializing_if = "Option::is_none")]
    pub user_contexts: Option<Vec<UserContext>>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AddDataCollectorResult {
    pub collector: Collector,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AddIntercept {
    pub method: String,
    pub params: AddInterceptParameters,
}

impl AddIntercept {
    pub fn new(params: AddInterceptParameters) -> Self {
        Self {
            method: "network.addIntercept".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AddInterceptParameters {
    pub phases: Vec<InterceptPhase>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contexts: Option<Vec<BrowsingContext>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url_patterns: Option<Vec<UrlPattern>>,
}

impl AddInterceptParameters {
    pub fn new(
        phases: Vec<InterceptPhase>,
        contexts: Option<Vec<BrowsingContext>>,
        url_patterns: Option<Vec<UrlPattern>>,
    ) -> Self {
        Self {
            phases,
            contexts,
            url_patterns,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub enum InterceptPhase {
    #[serde(rename = "beforeRequestSent")]
    BeforeRequestSent,
    #[serde(rename = "responseStarted")]
    ResponseStarted,
    #[serde(rename = "authRequired")]
    AuthRequired,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AddInterceptResult {
    pub intercept: Intercept,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueRequest {
    pub method: String,
    pub params: ContinueRequestParameters,
}

impl ContinueRequest {
    pub fn new(params: ContinueRequestParameters) -> Self {
        Self {
            method: "network.continueRequest".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueRequestParameters {
    pub request: Request,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub body: Option<BytesValue>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cookies: Option<Vec<CookieHeader>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub headers: Option<Vec<Header>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub method: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
}

impl ContinueRequestParameters {
    pub fn new(
        request: Request,
        body: Option<BytesValue>,
        cookies: Option<Vec<CookieHeader>>,
        headers: Option<Vec<Header>>,
        method: Option<String>,
        url: Option<String>,
    ) -> Self {
        Self {
            request,
            body,
            cookies,
            headers,
            method,
            url,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueResponse {
    pub method: String,
    pub params: ContinueResponseParameters,
}

impl ContinueResponse {
    pub fn new(params: ContinueResponseParameters) -> Self {
        Self {
            method: "network.continueResponse".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueResponseParameters {
    pub request: Request,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cookies: Option<Vec<SetCookieHeader>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub credentials: Option<AuthCredentials>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub headers: Option<Vec<Header>>,
    #[serde(rename = "reasonPhrase", skip_serializing_if = "Option::is_none")]
    pub reason_phrase: Option<String>,
    #[serde(rename = "statusCode", skip_serializing_if = "Option::is_none")]
    pub status_code: Option<JsUint>,
}

impl ContinueResponseParameters {
    pub fn new(
        request: Request,
        cookies: Option<Vec<SetCookieHeader>>,
        credentials: Option<AuthCredentials>,
        headers: Option<Vec<Header>>,
        reason_phrase: Option<String>,
        status_code: Option<JsUint>,
    ) -> Self {
        Self {
            request,
            cookies,
            credentials,
            headers,
            reason_phrase,
            status_code,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueWithAuth {
    pub method: String,
    pub params: ContinueWithAuthParameters,
}

impl ContinueWithAuth {
    pub fn new(params: ContinueWithAuthParameters) -> Self {
        Self {
            method: "network.continueWithAuth".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueWithAuthParameters {
    pub request: Request,
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    pub auth_option: Option<ContinueWithAuthOption>,
}

impl ContinueWithAuthParameters {
    pub fn new(request: Request, auth_option: Option<ContinueWithAuthOption>) -> Self {
        Self {
            request,
            auth_option,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ContinueWithAuthOption {
    Credentials(ContinueWithAuthCredentials),
    NoCredentials(ContinueWithAuthNoCredentials),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueWithAuthCredentials {
    pub action: String,
    pub credentials: AuthCredentials,
}

impl ContinueWithAuthCredentials {
    pub fn new(action: String, credentials: AuthCredentials) -> Self {
        Self {
            action,
            credentials,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ContinueWithAuthNoCredentials {
    pub action: NoCredentialsAction,
}

impl ContinueWithAuthNoCredentials {
    pub fn new(action: NoCredentialsAction) -> Self {
        Self { action }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum NoCredentialsAction {
    Default,
    Cancel,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DisownData {
    pub method: String,
    pub params: DisownDataParameters,
}

impl DisownData {
    pub fn new(params: DisownDataParameters) -> Self {
        Self {
            method: "network.disownData".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DisownDataParameters {
    #[serde(rename = "dataType")]
    pub data_type: DataType,
    pub collector: Collector,
    pub request: Request,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FailRequest {
    pub method: String,
    pub params: FailRequestParameters,
}

impl FailRequest {
    pub fn new(params: FailRequestParameters) -> Self {
        Self {
            method: "network.failRequest".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct FailRequestParameters {
    pub request: Request,
}

impl FailRequestParameters {
    pub fn new(request: Request) -> Self {
        Self { request }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetData {
    pub method: String,
    pub params: GetDataParameters,
}

impl GetData {
    pub fn new(params: GetDataParameters) -> Self {
        Self {
            method: "network.getData".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetDataParameters {
    #[serde(rename = "dataType")]
    pub data_type: DataType,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collector: Option<Collector>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disown: Option<bool>,
    pub request: Request,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GetDataResult {
    pub bytes: BytesValue,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ProvideResponse {
    pub method: String,
    pub params: ProvideResponseParameters,
}

impl ProvideResponse {
    pub fn new(params: ProvideResponseParameters) -> Self {
        Self {
            method: "network.provideResponse".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ProvideResponseParameters {
    pub request: Request,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub body: Option<BytesValue>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cookies: Option<Vec<SetCookieHeader>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub headers: Option<Vec<Header>>,
    #[serde(rename = "reasonPhrase", skip_serializing_if = "Option::is_none")]
    pub reason_phrase: Option<String>,
    #[serde(rename = "statusCode", skip_serializing_if = "Option::is_none")]
    pub status_code: Option<JsUint>,
}

impl ProvideResponseParameters {
    pub fn new(
        request: Request,
        body: Option<BytesValue>,
        cookies: Option<Vec<SetCookieHeader>>,
        headers: Option<Vec<Header>>,
        reason_phrase: Option<String>,
        status_code: Option<JsUint>,
    ) -> Self {
        Self {
            request,
            body,
            cookies,
            headers,
            reason_phrase,
            status_code,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RemoveDataCollector {
    pub method: String,
    pub params: RemoveDataCollectorParameters,
}

impl RemoveDataCollector {
    pub fn new(params: RemoveDataCollectorParameters) -> Self {
        Self {
            method: "network.removeDataCollector".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RemoveDataCollectorParameters {
    pub collector: Collector,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RemoveIntercept {
    pub method: String,
    pub params: RemoveInterceptParameters,
}

impl RemoveIntercept {
    pub fn new(params: RemoveInterceptParameters) -> Self {
        Self {
            method: "network.removeIntercept".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RemoveInterceptParameters {
    pub intercept: Intercept,
}

impl RemoveInterceptParameters {
    pub fn new(intercept: Intercept) -> Self {
        Self { intercept }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetCacheBehavior {
    pub method: String,
    pub params: SetCacheBehaviorParameters,
}

impl SetCacheBehavior {
    pub fn new(params: SetCacheBehaviorParameters) -> Self {
        Self {
            method: "network.setCacheBehavior".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetCacheBehaviorParameters {
    pub cache_behavior: CacheBehavior,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contexts: Option<Vec<BrowsingContext>>,
}

impl SetCacheBehaviorParameters {
    pub fn new(cache_behavior: CacheBehavior, contexts: Option<Vec<BrowsingContext>>) -> Self {
        Self {
            cache_behavior,
            contexts,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CacheBehavior {
    Default,
    Bypass,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct AuthRequired {
    pub method: String,
    pub params: AuthRequiredParameters,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AuthRequiredParameters {
    #[serde(flatten)]
    pub base: BaseParameters,
    pub response: ResponseData,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct BeforeRequestSent {
    pub method: String,
    pub params: BeforeRequestSentParameters,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct BeforeRequestSentParameters {
    #[serde(flatten)]
    pub base: BaseParameters,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initiator: Option<Initiator>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct FetchError {
    pub method: String,
    pub params: FetchErrorParameters,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct FetchErrorParameters {
    #[serde(flatten)]
    pub base: BaseParameters,
    #[serde(rename = "errorText")]
    pub error_text: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseCompleted {
    pub method: String,
    pub params: ResponseCompletedParameters,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseCompletedParameters {
    #[serde(flatten)]
    pub base: BaseParameters,
    pub response: ResponseData,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseStarted {
    pub method: String,
    pub params: ResponseStartedParameters,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ResponseStartedParameters {
    #[serde(flatten)]
    pub base: BaseParameters,
    pub response: ResponseData,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetExtraHeaders {
    pub method: String,
    pub params: SetExtraHeadersParameters,
}

impl SetExtraHeaders {
    pub fn new(params: SetExtraHeadersParameters) -> Self {
        Self {
            method: "network.setExtraHeaders".to_string(),
            params,
        }
    }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SetExtraHeadersParameters {
    pub headers: Vec<Header>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contexts: Option<Vec<BrowsingContext>>,
    #[serde(rename = "userContexts", skip_serializing_if = "Option::is_none")]
    pub user_contexts: Option<Vec<UserContext>>,
}