browser-commander 0.17.0

Universal browser automation library that supports multiple browser engines with a unified API
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
// @generated by scripts/generate-playwright-protocol.mjs from
// rust/protocol/playwright/*.yml. Do not edit by hand.

#![allow(clippy::all, missing_docs, unused_imports)]

use serde::{Deserialize, Serialize};

use super::*;
use crate::playwright::connection::{
    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextInitializerOptions {
    /// Properties of the `ContextOptions` mixin.
    #[serde(flatten)]
    pub context_options: ContextOptions,
}

/// Initializer the driver sends when it creates a `BrowserContext`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextInitializer {
    #[serde(rename = "debugger")]
    pub debugger: Ref<Debugger>,
    #[serde(rename = "requestContext")]
    pub request_context: Ref<APIRequestContext>,
    #[serde(rename = "tracing")]
    pub tracing: Ref<Tracing>,
    #[serde(rename = "options")]
    pub options: BrowserContextInitializerOptions,
}

/// Parameters of `BrowserContext.addCookies` (Add cookies).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextAddCookiesParams {
    #[serde(rename = "cookies")]
    pub cookies: Vec<SetNetworkCookie>,
}

/// Parameters of `BrowserContext.addInitScript` (Add init script).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextAddInitScriptParams {
    #[serde(rename = "source")]
    pub source: String,
}

/// Result of `BrowserContext.addInitScript` (Add init script).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextAddInitScriptResult {
    #[serde(rename = "disposable")]
    pub disposable: Ref<Disposable>,
}

/// Parameters of `BrowserContext.clearCookies` (Clear cookies).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClearCookiesParams {
    #[serde(rename = "name", default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(rename = "nameRegexSource", default, skip_serializing_if = "Option::is_none")]
    pub name_regex_source: Option<String>,
    #[serde(rename = "nameRegexFlags", default, skip_serializing_if = "Option::is_none")]
    pub name_regex_flags: Option<String>,
    #[serde(rename = "domain", default, skip_serializing_if = "Option::is_none")]
    pub domain: Option<String>,
    #[serde(rename = "domainRegexSource", default, skip_serializing_if = "Option::is_none")]
    pub domain_regex_source: Option<String>,
    #[serde(rename = "domainRegexFlags", default, skip_serializing_if = "Option::is_none")]
    pub domain_regex_flags: Option<String>,
    #[serde(rename = "path", default, skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
    #[serde(rename = "pathRegexSource", default, skip_serializing_if = "Option::is_none")]
    pub path_regex_source: Option<String>,
    #[serde(rename = "pathRegexFlags", default, skip_serializing_if = "Option::is_none")]
    pub path_regex_flags: Option<String>,
}

/// Parameters of `BrowserContext.close` (Close context).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCloseParams {
    #[serde(rename = "reason", default, skip_serializing_if = "Option::is_none")]
    pub reason: Option<String>,
}

/// Parameters of `BrowserContext.cookies` (Get cookies).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCookiesParams {
    #[serde(rename = "urls")]
    pub urls: Vec<String>,
}

/// Result of `BrowserContext.cookies` (Get cookies).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCookiesResult {
    #[serde(rename = "cookies")]
    pub cookies: Vec<NetworkCookie>,
}

/// Parameters of `BrowserContext.exposeBinding` (Expose binding).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextExposeBindingParams {
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "noGlobal", default, skip_serializing_if = "Option::is_none")]
    pub no_global: Option<bool>,
}

/// Result of `BrowserContext.exposeBinding` (Expose binding).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextExposeBindingResult {
    #[serde(rename = "disposable")]
    pub disposable: Ref<Disposable>,
}

/// Parameters of `BrowserContext.grantPermissions` (Grant permissions).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextGrantPermissionsParams {
    #[serde(rename = "permissions")]
    pub permissions: Vec<String>,
    #[serde(rename = "origin", default, skip_serializing_if = "Option::is_none")]
    pub origin: Option<String>,
}

/// Result of `BrowserContext.newPage` (Create page).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextNewPageResult {
    #[serde(rename = "page")]
    pub page: Ref<Page>,
}

