cdp-driver 0.5.0

Chrome DevTools Protocol (CDP) client for Rust: every command, event and type generated from the schema, with sessions, for browser automation and AI agents
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
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
// @generated by `just generate-methods` from protocol/*.json.
// Do not edit by hand; edit xtask/ and regenerate.

//! Supports additional targets discovery and allows to attach to them.
//!
//! Types, command parameters and event payloads for the `Target`
//! domain. The method-name constants for the same domain are in
//! [`crate::methods`].

use serde::{Deserialize, Serialize};

pub type TargetId = String;

/// Unique identifier of attached debugging session.
pub type SessionId = String;

#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TargetInfo {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
    /// List of types:
    /// <https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/devtools_agent_host_impl.cc?ss=chromium&q=f:devtools%20-f:out%20%22::kTypeTab%5B%5D%22>
    pub r#type: String,
    pub title: String,
    pub url: String,
    /// Whether the target has an attached client.
    pub attached: bool,
    /// Id of the parent target, if any. For example, "iframe" target may have a
    /// "page" parent.
    #[serde(rename = "parentId", default, skip_serializing_if = "Option::is_none")]
    pub parent_id: Option<TargetId>,
    /// Opener target Id
    #[serde(rename = "openerId", default, skip_serializing_if = "Option::is_none")]
    pub opener_id: Option<TargetId>,
    /// Whether the target has access to the originating window.
    ///
    /// Experimental: may change without notice.
    #[serde(rename = "canAccessOpener")]
    pub can_access_opener: bool,
    /// Frame id of originating window (is only set if target has an opener).
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "openerFrameId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub opener_frame_id: Option<crate::protocol::page::FrameId>,
    /// Id of the parent frame, present for "iframe" and "worker" targets. For
    /// nested workers, this is the "ancestor" frame that created the first worker
    /// in the nested chain.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "parentFrameId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub parent_frame_id: Option<crate::protocol::page::FrameId>,
    /// Experimental: may change without notice.
    #[serde(
        rename = "browserContextId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub browser_context_id: Option<crate::protocol::browser::BrowserContextId>,
    /// Provides additional details for specific target types. For example, for
    /// the type of "page", this may be set to "prerender".
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub subtype: Option<String>,
    /// Embedder-specific target metadata. This is only set for targets of type
    /// "tab".
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "embedderData",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub embedder_data: Option<serde_json::Value>,
}

/// A filter used by target query/discovery/auto-attach operations.
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct FilterEntry {
    /// If set, causes exclusion of matching targets from the list.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude: Option<bool>,
    /// If not present, matches any type.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub r#type: Option<String>,
}

/// The entries in TargetFilter are matched sequentially against targets and
/// the first entry that matches determines if the target is included or not,
/// depending on the value of `exclude` field in the entry. If filter is not
/// specified, the one assumed is \[{type: "browser", exclude: true}, {type:
/// "tab", exclude: true}, {}\] (i.e. include everything but `browser` and
/// `tab`).
///
/// Experimental: may change without notice.
pub type TargetFilter = Vec<FilterEntry>;

/// Experimental: may change without notice.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct RemoteLocation {
    pub host: String,
    pub port: i64,
}

/// The state of the target window.
///
/// Experimental: may change without notice.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum WindowState {
    /// `normal`
    #[serde(rename = "normal")]
    Normal,
    /// `minimized`
    #[serde(rename = "minimized")]
    Minimized,
    /// `maximized`
    #[serde(rename = "maximized")]
    Maximized,
    /// `fullscreen`
    #[serde(rename = "fullscreen")]
    Fullscreen,
    /// 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),
}

/// Activates (focuses) the target.
///
/// Parameters of `Target.activateTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ActivateTargetParams {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
}

impl crate::typed::Command for ActivateTargetParams {
    const METHOD: &'static str = "Target.activateTarget";
    type Returns = crate::typed::NoReturns;
}

/// Attaches to the target with given id.
///
/// Parameters of `Target.attachToTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AttachToTargetParams {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
    /// Enables "flat" access to the session via specifying sessionId attribute in
    /// the commands. We plan to make this the default, deprecate non-flattened
    /// mode, and eventually retire it. See crbug.com/991325.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flatten: Option<bool>,
}

/// What `Target.attachToTarget` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AttachToTargetReturns {
    /// Id assigned to the session.
    #[serde(rename = "sessionId")]
    pub session_id: SessionId,
}