/// Parameters of `BrowserContext.registerSelectorEngine`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextRegisterSelectorEngineParams {
    #[serde(rename = "selectorEngine")]
    pub selector_engine: SelectorEngine,
}

/// Parameters of `BrowserContext.setTestIdAttributeName`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetTestIdAttributeNameParams {
    #[serde(rename = "testIdAttributeName")]
    pub test_id_attribute_name: String,
}

/// Parameters of `BrowserContext.setExtraHTTPHeaders` (Set extra HTTP headers).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetExtraHTTPHeadersParams {
    #[serde(rename = "headers")]
    pub headers: Vec<NameValue>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetGeolocationParamsGeolocation {
    #[serde(rename = "longitude")]
    pub longitude: f64,
    #[serde(rename = "latitude")]
    pub latitude: f64,
    #[serde(rename = "accuracy", default, skip_serializing_if = "Option::is_none")]
    pub accuracy: Option<f64>,
}

/// Parameters of `BrowserContext.setGeolocation` (Set geolocation).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetGeolocationParams {
    #[serde(rename = "geolocation", default, skip_serializing_if = "Option::is_none")]
    pub geolocation: Option<BrowserContextSetGeolocationParamsGeolocation>,
}

/// Parameters of `BrowserContext.setHTTPCredentials` (Set HTTP credentials).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetHTTPCredentialsParams {
    #[serde(rename = "httpCredentials", default, skip_serializing_if = "Option::is_none")]
    pub http_credentials: Option<Vec<HttpCredentials>>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetNetworkInterceptionPatternsParamsPatterns {
    #[serde(rename = "glob", default, skip_serializing_if = "Option::is_none")]
    pub glob: Option<String>,
    #[serde(rename = "regexSource", default, skip_serializing_if = "Option::is_none")]
    pub regex_source: Option<String>,
    #[serde(rename = "regexFlags", default, skip_serializing_if = "Option::is_none")]
    pub regex_flags: Option<String>,
    #[serde(rename = "urlPattern", default, skip_serializing_if = "Option::is_none")]
    pub url_pattern: Option<URLPattern>,
}

/// Parameters of `BrowserContext.setNetworkInterceptionPatterns` (Route requests).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetNetworkInterceptionPatternsParams {
    #[serde(rename = "patterns")]
    pub patterns: Vec<BrowserContextSetNetworkInterceptionPatternsParamsPatterns>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetWebSocketInterceptionPatternsParamsPatterns {
    #[serde(rename = "glob", default, skip_serializing_if = "Option::is_none")]
    pub glob: Option<String>,
    #[serde(rename = "regexSource", default, skip_serializing_if = "Option::is_none")]
    pub regex_source: Option<String>,
    #[serde(rename = "regexFlags", default, skip_serializing_if = "Option::is_none")]
    pub regex_flags: Option<String>,
    #[serde(rename = "urlPattern", default, skip_serializing_if = "Option::is_none")]
    pub url_pattern: Option<URLPattern>,
}

/// Parameters of `BrowserContext.setWebSocketInterceptionPatterns` (Route WebSockets).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetWebSocketInterceptionPatternsParams {
    #[serde(rename = "patterns")]
    pub patterns: Vec<BrowserContextSetWebSocketInterceptionPatternsParamsPatterns>,
}

/// Parameters of `BrowserContext.setOffline` (Set offline mode).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetOfflineParams {
    #[serde(rename = "offline")]
    pub offline: bool,
}

/// Parameters of `BrowserContext.storageState` (Get storage state).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextStorageStateParams {
    #[serde(rename = "indexedDB", default, skip_serializing_if = "Option::is_none")]
    pub indexed_db: Option<bool>,
    #[serde(rename = "opfs", default, skip_serializing_if = "Option::is_none")]
    pub opfs: Option<bool>,
    #[serde(rename = "credentials", default, skip_serializing_if = "Option::is_none")]
    pub credentials: Option<bool>,
}

/// Result of `BrowserContext.storageState` (Get storage state).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextStorageStateResult {
    #[serde(rename = "cookies")]
    pub cookies: Vec<NetworkCookie>,
    #[serde(rename = "origins")]
    pub origins: Vec<OriginStorage>,
    #[serde(rename = "credentials", default, skip_serializing_if = "Option::is_none")]
    pub credentials: Option<Vec<VirtualCredential>>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetStorageStateParamsStorageState {
    #[serde(rename = "cookies", default, skip_serializing_if = "Option::is_none")]
    pub cookies: Option<Vec<SetNetworkCookie>>,
    #[serde(rename = "origins", default, skip_serializing_if = "Option::is_none")]
    pub origins: Option<Vec<SetOriginStorage>>,
    #[serde(rename = "credentials", default, skip_serializing_if = "Option::is_none")]
    pub credentials: Option<Vec<VirtualCredential>>,
}

/// Parameters of `BrowserContext.setStorageState` (Set storage state).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextSetStorageStateParams {
    #[serde(rename = "storageState", default, skip_serializing_if = "Option::is_none")]
    pub storage_state: Option<BrowserContextSetStorageStateParamsStorageState>,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BrowserContextEnableRecorderParamsMode {
    #[default]
    #[serde(rename = "inspecting")]
    Inspecting,
    #[serde(rename = "recording")]
    Recording,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BrowserContextEnableRecorderParamsRecorderMode {
    #[default]
    #[serde(rename = "default")]
    Default,
    #[serde(rename = "api")]
    Api,
}

/// Parameters of `BrowserContext.enableRecorder`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextEnableRecorderParams {
    #[serde(rename = "language", default, skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
    #[serde(rename = "mode", default, skip_serializing_if = "Option::is_none")]
    pub mode: Option<BrowserContextEnableRecorderParamsMode>,
    #[serde(rename = "recorderMode", default, skip_serializing_if = "Option::is_none")]
    pub recorder_mode: Option<BrowserContextEnableRecorderParamsRecorderMode>,
    #[serde(rename = "pauseOnNextStatement", default, skip_serializing_if = "Option::is_none")]
    pub pause_on_next_statement: Option<bool>,
    #[serde(rename = "testIdAttributeName", default, skip_serializing_if = "Option::is_none")]
    pub test_id_attribute_name: Option<String>,
    #[serde(rename = "launchOptions", default, skip_serializing_if = "Option::is_none")]
    pub launch_options: Option<serde_json::Value>,
    #[serde(rename = "contextOptions", default, skip_serializing_if = "Option::is_none")]
    pub context_options: Option<serde_json::Value>,
    #[serde(rename = "device", default, skip_serializing_if = "Option::is_none")]
    pub device: Option<String>,
    #[serde(rename = "saveStorage", default, skip_serializing_if = "Option::is_none")]
    pub save_storage: Option<String>,
    #[serde(rename = "outputFile", default, skip_serializing_if = "Option::is_none")]
    pub output_file: Option<String>,
    #[serde(rename = "handleSIGINT", default, skip_serializing_if = "Option::is_none")]
    pub handle_sigint: Option<bool>,
    #[serde(rename = "omitCallTracking", default, skip_serializing_if = "Option::is_none")]
    pub omit_call_tracking: Option<bool>,
}

/// Parameters of `BrowserContext.newCDPSession` (Create CDP session).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextNewCDPSessionParams {
    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
    pub page: Option<Ref<Page>>,
    #[serde(rename = "frame", default, skip_serializing_if = "Option::is_none")]
    pub frame: Option<Ref<Frame>>,
}

/// Result of `BrowserContext.newCDPSession` (Create CDP session).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextNewCDPSessionResult {
    #[serde(rename = "session")]
    pub session: Ref<CDPSession>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCreateTempFilesParamsItems {
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "lastModifiedMs", default, skip_serializing_if = "Option::is_none")]
    pub last_modified_ms: Option<f64>,
}

/// Parameters of `BrowserContext.createTempFiles`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCreateTempFilesParams {
    #[serde(rename = "rootDirName", default, skip_serializing_if = "Option::is_none")]
    pub root_dir_name: Option<String>,
    #[serde(rename = "items")]
    pub items: Vec<BrowserContextCreateTempFilesParamsItems>,
}