impl crate::typed::Command for AttachToTargetParams {
    const METHOD: &'static str = "Target.attachToTarget";
    type Returns = AttachToTargetReturns;
}

/// Attaches to the browser target, only uses flat sessionId mode.
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.attachToBrowserTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AttachToBrowserTargetParams {}

/// What `Target.attachToBrowserTarget` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AttachToBrowserTargetReturns {
    /// Id assigned to the session.
    #[serde(rename = "sessionId")]
    pub session_id: SessionId,
}

impl crate::typed::Command for AttachToBrowserTargetParams {
    const METHOD: &'static str = "Target.attachToBrowserTarget";
    type Returns = AttachToBrowserTargetReturns;
}

/// Closes the target. If the target is a page that gets closed too.
///
/// Parameters of `Target.closeTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CloseTargetParams {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
}

/// What `Target.closeTarget` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CloseTargetReturns {
    /// Always set to true. If an error occurs, the response indicates protocol
    /// error.
    ///
    /// Deprecated in the protocol.
    pub success: bool,
}

impl crate::typed::Command for CloseTargetParams {
    const METHOD: &'static str = "Target.closeTarget";
    type Returns = CloseTargetReturns;
}

/// Inject object to the target's main frame that provides a communication
/// channel with browser target. Injected object will be available as
/// `window\[bindingName\]`. The object has the following API: -
/// `binding.send(json)` - a method to send messages over the remote debugging
/// protocol - `binding.onmessage = json =\> handleMessage(json)` - a callback
/// that will be called for the protocol notifications and command responses.
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.exposeDevToolsProtocol`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ExposeDevToolsProtocolParams {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
    /// Binding name, 'cdp' if not specified.
    #[serde(
        rename = "bindingName",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub binding_name: Option<String>,
    /// If true, inherits the current root session's permissions (default: false).
    #[serde(
        rename = "inheritPermissions",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub inherit_permissions: Option<bool>,
}

impl crate::typed::Command for ExposeDevToolsProtocolParams {
    const METHOD: &'static str = "Target.exposeDevToolsProtocol";
    type Returns = crate::typed::NoReturns;
}

/// Creates a new empty BrowserContext. Similar to an incognito profile but
/// you can have more than one.
///
/// Parameters of `Target.createBrowserContext`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CreateBrowserContextParams {
    /// If specified, disposes this context when debugging session disconnects.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "disposeOnDetach",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub dispose_on_detach: Option<bool>,
    /// Proxy server, similar to the one passed to --proxy-server
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "proxyServer",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub proxy_server: Option<String>,
    /// Proxy bypass list, similar to the one passed to --proxy-bypass-list
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "proxyBypassList",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub proxy_bypass_list: Option<String>,
    /// An optional list of origins to grant unlimited cross-origin access to.
    /// Parts of the URL other than those constituting origin are ignored.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "originsWithUniversalNetworkAccess",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub origins_with_universal_network_access: Option<Vec<String>>,
}

/// What `Target.createBrowserContext` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CreateBrowserContextReturns {
    /// The id of the context created.
    #[serde(rename = "browserContextId")]
    pub browser_context_id: crate::protocol::browser::BrowserContextId,
}

impl crate::typed::Command for CreateBrowserContextParams {
    const METHOD: &'static str = "Target.createBrowserContext";
    type Returns = CreateBrowserContextReturns;
}

/// Returns all browser contexts created with `Target.createBrowserContext`
/// method.
///
/// Parameters of `Target.getBrowserContexts`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetBrowserContextsParams {}

/// What `Target.getBrowserContexts` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetBrowserContextsReturns {
    /// An array of browser context ids.
    #[serde(rename = "browserContextIds")]
    pub browser_context_ids: Vec<crate::protocol::browser::BrowserContextId>,
    /// The id of the default browser context if available.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "defaultBrowserContextId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub default_browser_context_id: Option<crate::protocol::browser::BrowserContextId>,
}

impl crate::typed::Command for GetBrowserContextsParams {
    const METHOD: &'static str = "Target.getBrowserContexts";
    type Returns = GetBrowserContextsReturns;
}

/// Creates a new page.
///
/// Parameters of `Target.createTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CreateTargetParams {
    /// The initial URL the page will be navigated to. An empty string indicates
    /// about:blank.
    pub url: String,
    /// Frame left origin in DIP (requires newWindow to be true or headless
    /// shell).
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub left: Option<i64>,
    /// Frame top origin in DIP (requires newWindow to be true or headless shell).
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub top: Option<i64>,
    /// Frame width in DIP (requires newWindow to be true or headless shell).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub width: Option<i64>,
    /// Frame height in DIP (requires newWindow to be true or headless shell).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,
    /// Frame window state (requires newWindow to be true or headless shell).
    /// Default is normal.
    #[serde(
        rename = "windowState",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub window_state: Option<WindowState>,
    /// The browser context to create the page in.
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "browserContextId",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub browser_context_id: Option<crate::protocol::browser::BrowserContextId>,
    /// Whether BeginFrames for this target will be controlled via DevTools
    /// (headless shell only, not supported on MacOS yet, false by default).
    ///
    /// Experimental: may change without notice.
    #[serde(
        rename = "enableBeginFrameControl",
        default,
        skip_serializing_if = "Option::is_none"
    )]
    pub enable_begin_frame_control: Option<bool>,
    /// Whether to create a new Window or Tab (false by default, not supported by
    /// headless shell).
    #[serde(rename = "newWindow", default, skip_serializing_if = "Option::is_none")]
    pub new_window: Option<bool>,
    /// Whether to create the target in background or foreground (false by
    /// default, not supported by headless shell).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub background: Option<bool>,
    /// Whether to create the target of type "tab".
    ///
    /// Experimental: may change without notice.
    #[serde(rename = "forTab", default, skip_serializing_if = "Option::is_none")]
    pub for_tab: Option<bool>,
    /// Whether to create a hidden target. The hidden target is observable via
    /// protocol, but not present in the tab UI strip. Cannot be created with
    /// `forTab: true`, `newWindow: true` or `background: false`. The life-time of
    /// the tab is limited to the life-time of the session.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub hidden: Option<bool>,
    /// If specified, determines whether the new target should be focused. By
    /// default, the focus behavior depends on the `background` parameter: - If
    /// `background` is false (default) and `focus` is omitted, the new target is
    /// focused and the browser window is brought to the foreground. - If
    /// `background` is false and `focus` is false, the target is opened but the
    /// browser window's focus remains unchanged (e.g., if the window was in the
    /// background, it stays there). - If `background` is true, setting `focus` to
    /// true is not supported and will result in an error.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub focus: Option<bool>,
}