/// Result of `BrowserContext.createTempFiles`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCreateTempFilesResult {
    #[serde(rename = "rootDir", default, skip_serializing_if = "Option::is_none")]
    pub root_dir: Option<Ref<WritableStream>>,
    #[serde(rename = "writableStreams")]
    pub writable_streams: Vec<Ref<WritableStream>>,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BrowserContextUpdateSubscriptionParamsEvent {
    #[default]
    #[serde(rename = "console")]
    Console,
    #[serde(rename = "dialog")]
    Dialog,
    #[serde(rename = "dialogClosed")]
    DialogClosed,
    #[serde(rename = "request")]
    Request,
    #[serde(rename = "response")]
    Response,
    #[serde(rename = "requestFinished")]
    RequestFinished,
    #[serde(rename = "requestFailed")]
    RequestFailed,
}

/// Parameters of `BrowserContext.updateSubscription`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextUpdateSubscriptionParams {
    #[serde(rename = "event")]
    pub event: BrowserContextUpdateSubscriptionParamsEvent,
    #[serde(rename = "enabled")]
    pub enabled: bool,
}

/// Parameters of `BrowserContext.clockFastForward` (Fast forward clock "{ticksNumber|ticksString}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClockFastForwardParams {
    #[serde(rename = "ticksNumber", default, skip_serializing_if = "Option::is_none")]
    pub ticks_number: Option<f64>,
    #[serde(rename = "ticksString", default, skip_serializing_if = "Option::is_none")]
    pub ticks_string: Option<String>,
}

/// Parameters of `BrowserContext.clockInstall` (Install clock "{timeNumber|timeString}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClockInstallParams {
    #[serde(rename = "timeNumber", default, skip_serializing_if = "Option::is_none")]
    pub time_number: Option<f64>,
    #[serde(rename = "timeString", default, skip_serializing_if = "Option::is_none")]
    pub time_string: Option<String>,
}

/// Parameters of `BrowserContext.clockPauseAt` (Pause clock "{timeNumber|timeString}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClockPauseAtParams {
    #[serde(rename = "timeNumber", default, skip_serializing_if = "Option::is_none")]
    pub time_number: Option<f64>,
    #[serde(rename = "timeString", default, skip_serializing_if = "Option::is_none")]
    pub time_string: Option<String>,
}

/// Parameters of `BrowserContext.clockRunFor` (Run clock "{ticksNumber|ticksString}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClockRunForParams {
    #[serde(rename = "ticksNumber", default, skip_serializing_if = "Option::is_none")]
    pub ticks_number: Option<f64>,
    #[serde(rename = "ticksString", default, skip_serializing_if = "Option::is_none")]
    pub ticks_string: Option<String>,
}

/// Parameters of `BrowserContext.clockSetFixedTime` (Set fixed time "{timeNumber|timeString}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClockSetFixedTimeParams {
    #[serde(rename = "timeNumber", default, skip_serializing_if = "Option::is_none")]
    pub time_number: Option<f64>,
    #[serde(rename = "timeString", default, skip_serializing_if = "Option::is_none")]
    pub time_string: Option<String>,
}

/// Parameters of `BrowserContext.clockSetSystemTime` (Set system time "{timeNumber|timeString}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextClockSetSystemTimeParams {
    #[serde(rename = "timeNumber", default, skip_serializing_if = "Option::is_none")]
    pub time_number: Option<f64>,
    #[serde(rename = "timeString", default, skip_serializing_if = "Option::is_none")]
    pub time_string: Option<String>,
}

/// Parameters of `BrowserContext.credentialsCreate` (Create virtual credential for "{rpId}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCredentialsCreateParams {
    #[serde(rename = "rpId")]
    pub rp_id: String,
    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    #[serde(rename = "userHandle", default, skip_serializing_if = "Option::is_none")]
    pub user_handle: Option<String>,
    #[serde(rename = "privateKey", default, skip_serializing_if = "Option::is_none")]
    pub private_key: Option<String>,
    #[serde(rename = "publicKey", default, skip_serializing_if = "Option::is_none")]
    pub public_key: Option<String>,
}

/// Result of `BrowserContext.credentialsCreate` (Create virtual credential for "{rpId}").
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCredentialsCreateResult {
    #[serde(rename = "credential")]
    pub credential: VirtualCredential,
}

/// Parameters of `BrowserContext.credentialsGet` (Get virtual credentials).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCredentialsGetParams {
    #[serde(rename = "rpId", default, skip_serializing_if = "Option::is_none")]
    pub rp_id: Option<String>,
    #[serde(rename = "id", default, skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
}

/// Result of `BrowserContext.credentialsGet` (Get virtual credentials).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCredentialsGetResult {
    #[serde(rename = "credentials")]
    pub credentials: Vec<VirtualCredential>,
}

/// Parameters of `BrowserContext.credentialsDelete` (Delete virtual credential).
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextCredentialsDeleteParams {
    #[serde(rename = "id")]
    pub id: String,
}

/// Payload of the `BrowserContext.bindingCall` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextBindingCallEventParams {
    #[serde(rename = "binding")]
    pub binding: Ref<BindingCall>,
}

/// Payload of the `BrowserContext.console` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextConsoleEventParams {
    /// Properties of the `ConsoleMessage` mixin.
    #[serde(flatten)]
    pub console_message: ConsoleMessage,
    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
    pub page: Option<Ref<Page>>,
    #[serde(rename = "worker", default, skip_serializing_if = "Option::is_none")]
    pub worker: Option<Ref<Worker>>,
}

/// Payload of the `BrowserContext.dialog` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextDialogEventParams {
    #[serde(rename = "dialog")]
    pub dialog: Ref<Dialog>,
}

/// Payload of the `BrowserContext.dialogClosed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextDialogClosedEventParams {
    #[serde(rename = "dialog")]
    pub dialog: Ref<Dialog>,
}

/// Payload of the `BrowserContext.page` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextPageEventParams {
    #[serde(rename = "page")]
    pub page: Ref<Page>,
}

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextPageErrorEventParamsLocation {
    #[serde(rename = "url")]
    pub url: String,
    #[serde(rename = "line")]
    pub line: i64,
    #[serde(rename = "column")]
    pub column: i64,
}

/// Payload of the `BrowserContext.pageError` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextPageErrorEventParams {
    #[serde(rename = "error")]
    pub error: SerializedError,
    #[serde(rename = "page")]
    pub page: Ref<Page>,
    #[serde(rename = "location")]
    pub location: BrowserContextPageErrorEventParamsLocation,
}

/// Payload of the `BrowserContext.route` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextRouteEventParams {
    #[serde(rename = "route")]
    pub route: Ref<Route>,
}

/// Payload of the `BrowserContext.webSocketRoute` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextWebSocketRouteEventParams {
    #[serde(rename = "webSocketRoute")]
    pub web_socket_route: Ref<WebSocketRoute>,
}

/// Payload of the `BrowserContext.serviceWorker` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextServiceWorkerEventParams {
    #[serde(rename = "worker")]
    pub worker: Ref<Worker>,
}

/// Payload of the `BrowserContext.request` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextRequestEventParams {
    #[serde(rename = "request")]
    pub request: Ref<Request>,
    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
    pub page: Option<Ref<Page>>,
}

/// Payload of the `BrowserContext.requestFailed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextRequestFailedEventParams {
    #[serde(rename = "request")]
    pub request: Ref<Request>,
    #[serde(rename = "failureText", default, skip_serializing_if = "Option::is_none")]
    pub failure_text: Option<String>,
    #[serde(rename = "responseEndTiming")]
    pub response_end_timing: f64,
    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
    pub page: Option<Ref<Page>>,
}

/// Payload of the `BrowserContext.requestFinished` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextRequestFinishedEventParams {
    #[serde(rename = "request")]
    pub request: Ref<Request>,
    #[serde(rename = "response", default, skip_serializing_if = "Option::is_none")]
    pub response: Option<Ref<Response>>,
    #[serde(rename = "responseEndTiming")]
    pub response_end_timing: f64,
    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
    pub page: Option<Ref<Page>>,
}

/// Payload of the `BrowserContext.response` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextResponseEventParams {
    #[serde(rename = "response")]
    pub response: Ref<Response>,
    #[serde(rename = "page", default, skip_serializing_if = "Option::is_none")]
    pub page: Option<Ref<Page>>,
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BrowserContextRecorderEventEventParamsEvent {
    #[default]
    #[serde(rename = "actionAdded")]
    ActionAdded,
    #[serde(rename = "actionUpdated")]
    ActionUpdated,
    #[serde(rename = "signalAdded")]
    SignalAdded,
}