/// What `Target.createTarget` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct CreateTargetReturns {
    /// The id of the page opened.
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
}

impl crate::typed::Command for CreateTargetParams {
    const METHOD: &'static str = "Target.createTarget";
    type Returns = CreateTargetReturns;
}

/// Detaches session with given id.
///
/// Parameters of `Target.detachFromTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DetachFromTargetParams {
    /// Session to detach.
    #[serde(rename = "sessionId", default, skip_serializing_if = "Option::is_none")]
    pub session_id: Option<SessionId>,
    /// Deprecated.
    ///
    /// Deprecated in the protocol.
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<TargetId>,
}

impl crate::typed::Command for DetachFromTargetParams {
    const METHOD: &'static str = "Target.detachFromTarget";
    type Returns = crate::typed::NoReturns;
}

/// Deletes a BrowserContext. All the belonging pages will be closed without
/// calling their beforeunload hooks.
///
/// Parameters of `Target.disposeBrowserContext`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DisposeBrowserContextParams {
    #[serde(rename = "browserContextId")]
    pub browser_context_id: crate::protocol::browser::BrowserContextId,
}

impl crate::typed::Command for DisposeBrowserContextParams {
    const METHOD: &'static str = "Target.disposeBrowserContext";
    type Returns = crate::typed::NoReturns;
}

/// Returns information about a target.
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.getTargetInfo`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetTargetInfoParams {
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<TargetId>,
}

/// What `Target.getTargetInfo` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetTargetInfoReturns {
    #[serde(rename = "targetInfo")]
    pub target_info: TargetInfo,
}

impl crate::typed::Command for GetTargetInfoParams {
    const METHOD: &'static str = "Target.getTargetInfo";
    type Returns = GetTargetInfoReturns;
}

/// Retrieves a list of available targets.
///
/// Parameters of `Target.getTargets`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetTargetsParams {
    /// Only targets matching filter will be reported. If filter is not specified
    /// and target discovery is currently enabled, a filter used for target
    /// discovery is used for consistency.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub filter: Option<TargetFilter>,
}

/// What `Target.getTargets` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetTargetsReturns {
    /// The list of targets.
    #[serde(rename = "targetInfos")]
    pub target_infos: Vec<TargetInfo>,
}

impl crate::typed::Command for GetTargetsParams {
    const METHOD: &'static str = "Target.getTargets";
    type Returns = GetTargetsReturns;
}

/// Sends protocol message over session with given id. Consider using flat
/// mode instead; see commands attachToTarget, setAutoAttach, and
/// crbug.com/991325.
///
/// Deprecated in the protocol.
///
/// Parameters of `Target.sendMessageToTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SendMessageToTargetParams {
    pub message: String,
    /// Identifier of the session.
    #[serde(rename = "sessionId", default, skip_serializing_if = "Option::is_none")]
    pub session_id: Option<SessionId>,
    /// Deprecated.
    ///
    /// Deprecated in the protocol.
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<TargetId>,
}