/// Payload of the `BrowserContext.recorderEvent` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct BrowserContextRecorderEventEventParams {
    #[serde(rename = "event")]
    pub event: BrowserContextRecorderEventEventParamsEvent,
    #[serde(rename = "data")]
    pub data: serde_json::Value,
    #[serde(rename = "page")]
    pub page: Ref<Page>,
    #[serde(rename = "code")]
    pub code: String,
}

/// Events a `BrowserContext` channel can emit.
#[derive(Debug, Clone, PartialEq)]
pub enum BrowserContextEvent {
    /// `BrowserContext.bindingCall`
    BindingCall(BrowserContextBindingCallEventParams),
    /// `BrowserContext.console`
    Console(BrowserContextConsoleEventParams),
    /// `BrowserContext.close`
    Close,
    /// `BrowserContext.dialog`
    Dialog(BrowserContextDialogEventParams),
    /// `BrowserContext.dialogClosed`
    DialogClosed(BrowserContextDialogClosedEventParams),
    /// `BrowserContext.page`
    Page(BrowserContextPageEventParams),
    /// `BrowserContext.pageError`
    PageError(BrowserContextPageErrorEventParams),
    /// `BrowserContext.route`
    Route(BrowserContextRouteEventParams),
    /// `BrowserContext.webSocketRoute`
    WebSocketRoute(BrowserContextWebSocketRouteEventParams),
    /// `BrowserContext.serviceWorker`
    ServiceWorker(BrowserContextServiceWorkerEventParams),
    /// `BrowserContext.request`
    Request(BrowserContextRequestEventParams),
    /// `BrowserContext.requestFailed`
    RequestFailed(BrowserContextRequestFailedEventParams),
    /// `BrowserContext.requestFinished`
    RequestFinished(BrowserContextRequestFinishedEventParams),
    /// `BrowserContext.response`
    Response(BrowserContextResponseEventParams),
    /// `BrowserContext.recorderEvent`
    RecorderEvent(BrowserContextRecorderEventEventParams),
    /// An event this binding does not know (a newer driver).
    Unknown {
        /// Event name.
        method: String,
        /// Raw event parameters.
        params: serde_json::Value,
    },
}

impl ProtocolEvent for BrowserContextEvent {
    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
        match method {
            "bindingCall" => Ok(Self::BindingCall(serde_json::from_value(params)?)),
            "console" => Ok(Self::Console(serde_json::from_value(params)?)),
            "close" => Ok(Self::Close),
            "dialog" => Ok(Self::Dialog(serde_json::from_value(params)?)),
            "dialogClosed" => Ok(Self::DialogClosed(serde_json::from_value(params)?)),
            "page" => Ok(Self::Page(serde_json::from_value(params)?)),
            "pageError" => Ok(Self::PageError(serde_json::from_value(params)?)),
            "route" => Ok(Self::Route(serde_json::from_value(params)?)),
            "webSocketRoute" => Ok(Self::WebSocketRoute(serde_json::from_value(params)?)),
            "serviceWorker" => Ok(Self::ServiceWorker(serde_json::from_value(params)?)),
            "request" => Ok(Self::Request(serde_json::from_value(params)?)),
            "requestFailed" => Ok(Self::RequestFailed(serde_json::from_value(params)?)),
            "requestFinished" => Ok(Self::RequestFinished(serde_json::from_value(params)?)),
            "response" => Ok(Self::Response(serde_json::from_value(params)?)),
            "recorderEvent" => Ok(Self::RecorderEvent(serde_json::from_value(params)?)),
            _ => Ok(Self::Unknown { method: method.to_string(), params }),
        }
    }
}

/// Channel for the `BrowserContext` interface (`browserContext.yml`).
#[derive(Debug, Clone)]
pub struct BrowserContext {
    channel: Channel,
}

impl ChannelType for BrowserContext {
    const INTERFACE: &'static str = "BrowserContext";
    type Initializer = BrowserContextInitializer;
    type Event = BrowserContextEvent;

    fn accepts(interface: &str) -> bool {
        matches!(interface, "BrowserContext")
    }

    fn from_channel(channel: Channel) -> Self {
        Self { channel }
    }

    fn channel(&self) -> &Channel {
        &self.channel
    }
}

impl BrowserContext {
    /// `BrowserContext.addCookies` ("Add cookies").
    pub async fn add_cookies(&self, params: BrowserContextAddCookiesParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("addCookies", &params).await
    }

    /// `BrowserContext.addInitScript` ("Add init script").
    pub async fn add_init_script(&self, params: BrowserContextAddInitScriptParams) -> Result<BrowserContextAddInitScriptResult, ProtocolError> {
        self.channel.send("addInitScript", &params).await
    }

    /// `BrowserContext.clearCookies` ("Clear cookies").
    pub async fn clear_cookies(&self, params: BrowserContextClearCookiesParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clearCookies", &params).await
    }

    /// `BrowserContext.clearPermissions` ("Clear permissions").
    pub async fn clear_permissions(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clearPermissions", &serde_json::json!({})).await
    }

    /// `BrowserContext.close` ("Close context").
    pub async fn close(&self, params: BrowserContextCloseParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("close", &params).await
    }

    /// `BrowserContext.cookies` ("Get cookies").
    pub async fn cookies(&self, params: BrowserContextCookiesParams) -> Result<BrowserContextCookiesResult, ProtocolError> {
        self.channel.send("cookies", &params).await
    }

    /// `BrowserContext.exposeBinding` ("Expose binding").
    pub async fn expose_binding(&self, params: BrowserContextExposeBindingParams) -> Result<BrowserContextExposeBindingResult, ProtocolError> {
        self.channel.send("exposeBinding", &params).await
    }

    /// `BrowserContext.grantPermissions` ("Grant permissions").
    pub async fn grant_permissions(&self, params: BrowserContextGrantPermissionsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("grantPermissions", &params).await
    }

    /// `BrowserContext.newPage` ("Create page").
    pub async fn new_page(&self) -> Result<BrowserContextNewPageResult, ProtocolError> {
        self.channel.send("newPage", &serde_json::json!({})).await
    }

    /// `BrowserContext.registerSelectorEngine` (internal).
    pub async fn register_selector_engine(&self, params: BrowserContextRegisterSelectorEngineParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("registerSelectorEngine", &params).await
    }

    /// `BrowserContext.setTestIdAttributeName` (internal).
    pub async fn set_test_id_attribute_name(&self, params: BrowserContextSetTestIdAttributeNameParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setTestIdAttributeName", &params).await
    }

    /// `BrowserContext.setExtraHTTPHeaders` ("Set extra HTTP headers").
    pub async fn set_extra_http_headers(&self, params: BrowserContextSetExtraHTTPHeadersParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setExtraHTTPHeaders", &params).await
    }

    /// `BrowserContext.setGeolocation` ("Set geolocation").
    pub async fn set_geolocation(&self, params: BrowserContextSetGeolocationParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setGeolocation", &params).await
    }

    /// `BrowserContext.setHTTPCredentials` ("Set HTTP credentials").
    pub async fn set_http_credentials(&self, params: BrowserContextSetHTTPCredentialsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setHTTPCredentials", &params).await
    }

    /// `BrowserContext.setNetworkInterceptionPatterns` ("Route requests").
    pub async fn set_network_interception_patterns(&self, params: BrowserContextSetNetworkInterceptionPatternsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setNetworkInterceptionPatterns", &params).await
    }

    /// `BrowserContext.setWebSocketInterceptionPatterns` ("Route WebSockets").
    pub async fn set_web_socket_interception_patterns(&self, params: BrowserContextSetWebSocketInterceptionPatternsParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setWebSocketInterceptionPatterns", &params).await
    }

    /// `BrowserContext.setOffline` ("Set offline mode").
    pub async fn set_offline(&self, params: BrowserContextSetOfflineParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setOffline", &params).await
    }

    /// `BrowserContext.storageState` ("Get storage state").
    pub async fn storage_state(&self, params: BrowserContextStorageStateParams) -> Result<BrowserContextStorageStateResult, ProtocolError> {
        self.channel.send("storageState", &params).await
    }

    /// `BrowserContext.setStorageState` ("Set storage state").
    pub async fn set_storage_state(&self, params: BrowserContextSetStorageStateParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("setStorageState", &params).await
    }