impl crate::typed::Command for SendMessageToTargetParams {
    const METHOD: &'static str = "Target.sendMessageToTarget";
    type Returns = crate::typed::NoReturns;
}

/// Controls whether to automatically attach to new targets which are
/// considered to be directly related to this one (for example, iframes or
/// workers). When turned on, attaches to all existing related targets as
/// well. When turned off, automatically detaches from all currently attached
/// targets. This also clears all targets added by `autoAttachRelated` from
/// the list of targets to watch for creation of related targets. You might
/// want to call this recursively for auto-attached targets to attach to all
/// available targets.
///
/// Parameters of `Target.setAutoAttach`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetAutoAttachParams {
    /// Whether to auto-attach to related targets.
    #[serde(rename = "autoAttach")]
    pub auto_attach: bool,
    /// Whether to pause new targets when attaching to them. Use
    /// `Runtime.runIfWaitingForDebugger` to run paused targets.
    #[serde(rename = "waitForDebuggerOnStart")]
    pub wait_for_debugger_on_start: bool,
    /// Enables "flat" access to the session via specifying sessionId attribute in
    /// the commands. We plan to make this the default, deprecate non-flattened
    /// mode, and eventually retire it. See crbug.com/991325.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flatten: Option<bool>,
    /// Only targets matching filter will be attached.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub filter: Option<TargetFilter>,
}

impl crate::typed::Command for SetAutoAttachParams {
    const METHOD: &'static str = "Target.setAutoAttach";
    type Returns = crate::typed::NoReturns;
}

/// Adds the specified target to the list of targets that will be monitored
/// for any related target creation (such as child frames, child workers and
/// new versions of service worker) and reported through `attachedToTarget`.
/// The specified target is also auto-attached. This cancels the effect of any
/// previous `setAutoAttach` and is also cancelled by subsequent
/// `setAutoAttach`. Only available at the Browser target.
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.autoAttachRelated`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AutoAttachRelatedParams {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
    /// Whether to pause new targets when attaching to them. Use
    /// `Runtime.runIfWaitingForDebugger` to run paused targets.
    #[serde(rename = "waitForDebuggerOnStart")]
    pub wait_for_debugger_on_start: bool,
    /// Only targets matching filter will be attached.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub filter: Option<TargetFilter>,
}

impl crate::typed::Command for AutoAttachRelatedParams {
    const METHOD: &'static str = "Target.autoAttachRelated";
    type Returns = crate::typed::NoReturns;
}

/// Controls whether to discover available targets and notify via
/// `targetCreated/targetInfoChanged/targetDestroyed` events.
///
/// Parameters of `Target.setDiscoverTargets`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetDiscoverTargetsParams {
    /// Whether to discover available targets.
    pub discover: bool,
    /// Only targets matching filter will be attached. If `discover` is false,
    /// `filter` must be omitted or empty.
    ///
    /// Experimental: may change without notice.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub filter: Option<TargetFilter>,
}

impl crate::typed::Command for SetDiscoverTargetsParams {
    const METHOD: &'static str = "Target.setDiscoverTargets";
    type Returns = crate::typed::NoReturns;
}

/// Enables target discovery for the specified locations, when
/// `setDiscoverTargets` was set to `true`.
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.setRemoteLocations`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SetRemoteLocationsParams {
    /// List of remote locations.
    pub locations: Vec<RemoteLocation>,
}

impl crate::typed::Command for SetRemoteLocationsParams {
    const METHOD: &'static str = "Target.setRemoteLocations";
    type Returns = crate::typed::NoReturns;
}