    /// `BrowserContext.pause` ("Pause").
    pub async fn pause(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("pause", &serde_json::json!({})).await
    }

    /// `BrowserContext.enableRecorder` (internal).
    pub async fn enable_recorder(&self, params: BrowserContextEnableRecorderParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("enableRecorder", &params).await
    }

    /// `BrowserContext.disableRecorder` (internal).
    pub async fn disable_recorder(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("disableRecorder", &serde_json::json!({})).await
    }

    /// `BrowserContext.exposeConsoleApi` (internal).
    pub async fn expose_console_api(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("exposeConsoleApi", &serde_json::json!({})).await
    }

    /// `BrowserContext.newCDPSession` ("Create CDP session").
    pub async fn new_cdp_session(&self, params: BrowserContextNewCDPSessionParams) -> Result<BrowserContextNewCDPSessionResult, ProtocolError> {
        self.channel.send("newCDPSession", &params).await
    }

    /// `BrowserContext.createTempFiles` (internal).
    pub async fn create_temp_files(&self, params: BrowserContextCreateTempFilesParams) -> Result<BrowserContextCreateTempFilesResult, ProtocolError> {
        self.channel.send("createTempFiles", &params).await
    }

    /// `BrowserContext.updateSubscription` (internal).
    pub async fn update_subscription(&self, params: BrowserContextUpdateSubscriptionParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("updateSubscription", &params).await
    }

    /// `BrowserContext.clockFastForward` ("Fast forward clock "{ticksNumber|ticksString}"").
    pub async fn clock_fast_forward(&self, params: BrowserContextClockFastForwardParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockFastForward", &params).await
    }

    /// `BrowserContext.clockInstall` ("Install clock "{timeNumber|timeString}"").
    pub async fn clock_install(&self, params: BrowserContextClockInstallParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockInstall", &params).await
    }

    /// `BrowserContext.clockPauseAt` ("Pause clock "{timeNumber|timeString}"").
    pub async fn clock_pause_at(&self, params: BrowserContextClockPauseAtParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockPauseAt", &params).await
    }

    /// `BrowserContext.clockResume` ("Resume clock").
    pub async fn clock_resume(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockResume", &serde_json::json!({})).await
    }

    /// `BrowserContext.clockRunFor` ("Run clock "{ticksNumber|ticksString}"").
    pub async fn clock_run_for(&self, params: BrowserContextClockRunForParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockRunFor", &params).await
    }

    /// `BrowserContext.clockSetFixedTime` ("Set fixed time "{timeNumber|timeString}"").
    pub async fn clock_set_fixed_time(&self, params: BrowserContextClockSetFixedTimeParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockSetFixedTime", &params).await
    }

    /// `BrowserContext.clockSetSystemTime` ("Set system time "{timeNumber|timeString}"").
    pub async fn clock_set_system_time(&self, params: BrowserContextClockSetSystemTimeParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("clockSetSystemTime", &params).await
    }

    /// `BrowserContext.credentialsInstall` ("Install virtual WebAuthn authenticator").
    pub async fn credentials_install(&self) -> Result<(), ProtocolError> {
        self.channel.send_no_result("credentialsInstall", &serde_json::json!({})).await
    }

    /// `BrowserContext.credentialsCreate` ("Create virtual credential for "{rpId}"").
    pub async fn credentials_create(&self, params: BrowserContextCredentialsCreateParams) -> Result<BrowserContextCredentialsCreateResult, ProtocolError> {
        self.channel.send("credentialsCreate", &params).await
    }

    /// `BrowserContext.credentialsGet` ("Get virtual credentials").
    pub async fn credentials_get(&self, params: BrowserContextCredentialsGetParams) -> Result<BrowserContextCredentialsGetResult, ProtocolError> {
        self.channel.send("credentialsGet", &params).await
    }

    /// `BrowserContext.credentialsDelete` ("Delete virtual credential").
    pub async fn credentials_delete(&self, params: BrowserContextCredentialsDeleteParams) -> Result<(), ProtocolError> {
        self.channel.send_no_result("credentialsDelete", &params).await
    }
}