/// Gets the targetId of the DevTools page target opened for the given target
/// (if any).
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.getDevToolsTarget`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDevToolsTargetParams {
    /// Page or tab target ID.
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
}

/// What `Target.getDevToolsTarget` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct GetDevToolsTargetReturns {
    /// The targetId of DevTools page target if exists.
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<TargetId>,
}

impl crate::typed::Command for GetDevToolsTargetParams {
    const METHOD: &'static str = "Target.getDevToolsTarget";
    type Returns = GetDevToolsTargetReturns;
}

/// Opens a DevTools window for the target.
///
/// Experimental: may change without notice.
///
/// Parameters of `Target.openDevTools`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct OpenDevToolsParams {
    /// This can be the page or tab target ID.
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
    /// The id of the panel we want DevTools to open initially. Currently
    /// supported panels are elements, console, network, sources, resources,
    /// timeline, chrome-recorder, heap-profiler, lighthouse, and security.
    #[serde(rename = "panelId", default, skip_serializing_if = "Option::is_none")]
    pub panel_id: Option<String>,
}

/// What `Target.openDevTools` answers with.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct OpenDevToolsReturns {
    /// The targetId of DevTools page target.
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
}

impl crate::typed::Command for OpenDevToolsParams {
    const METHOD: &'static str = "Target.openDevTools";
    type Returns = OpenDevToolsReturns;
}

/// Issued when attached to target because of auto-attach or `attachToTarget`
/// command.
///
/// Experimental: may change without notice.
///
/// Payload of the `Target.attachedToTarget` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AttachedToTargetEvent {
    /// Identifier assigned to the session used to send/receive messages.
    #[serde(rename = "sessionId")]
    pub session_id: SessionId,
    #[serde(rename = "targetInfo")]
    pub target_info: TargetInfo,
    #[serde(rename = "waitingForDebugger")]
    pub waiting_for_debugger: bool,
}

impl crate::typed::Event for AttachedToTargetEvent {
    const METHOD: &'static str = "Target.attachedToTarget";
}

/// Issued when detached from target for any reason (including
/// `detachFromTarget` command). Can be issued multiple times per target if
/// multiple sessions have been attached to it.
///
/// Experimental: may change without notice.
///
/// Payload of the `Target.detachedFromTarget` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct DetachedFromTargetEvent {
    /// Detached session identifier.
    #[serde(rename = "sessionId")]
    pub session_id: SessionId,
    /// Deprecated.
    ///
    /// Deprecated in the protocol.
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<TargetId>,
}

impl crate::typed::Event for DetachedFromTargetEvent {
    const METHOD: &'static str = "Target.detachedFromTarget";
}

/// Notifies about a new protocol message received from the session (as
/// reported in `attachedToTarget` event).
///
/// Payload of the `Target.receivedMessageFromTarget` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ReceivedMessageFromTargetEvent {
    /// Identifier of a session which sends a message.
    #[serde(rename = "sessionId")]
    pub session_id: SessionId,
    pub message: String,
    /// Deprecated.
    ///
    /// Deprecated in the protocol.
    #[serde(rename = "targetId", default, skip_serializing_if = "Option::is_none")]
    pub target_id: Option<TargetId>,
}

impl crate::typed::Event for ReceivedMessageFromTargetEvent {
    const METHOD: &'static str = "Target.receivedMessageFromTarget";
}

/// Issued when a possible inspection target is created.
///
/// Payload of the `Target.targetCreated` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TargetCreatedEvent {
    #[serde(rename = "targetInfo")]
    pub target_info: TargetInfo,
}

impl crate::typed::Event for TargetCreatedEvent {
    const METHOD: &'static str = "Target.targetCreated";
}

/// Issued when a target is destroyed.
///
/// Payload of the `Target.targetDestroyed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TargetDestroyedEvent {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
}

impl crate::typed::Event for TargetDestroyedEvent {
    const METHOD: &'static str = "Target.targetDestroyed";
}

/// Issued when a target has crashed.
///
/// Payload of the `Target.targetCrashed` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TargetCrashedEvent {
    #[serde(rename = "targetId")]
    pub target_id: TargetId,
    /// Termination status type.
    pub status: String,
    /// Termination error code.
    #[serde(rename = "errorCode")]
    pub error_code: i64,
}

impl crate::typed::Event for TargetCrashedEvent {
    const METHOD: &'static str = "Target.targetCrashed";
}

/// Issued when some information about a target has changed. This only happens
/// between `targetCreated` and `targetDestroyed`.
///
/// Payload of the `Target.targetInfoChanged` event.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct TargetInfoChangedEvent {
    #[serde(rename = "targetInfo")]
    pub target_info: TargetInfo,
}

impl crate::typed::Event for TargetInfoChangedEvent {
    const METHOD: &'static str = "Target.targetInfoChanged";
}