Skip to main content

browser_protocol/target/
mod.rs

1//! Supports additional targets discovery and allows to attach to them.
2
3
4use serde::{Serialize, Deserialize};
5use serde_json::Value as JsonValue;
6use std::borrow::Cow;
7
8
9pub type TargetID<'a> = Cow<'a, str>;
10
11/// Unique identifier of attached debugging session.
12
13pub type SessionID<'a> = Cow<'a, str>;
14
15
16#[derive(Debug, Clone, Serialize, Deserialize, Default)]
17#[serde(rename_all = "camelCase")]
18pub struct TargetInfo<'a> {
19    targetId: TargetID<'a>,
20    /// 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
21    #[serde(rename = "type")]
22    type_: Cow<'a, str>,
23    title: Cow<'a, str>,
24    url: Cow<'a, str>,
25    /// Whether the target has an attached client.
26    attached: bool,
27    /// Opener target Id
28    #[serde(skip_serializing_if = "Option::is_none")]
29    openerId: Option<TargetID<'a>>,
30    /// Whether the target has access to the originating window.
31    canAccessOpener: bool,
32    /// Frame id of originating window (is only set if target has an opener).
33    #[serde(skip_serializing_if = "Option::is_none")]
34    openerFrameId: Option<crate::page::FrameId<'a>>,
35    /// Id of the parent frame, present for "iframe" and "worker" targets. For nested workers,
36    /// this is the "ancestor" frame that created the first worker in the nested chain.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    parentFrameId: Option<crate::page::FrameId<'a>>,
39    #[serde(skip_serializing_if = "Option::is_none")]
40    browserContextId: Option<crate::browser::BrowserContextID<'a>>,
41    /// Provides additional details for specific target types. For example, for
42    /// the type of "page", this may be set to "prerender".
43    #[serde(skip_serializing_if = "Option::is_none")]
44    subtype: Option<Cow<'a, str>>,
45}
46
47impl<'a> TargetInfo<'a> {
48    pub fn builder(targetId: TargetID<'a>, type_: impl Into<Cow<'a, str>>, title: impl Into<Cow<'a, str>>, url: impl Into<Cow<'a, str>>, attached: bool, canAccessOpener: bool) -> TargetInfoBuilder<'a> {
49        TargetInfoBuilder {
50            targetId: targetId,
51            type_: type_.into(),
52            title: title.into(),
53            url: url.into(),
54            attached: attached,
55            openerId: None,
56            canAccessOpener: canAccessOpener,
57            openerFrameId: None,
58            parentFrameId: None,
59            browserContextId: None,
60            subtype: None,
61        }
62    }
63    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
64    pub fn type_(&self) -> &str { self.type_.as_ref() }
65    pub fn title(&self) -> &str { self.title.as_ref() }
66    pub fn url(&self) -> &str { self.url.as_ref() }
67    pub fn attached(&self) -> bool { self.attached }
68    pub fn openerId(&self) -> Option<&TargetID<'a>> { self.openerId.as_ref() }
69    pub fn canAccessOpener(&self) -> bool { self.canAccessOpener }
70    pub fn openerFrameId(&self) -> Option<&crate::page::FrameId<'a>> { self.openerFrameId.as_ref() }
71    pub fn parentFrameId(&self) -> Option<&crate::page::FrameId<'a>> { self.parentFrameId.as_ref() }
72    pub fn browserContextId(&self) -> Option<&crate::browser::BrowserContextID<'a>> { self.browserContextId.as_ref() }
73    pub fn subtype(&self) -> Option<&str> { self.subtype.as_deref() }
74}
75
76
77pub struct TargetInfoBuilder<'a> {
78    targetId: TargetID<'a>,
79    type_: Cow<'a, str>,
80    title: Cow<'a, str>,
81    url: Cow<'a, str>,
82    attached: bool,
83    openerId: Option<TargetID<'a>>,
84    canAccessOpener: bool,
85    openerFrameId: Option<crate::page::FrameId<'a>>,
86    parentFrameId: Option<crate::page::FrameId<'a>>,
87    browserContextId: Option<crate::browser::BrowserContextID<'a>>,
88    subtype: Option<Cow<'a, str>>,
89}
90
91impl<'a> TargetInfoBuilder<'a> {
92    /// Opener target Id
93    pub fn openerId(mut self, openerId: TargetID<'a>) -> Self { self.openerId = Some(openerId); self }
94    /// Frame id of originating window (is only set if target has an opener).
95    pub fn openerFrameId(mut self, openerFrameId: crate::page::FrameId<'a>) -> Self { self.openerFrameId = Some(openerFrameId); self }
96    /// Id of the parent frame, present for "iframe" and "worker" targets. For nested workers,
97    /// this is the "ancestor" frame that created the first worker in the nested chain.
98    pub fn parentFrameId(mut self, parentFrameId: crate::page::FrameId<'a>) -> Self { self.parentFrameId = Some(parentFrameId); self }
99    pub fn browserContextId(mut self, browserContextId: crate::browser::BrowserContextID<'a>) -> Self { self.browserContextId = Some(browserContextId); self }
100    /// Provides additional details for specific target types. For example, for
101    /// the type of "page", this may be set to "prerender".
102    pub fn subtype(mut self, subtype: impl Into<Cow<'a, str>>) -> Self { self.subtype = Some(subtype.into()); self }
103    pub fn build(self) -> TargetInfo<'a> {
104        TargetInfo {
105            targetId: self.targetId,
106            type_: self.type_,
107            title: self.title,
108            url: self.url,
109            attached: self.attached,
110            openerId: self.openerId,
111            canAccessOpener: self.canAccessOpener,
112            openerFrameId: self.openerFrameId,
113            parentFrameId: self.parentFrameId,
114            browserContextId: self.browserContextId,
115            subtype: self.subtype,
116        }
117    }
118}
119
120/// A filter used by target query/discovery/auto-attach operations.
121
122#[derive(Debug, Clone, Serialize, Deserialize, Default)]
123#[serde(rename_all = "camelCase")]
124pub struct FilterEntry<'a> {
125    /// If set, causes exclusion of matching targets from the list.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    exclude: Option<bool>,
128    /// If not present, matches any type.
129    #[serde(skip_serializing_if = "Option::is_none", rename = "type")]
130    type_: Option<Cow<'a, str>>,
131}
132
133impl<'a> FilterEntry<'a> {
134    pub fn builder() -> FilterEntryBuilder<'a> {
135        FilterEntryBuilder {
136            exclude: None,
137            type_: None,
138        }
139    }
140    pub fn exclude(&self) -> Option<bool> { self.exclude }
141    pub fn type_(&self) -> Option<&str> { self.type_.as_deref() }
142}
143
144#[derive(Default)]
145pub struct FilterEntryBuilder<'a> {
146    exclude: Option<bool>,
147    type_: Option<Cow<'a, str>>,
148}
149
150impl<'a> FilterEntryBuilder<'a> {
151    /// If set, causes exclusion of matching targets from the list.
152    pub fn exclude(mut self, exclude: bool) -> Self { self.exclude = Some(exclude); self }
153    /// If not present, matches any type.
154    pub fn type_(mut self, type_: impl Into<Cow<'a, str>>) -> Self { self.type_ = Some(type_.into()); self }
155    pub fn build(self) -> FilterEntry<'a> {
156        FilterEntry {
157            exclude: self.exclude,
158            type_: self.type_,
159        }
160    }
161}
162
163/// The entries in TargetFilter are matched sequentially against targets and
164/// the first entry that matches determines if the target is included or not,
165/// depending on the value of 'exclude' field in the entry.
166/// If filter is not specified, the one assumed is
167/// [{type: "browser", exclude: true}, {type: "tab", exclude: true}, {}]
168/// (i.e. include everything but 'browser' and 'tab').
169
170pub type TargetFilter<'a> = Vec<FilterEntry<'a>>;
171
172
173#[derive(Debug, Clone, Serialize, Deserialize, Default)]
174#[serde(rename_all = "camelCase")]
175pub struct RemoteLocation<'a> {
176    host: Cow<'a, str>,
177    port: i64,
178}
179
180impl<'a> RemoteLocation<'a> {
181    pub fn builder(host: impl Into<Cow<'a, str>>, port: i64) -> RemoteLocationBuilder<'a> {
182        RemoteLocationBuilder {
183            host: host.into(),
184            port: port,
185        }
186    }
187    pub fn host(&self) -> &str { self.host.as_ref() }
188    pub fn port(&self) -> i64 { self.port }
189}
190
191
192pub struct RemoteLocationBuilder<'a> {
193    host: Cow<'a, str>,
194    port: i64,
195}
196
197impl<'a> RemoteLocationBuilder<'a> {
198    pub fn build(self) -> RemoteLocation<'a> {
199        RemoteLocation {
200            host: self.host,
201            port: self.port,
202        }
203    }
204}
205
206/// The state of the target window.
207
208#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
209pub enum WindowState {
210    #[default]
211    #[serde(rename = "normal")]
212    Normal,
213    #[serde(rename = "minimized")]
214    Minimized,
215    #[serde(rename = "maximized")]
216    Maximized,
217    #[serde(rename = "fullscreen")]
218    Fullscreen,
219}
220
221/// Activates (focuses) the target.
222
223#[derive(Debug, Clone, Serialize, Deserialize, Default)]
224#[serde(rename_all = "camelCase")]
225pub struct ActivateTargetParams<'a> {
226    targetId: TargetID<'a>,
227}
228
229impl<'a> ActivateTargetParams<'a> {
230    pub fn builder(targetId: TargetID<'a>) -> ActivateTargetParamsBuilder<'a> {
231        ActivateTargetParamsBuilder {
232            targetId: targetId,
233        }
234    }
235    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
236}
237
238
239pub struct ActivateTargetParamsBuilder<'a> {
240    targetId: TargetID<'a>,
241}
242
243impl<'a> ActivateTargetParamsBuilder<'a> {
244    pub fn build(self) -> ActivateTargetParams<'a> {
245        ActivateTargetParams {
246            targetId: self.targetId,
247        }
248    }
249}
250
251impl<'a> ActivateTargetParams<'a> { pub const METHOD: &'static str = "Target.activateTarget"; }
252
253impl<'a> crate::CdpCommand<'a> for ActivateTargetParams<'a> {
254    const METHOD: &'static str = "Target.activateTarget";
255    type Response = crate::EmptyReturns;
256}
257
258/// Attaches to the target with given id.
259
260#[derive(Debug, Clone, Serialize, Deserialize, Default)]
261#[serde(rename_all = "camelCase")]
262pub struct AttachToTargetParams<'a> {
263    targetId: TargetID<'a>,
264    /// Enables "flat" access to the session via specifying sessionId attribute in the commands.
265    /// We plan to make this the default, deprecate non-flattened mode,
266    /// and eventually retire it. See crbug.com/991325.
267    #[serde(skip_serializing_if = "Option::is_none")]
268    flatten: Option<bool>,
269}
270
271impl<'a> AttachToTargetParams<'a> {
272    pub fn builder(targetId: TargetID<'a>) -> AttachToTargetParamsBuilder<'a> {
273        AttachToTargetParamsBuilder {
274            targetId: targetId,
275            flatten: None,
276        }
277    }
278    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
279    pub fn flatten(&self) -> Option<bool> { self.flatten }
280}
281
282
283pub struct AttachToTargetParamsBuilder<'a> {
284    targetId: TargetID<'a>,
285    flatten: Option<bool>,
286}
287
288impl<'a> AttachToTargetParamsBuilder<'a> {
289    /// Enables "flat" access to the session via specifying sessionId attribute in the commands.
290    /// We plan to make this the default, deprecate non-flattened mode,
291    /// and eventually retire it. See crbug.com/991325.
292    pub fn flatten(mut self, flatten: bool) -> Self { self.flatten = Some(flatten); self }
293    pub fn build(self) -> AttachToTargetParams<'a> {
294        AttachToTargetParams {
295            targetId: self.targetId,
296            flatten: self.flatten,
297        }
298    }
299}
300
301/// Attaches to the target with given id.
302
303#[derive(Debug, Clone, Serialize, Deserialize, Default)]
304#[serde(rename_all = "camelCase")]
305pub struct AttachToTargetReturns<'a> {
306    /// Id assigned to the session.
307    sessionId: SessionID<'a>,
308}
309
310impl<'a> AttachToTargetReturns<'a> {
311    pub fn builder(sessionId: SessionID<'a>) -> AttachToTargetReturnsBuilder<'a> {
312        AttachToTargetReturnsBuilder {
313            sessionId: sessionId,
314        }
315    }
316    pub fn sessionId(&self) -> &SessionID<'a> { &self.sessionId }
317}
318
319
320pub struct AttachToTargetReturnsBuilder<'a> {
321    sessionId: SessionID<'a>,
322}
323
324impl<'a> AttachToTargetReturnsBuilder<'a> {
325    pub fn build(self) -> AttachToTargetReturns<'a> {
326        AttachToTargetReturns {
327            sessionId: self.sessionId,
328        }
329    }
330}
331
332impl<'a> AttachToTargetParams<'a> { pub const METHOD: &'static str = "Target.attachToTarget"; }
333
334impl<'a> crate::CdpCommand<'a> for AttachToTargetParams<'a> {
335    const METHOD: &'static str = "Target.attachToTarget";
336    type Response = AttachToTargetReturns<'a>;
337}
338
339/// Attaches to the browser target, only uses flat sessionId mode.
340
341#[derive(Debug, Clone, Serialize, Deserialize, Default)]
342#[serde(rename_all = "camelCase")]
343pub struct AttachToBrowserTargetReturns<'a> {
344    /// Id assigned to the session.
345    sessionId: SessionID<'a>,
346}
347
348impl<'a> AttachToBrowserTargetReturns<'a> {
349    pub fn builder(sessionId: SessionID<'a>) -> AttachToBrowserTargetReturnsBuilder<'a> {
350        AttachToBrowserTargetReturnsBuilder {
351            sessionId: sessionId,
352        }
353    }
354    pub fn sessionId(&self) -> &SessionID<'a> { &self.sessionId }
355}
356
357
358pub struct AttachToBrowserTargetReturnsBuilder<'a> {
359    sessionId: SessionID<'a>,
360}
361
362impl<'a> AttachToBrowserTargetReturnsBuilder<'a> {
363    pub fn build(self) -> AttachToBrowserTargetReturns<'a> {
364        AttachToBrowserTargetReturns {
365            sessionId: self.sessionId,
366        }
367    }
368}
369
370#[derive(Debug, Clone, Serialize, Deserialize, Default)]
371pub struct AttachToBrowserTargetParams {}
372
373impl AttachToBrowserTargetParams { pub const METHOD: &'static str = "Target.attachToBrowserTarget"; }
374
375impl<'a> crate::CdpCommand<'a> for AttachToBrowserTargetParams {
376    const METHOD: &'static str = "Target.attachToBrowserTarget";
377    type Response = AttachToBrowserTargetReturns<'a>;
378}
379
380/// Closes the target. If the target is a page that gets closed too.
381
382#[derive(Debug, Clone, Serialize, Deserialize, Default)]
383#[serde(rename_all = "camelCase")]
384pub struct CloseTargetParams<'a> {
385    targetId: TargetID<'a>,
386}
387
388impl<'a> CloseTargetParams<'a> {
389    pub fn builder(targetId: TargetID<'a>) -> CloseTargetParamsBuilder<'a> {
390        CloseTargetParamsBuilder {
391            targetId: targetId,
392        }
393    }
394    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
395}
396
397
398pub struct CloseTargetParamsBuilder<'a> {
399    targetId: TargetID<'a>,
400}
401
402impl<'a> CloseTargetParamsBuilder<'a> {
403    pub fn build(self) -> CloseTargetParams<'a> {
404        CloseTargetParams {
405            targetId: self.targetId,
406        }
407    }
408}
409
410/// Closes the target. If the target is a page that gets closed too.
411
412#[derive(Debug, Clone, Serialize, Deserialize, Default)]
413#[serde(rename_all = "camelCase")]
414pub struct CloseTargetReturns {
415    /// Always set to true. If an error occurs, the response indicates protocol error.
416    success: bool,
417}
418
419impl CloseTargetReturns {
420    pub fn builder(success: bool) -> CloseTargetReturnsBuilder {
421        CloseTargetReturnsBuilder {
422            success: success,
423        }
424    }
425    pub fn success(&self) -> bool { self.success }
426}
427
428
429pub struct CloseTargetReturnsBuilder {
430    success: bool,
431}
432
433impl CloseTargetReturnsBuilder {
434    pub fn build(self) -> CloseTargetReturns {
435        CloseTargetReturns {
436            success: self.success,
437        }
438    }
439}
440
441impl<'a> CloseTargetParams<'a> { pub const METHOD: &'static str = "Target.closeTarget"; }
442
443impl<'a> crate::CdpCommand<'a> for CloseTargetParams<'a> {
444    const METHOD: &'static str = "Target.closeTarget";
445    type Response = CloseTargetReturns;
446}
447
448/// Inject object to the target's main frame that provides a communication
449/// channel with browser target.
450/// 
451/// Injected object will be available as 'window[bindingName]'.
452/// 
453/// The object has the following API:
454/// - 'binding.send(json)' - a method to send messages over the remote debugging protocol
455/// - 'binding.onmessage = json => handleMessage(json)' - a callback that will be called for the protocol notifications and command responses.
456
457#[derive(Debug, Clone, Serialize, Deserialize, Default)]
458#[serde(rename_all = "camelCase")]
459pub struct ExposeDevToolsProtocolParams<'a> {
460    targetId: TargetID<'a>,
461    /// Binding name, 'cdp' if not specified.
462    #[serde(skip_serializing_if = "Option::is_none")]
463    bindingName: Option<Cow<'a, str>>,
464    /// If true, inherits the current root session's permissions (default: false).
465    #[serde(skip_serializing_if = "Option::is_none")]
466    inheritPermissions: Option<bool>,
467}
468
469impl<'a> ExposeDevToolsProtocolParams<'a> {
470    pub fn builder(targetId: TargetID<'a>) -> ExposeDevToolsProtocolParamsBuilder<'a> {
471        ExposeDevToolsProtocolParamsBuilder {
472            targetId: targetId,
473            bindingName: None,
474            inheritPermissions: None,
475        }
476    }
477    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
478    pub fn bindingName(&self) -> Option<&str> { self.bindingName.as_deref() }
479    pub fn inheritPermissions(&self) -> Option<bool> { self.inheritPermissions }
480}
481
482
483pub struct ExposeDevToolsProtocolParamsBuilder<'a> {
484    targetId: TargetID<'a>,
485    bindingName: Option<Cow<'a, str>>,
486    inheritPermissions: Option<bool>,
487}
488
489impl<'a> ExposeDevToolsProtocolParamsBuilder<'a> {
490    /// Binding name, 'cdp' if not specified.
491    pub fn bindingName(mut self, bindingName: impl Into<Cow<'a, str>>) -> Self { self.bindingName = Some(bindingName.into()); self }
492    /// If true, inherits the current root session's permissions (default: false).
493    pub fn inheritPermissions(mut self, inheritPermissions: bool) -> Self { self.inheritPermissions = Some(inheritPermissions); self }
494    pub fn build(self) -> ExposeDevToolsProtocolParams<'a> {
495        ExposeDevToolsProtocolParams {
496            targetId: self.targetId,
497            bindingName: self.bindingName,
498            inheritPermissions: self.inheritPermissions,
499        }
500    }
501}
502
503impl<'a> ExposeDevToolsProtocolParams<'a> { pub const METHOD: &'static str = "Target.exposeDevToolsProtocol"; }
504
505impl<'a> crate::CdpCommand<'a> for ExposeDevToolsProtocolParams<'a> {
506    const METHOD: &'static str = "Target.exposeDevToolsProtocol";
507    type Response = crate::EmptyReturns;
508}
509
510/// Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than
511/// one.
512
513#[derive(Debug, Clone, Serialize, Deserialize, Default)]
514#[serde(rename_all = "camelCase")]
515pub struct CreateBrowserContextParams<'a> {
516    /// If specified, disposes this context when debugging session disconnects.
517    #[serde(skip_serializing_if = "Option::is_none")]
518    disposeOnDetach: Option<bool>,
519    /// Proxy server, similar to the one passed to --proxy-server
520    #[serde(skip_serializing_if = "Option::is_none")]
521    proxyServer: Option<Cow<'a, str>>,
522    /// Proxy bypass list, similar to the one passed to --proxy-bypass-list
523    #[serde(skip_serializing_if = "Option::is_none")]
524    proxyBypassList: Option<Cow<'a, str>>,
525    /// An optional list of origins to grant unlimited cross-origin access to.
526    /// Parts of the URL other than those constituting origin are ignored.
527    #[serde(skip_serializing_if = "Option::is_none")]
528    originsWithUniversalNetworkAccess: Option<Vec<Cow<'a, str>>>,
529}
530
531impl<'a> CreateBrowserContextParams<'a> {
532    pub fn builder() -> CreateBrowserContextParamsBuilder<'a> {
533        CreateBrowserContextParamsBuilder {
534            disposeOnDetach: None,
535            proxyServer: None,
536            proxyBypassList: None,
537            originsWithUniversalNetworkAccess: None,
538        }
539    }
540    pub fn disposeOnDetach(&self) -> Option<bool> { self.disposeOnDetach }
541    pub fn proxyServer(&self) -> Option<&str> { self.proxyServer.as_deref() }
542    pub fn proxyBypassList(&self) -> Option<&str> { self.proxyBypassList.as_deref() }
543    pub fn originsWithUniversalNetworkAccess(&self) -> Option<&[Cow<'a, str>]> { self.originsWithUniversalNetworkAccess.as_deref() }
544}
545
546#[derive(Default)]
547pub struct CreateBrowserContextParamsBuilder<'a> {
548    disposeOnDetach: Option<bool>,
549    proxyServer: Option<Cow<'a, str>>,
550    proxyBypassList: Option<Cow<'a, str>>,
551    originsWithUniversalNetworkAccess: Option<Vec<Cow<'a, str>>>,
552}
553
554impl<'a> CreateBrowserContextParamsBuilder<'a> {
555    /// If specified, disposes this context when debugging session disconnects.
556    pub fn disposeOnDetach(mut self, disposeOnDetach: bool) -> Self { self.disposeOnDetach = Some(disposeOnDetach); self }
557    /// Proxy server, similar to the one passed to --proxy-server
558    pub fn proxyServer(mut self, proxyServer: impl Into<Cow<'a, str>>) -> Self { self.proxyServer = Some(proxyServer.into()); self }
559    /// Proxy bypass list, similar to the one passed to --proxy-bypass-list
560    pub fn proxyBypassList(mut self, proxyBypassList: impl Into<Cow<'a, str>>) -> Self { self.proxyBypassList = Some(proxyBypassList.into()); self }
561    /// An optional list of origins to grant unlimited cross-origin access to.
562    /// Parts of the URL other than those constituting origin are ignored.
563    pub fn originsWithUniversalNetworkAccess(mut self, originsWithUniversalNetworkAccess: Vec<Cow<'a, str>>) -> Self { self.originsWithUniversalNetworkAccess = Some(originsWithUniversalNetworkAccess); self }
564    pub fn build(self) -> CreateBrowserContextParams<'a> {
565        CreateBrowserContextParams {
566            disposeOnDetach: self.disposeOnDetach,
567            proxyServer: self.proxyServer,
568            proxyBypassList: self.proxyBypassList,
569            originsWithUniversalNetworkAccess: self.originsWithUniversalNetworkAccess,
570        }
571    }
572}
573
574/// Creates a new empty BrowserContext. Similar to an incognito profile but you can have more than
575/// one.
576
577#[derive(Debug, Clone, Serialize, Deserialize, Default)]
578#[serde(rename_all = "camelCase")]
579pub struct CreateBrowserContextReturns<'a> {
580    /// The id of the context created.
581    browserContextId: crate::browser::BrowserContextID<'a>,
582}
583
584impl<'a> CreateBrowserContextReturns<'a> {
585    pub fn builder(browserContextId: crate::browser::BrowserContextID<'a>) -> CreateBrowserContextReturnsBuilder<'a> {
586        CreateBrowserContextReturnsBuilder {
587            browserContextId: browserContextId,
588        }
589    }
590    pub fn browserContextId(&self) -> &crate::browser::BrowserContextID<'a> { &self.browserContextId }
591}
592
593
594pub struct CreateBrowserContextReturnsBuilder<'a> {
595    browserContextId: crate::browser::BrowserContextID<'a>,
596}
597
598impl<'a> CreateBrowserContextReturnsBuilder<'a> {
599    pub fn build(self) -> CreateBrowserContextReturns<'a> {
600        CreateBrowserContextReturns {
601            browserContextId: self.browserContextId,
602        }
603    }
604}
605
606impl<'a> CreateBrowserContextParams<'a> { pub const METHOD: &'static str = "Target.createBrowserContext"; }
607
608impl<'a> crate::CdpCommand<'a> for CreateBrowserContextParams<'a> {
609    const METHOD: &'static str = "Target.createBrowserContext";
610    type Response = CreateBrowserContextReturns<'a>;
611}
612
613/// Returns all browser contexts created with 'Target.createBrowserContext' method.
614
615#[derive(Debug, Clone, Serialize, Deserialize, Default)]
616#[serde(rename_all = "camelCase")]
617pub struct GetBrowserContextsReturns<'a> {
618    /// An array of browser context ids.
619    browserContextIds: Vec<crate::browser::BrowserContextID<'a>>,
620    /// The id of the default browser context if available.
621    #[serde(skip_serializing_if = "Option::is_none")]
622    defaultBrowserContextId: Option<crate::browser::BrowserContextID<'a>>,
623}
624
625impl<'a> GetBrowserContextsReturns<'a> {
626    pub fn builder(browserContextIds: Vec<crate::browser::BrowserContextID<'a>>) -> GetBrowserContextsReturnsBuilder<'a> {
627        GetBrowserContextsReturnsBuilder {
628            browserContextIds: browserContextIds,
629            defaultBrowserContextId: None,
630        }
631    }
632    pub fn browserContextIds(&self) -> &[crate::browser::BrowserContextID<'a>] { &self.browserContextIds }
633    pub fn defaultBrowserContextId(&self) -> Option<&crate::browser::BrowserContextID<'a>> { self.defaultBrowserContextId.as_ref() }
634}
635
636
637pub struct GetBrowserContextsReturnsBuilder<'a> {
638    browserContextIds: Vec<crate::browser::BrowserContextID<'a>>,
639    defaultBrowserContextId: Option<crate::browser::BrowserContextID<'a>>,
640}
641
642impl<'a> GetBrowserContextsReturnsBuilder<'a> {
643    /// The id of the default browser context if available.
644    pub fn defaultBrowserContextId(mut self, defaultBrowserContextId: crate::browser::BrowserContextID<'a>) -> Self { self.defaultBrowserContextId = Some(defaultBrowserContextId); self }
645    pub fn build(self) -> GetBrowserContextsReturns<'a> {
646        GetBrowserContextsReturns {
647            browserContextIds: self.browserContextIds,
648            defaultBrowserContextId: self.defaultBrowserContextId,
649        }
650    }
651}
652
653#[derive(Debug, Clone, Serialize, Deserialize, Default)]
654pub struct GetBrowserContextsParams {}
655
656impl GetBrowserContextsParams { pub const METHOD: &'static str = "Target.getBrowserContexts"; }
657
658impl<'a> crate::CdpCommand<'a> for GetBrowserContextsParams {
659    const METHOD: &'static str = "Target.getBrowserContexts";
660    type Response = GetBrowserContextsReturns<'a>;
661}
662
663/// Creates a new page.
664
665#[derive(Debug, Clone, Serialize, Deserialize, Default)]
666#[serde(rename_all = "camelCase")]
667pub struct CreateTargetParams<'a> {
668    /// The initial URL the page will be navigated to. An empty string indicates about:blank.
669    url: Cow<'a, str>,
670    /// Frame left origin in DIP (requires newWindow to be true or headless shell).
671    #[serde(skip_serializing_if = "Option::is_none")]
672    left: Option<i64>,
673    /// Frame top origin in DIP (requires newWindow to be true or headless shell).
674    #[serde(skip_serializing_if = "Option::is_none")]
675    top: Option<i64>,
676    /// Frame width in DIP (requires newWindow to be true or headless shell).
677    #[serde(skip_serializing_if = "Option::is_none")]
678    width: Option<u64>,
679    /// Frame height in DIP (requires newWindow to be true or headless shell).
680    #[serde(skip_serializing_if = "Option::is_none")]
681    height: Option<i64>,
682    /// Frame window state (requires newWindow to be true or headless shell).
683    /// Default is normal.
684    #[serde(skip_serializing_if = "Option::is_none")]
685    windowState: Option<WindowState>,
686    /// The browser context to create the page in.
687    #[serde(skip_serializing_if = "Option::is_none")]
688    browserContextId: Option<crate::browser::BrowserContextID<'a>>,
689    /// Whether BeginFrames for this target will be controlled via DevTools (headless shell only,
690    /// not supported on MacOS yet, false by default).
691    #[serde(skip_serializing_if = "Option::is_none")]
692    enableBeginFrameControl: Option<bool>,
693    /// Whether to create a new Window or Tab (false by default, not supported by headless shell).
694    #[serde(skip_serializing_if = "Option::is_none")]
695    newWindow: Option<bool>,
696    /// Whether to create the target in background or foreground (false by default, not supported
697    /// by headless shell).
698    #[serde(skip_serializing_if = "Option::is_none")]
699    background: Option<bool>,
700    /// Whether to create the target of type "tab".
701    #[serde(skip_serializing_if = "Option::is_none")]
702    forTab: Option<bool>,
703    /// Whether to create a hidden target. The hidden target is observable via protocol, but not
704    /// present in the tab UI strip. Cannot be created with 'forTab: true', 'newWindow: true' or
705    /// 'background: false'. The life-time of the tab is limited to the life-time of the session.
706    #[serde(skip_serializing_if = "Option::is_none")]
707    hidden: Option<bool>,
708    /// If specified, the option is used to determine if the new target should
709    /// be focused or not. By default, the focus behavior depends on the
710    /// value of the background field. For example, background=false and focus=false
711    /// will result in the target tab being opened but the browser window remain
712    /// unchanged (if it was in the background, it will remain in the background)
713    /// and background=false with focus=undefined will result in the window being focused.
714    /// Using background: true and focus: true is not supported and will result in an error.
715    #[serde(skip_serializing_if = "Option::is_none")]
716    focus: Option<bool>,
717}
718
719impl<'a> CreateTargetParams<'a> {
720    pub fn builder(url: impl Into<Cow<'a, str>>) -> CreateTargetParamsBuilder<'a> {
721        CreateTargetParamsBuilder {
722            url: url.into(),
723            left: None,
724            top: None,
725            width: None,
726            height: None,
727            windowState: None,
728            browserContextId: None,
729            enableBeginFrameControl: None,
730            newWindow: None,
731            background: None,
732            forTab: None,
733            hidden: None,
734            focus: None,
735        }
736    }
737    pub fn url(&self) -> &str { self.url.as_ref() }
738    pub fn left(&self) -> Option<i64> { self.left }
739    pub fn top(&self) -> Option<i64> { self.top }
740    pub fn width(&self) -> Option<u64> { self.width }
741    pub fn height(&self) -> Option<i64> { self.height }
742    pub fn windowState(&self) -> Option<&WindowState> { self.windowState.as_ref() }
743    pub fn browserContextId(&self) -> Option<&crate::browser::BrowserContextID<'a>> { self.browserContextId.as_ref() }
744    pub fn enableBeginFrameControl(&self) -> Option<bool> { self.enableBeginFrameControl }
745    pub fn newWindow(&self) -> Option<bool> { self.newWindow }
746    pub fn background(&self) -> Option<bool> { self.background }
747    pub fn forTab(&self) -> Option<bool> { self.forTab }
748    pub fn hidden(&self) -> Option<bool> { self.hidden }
749    pub fn focus(&self) -> Option<bool> { self.focus }
750}
751
752
753pub struct CreateTargetParamsBuilder<'a> {
754    url: Cow<'a, str>,
755    left: Option<i64>,
756    top: Option<i64>,
757    width: Option<u64>,
758    height: Option<i64>,
759    windowState: Option<WindowState>,
760    browserContextId: Option<crate::browser::BrowserContextID<'a>>,
761    enableBeginFrameControl: Option<bool>,
762    newWindow: Option<bool>,
763    background: Option<bool>,
764    forTab: Option<bool>,
765    hidden: Option<bool>,
766    focus: Option<bool>,
767}
768
769impl<'a> CreateTargetParamsBuilder<'a> {
770    /// Frame left origin in DIP (requires newWindow to be true or headless shell).
771    pub fn left(mut self, left: i64) -> Self { self.left = Some(left); self }
772    /// Frame top origin in DIP (requires newWindow to be true or headless shell).
773    pub fn top(mut self, top: i64) -> Self { self.top = Some(top); self }
774    /// Frame width in DIP (requires newWindow to be true or headless shell).
775    pub fn width(mut self, width: u64) -> Self { self.width = Some(width); self }
776    /// Frame height in DIP (requires newWindow to be true or headless shell).
777    pub fn height(mut self, height: i64) -> Self { self.height = Some(height); self }
778    /// Frame window state (requires newWindow to be true or headless shell).
779    /// Default is normal.
780    pub fn windowState(mut self, windowState: WindowState) -> Self { self.windowState = Some(windowState); self }
781    /// The browser context to create the page in.
782    pub fn browserContextId(mut self, browserContextId: crate::browser::BrowserContextID<'a>) -> Self { self.browserContextId = Some(browserContextId); self }
783    /// Whether BeginFrames for this target will be controlled via DevTools (headless shell only,
784    /// not supported on MacOS yet, false by default).
785    pub fn enableBeginFrameControl(mut self, enableBeginFrameControl: bool) -> Self { self.enableBeginFrameControl = Some(enableBeginFrameControl); self }
786    /// Whether to create a new Window or Tab (false by default, not supported by headless shell).
787    pub fn newWindow(mut self, newWindow: bool) -> Self { self.newWindow = Some(newWindow); self }
788    /// Whether to create the target in background or foreground (false by default, not supported
789    /// by headless shell).
790    pub fn background(mut self, background: bool) -> Self { self.background = Some(background); self }
791    /// Whether to create the target of type "tab".
792    pub fn forTab(mut self, forTab: bool) -> Self { self.forTab = Some(forTab); self }
793    /// Whether to create a hidden target. The hidden target is observable via protocol, but not
794    /// present in the tab UI strip. Cannot be created with 'forTab: true', 'newWindow: true' or
795    /// 'background: false'. The life-time of the tab is limited to the life-time of the session.
796    pub fn hidden(mut self, hidden: bool) -> Self { self.hidden = Some(hidden); self }
797    /// If specified, the option is used to determine if the new target should
798    /// be focused or not. By default, the focus behavior depends on the
799    /// value of the background field. For example, background=false and focus=false
800    /// will result in the target tab being opened but the browser window remain
801    /// unchanged (if it was in the background, it will remain in the background)
802    /// and background=false with focus=undefined will result in the window being focused.
803    /// Using background: true and focus: true is not supported and will result in an error.
804    pub fn focus(mut self, focus: bool) -> Self { self.focus = Some(focus); self }
805    pub fn build(self) -> CreateTargetParams<'a> {
806        CreateTargetParams {
807            url: self.url,
808            left: self.left,
809            top: self.top,
810            width: self.width,
811            height: self.height,
812            windowState: self.windowState,
813            browserContextId: self.browserContextId,
814            enableBeginFrameControl: self.enableBeginFrameControl,
815            newWindow: self.newWindow,
816            background: self.background,
817            forTab: self.forTab,
818            hidden: self.hidden,
819            focus: self.focus,
820        }
821    }
822}
823
824/// Creates a new page.
825
826#[derive(Debug, Clone, Serialize, Deserialize, Default)]
827#[serde(rename_all = "camelCase")]
828pub struct CreateTargetReturns<'a> {
829    /// The id of the page opened.
830    targetId: TargetID<'a>,
831}
832
833impl<'a> CreateTargetReturns<'a> {
834    pub fn builder(targetId: TargetID<'a>) -> CreateTargetReturnsBuilder<'a> {
835        CreateTargetReturnsBuilder {
836            targetId: targetId,
837        }
838    }
839    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
840}
841
842
843pub struct CreateTargetReturnsBuilder<'a> {
844    targetId: TargetID<'a>,
845}
846
847impl<'a> CreateTargetReturnsBuilder<'a> {
848    pub fn build(self) -> CreateTargetReturns<'a> {
849        CreateTargetReturns {
850            targetId: self.targetId,
851        }
852    }
853}
854
855impl<'a> CreateTargetParams<'a> { pub const METHOD: &'static str = "Target.createTarget"; }
856
857impl<'a> crate::CdpCommand<'a> for CreateTargetParams<'a> {
858    const METHOD: &'static str = "Target.createTarget";
859    type Response = CreateTargetReturns<'a>;
860}
861
862/// Detaches session with given id.
863
864#[derive(Debug, Clone, Serialize, Deserialize, Default)]
865#[serde(rename_all = "camelCase")]
866pub struct DetachFromTargetParams<'a> {
867    /// Session to detach.
868    #[serde(skip_serializing_if = "Option::is_none")]
869    sessionId: Option<SessionID<'a>>,
870    /// Deprecated.
871    #[serde(skip_serializing_if = "Option::is_none")]
872    targetId: Option<TargetID<'a>>,
873}
874
875impl<'a> DetachFromTargetParams<'a> {
876    pub fn builder() -> DetachFromTargetParamsBuilder<'a> {
877        DetachFromTargetParamsBuilder {
878            sessionId: None,
879            targetId: None,
880        }
881    }
882    pub fn sessionId(&self) -> Option<&SessionID<'a>> { self.sessionId.as_ref() }
883    pub fn targetId(&self) -> Option<&TargetID<'a>> { self.targetId.as_ref() }
884}
885
886#[derive(Default)]
887pub struct DetachFromTargetParamsBuilder<'a> {
888    sessionId: Option<SessionID<'a>>,
889    targetId: Option<TargetID<'a>>,
890}
891
892impl<'a> DetachFromTargetParamsBuilder<'a> {
893    /// Session to detach.
894    pub fn sessionId(mut self, sessionId: SessionID<'a>) -> Self { self.sessionId = Some(sessionId); self }
895    /// Deprecated.
896    pub fn targetId(mut self, targetId: TargetID<'a>) -> Self { self.targetId = Some(targetId); self }
897    pub fn build(self) -> DetachFromTargetParams<'a> {
898        DetachFromTargetParams {
899            sessionId: self.sessionId,
900            targetId: self.targetId,
901        }
902    }
903}
904
905impl<'a> DetachFromTargetParams<'a> { pub const METHOD: &'static str = "Target.detachFromTarget"; }
906
907impl<'a> crate::CdpCommand<'a> for DetachFromTargetParams<'a> {
908    const METHOD: &'static str = "Target.detachFromTarget";
909    type Response = crate::EmptyReturns;
910}
911
912/// Deletes a BrowserContext. All the belonging pages will be closed without calling their
913/// beforeunload hooks.
914
915#[derive(Debug, Clone, Serialize, Deserialize, Default)]
916#[serde(rename_all = "camelCase")]
917pub struct DisposeBrowserContextParams<'a> {
918    browserContextId: crate::browser::BrowserContextID<'a>,
919}
920
921impl<'a> DisposeBrowserContextParams<'a> {
922    pub fn builder(browserContextId: crate::browser::BrowserContextID<'a>) -> DisposeBrowserContextParamsBuilder<'a> {
923        DisposeBrowserContextParamsBuilder {
924            browserContextId: browserContextId,
925        }
926    }
927    pub fn browserContextId(&self) -> &crate::browser::BrowserContextID<'a> { &self.browserContextId }
928}
929
930
931pub struct DisposeBrowserContextParamsBuilder<'a> {
932    browserContextId: crate::browser::BrowserContextID<'a>,
933}
934
935impl<'a> DisposeBrowserContextParamsBuilder<'a> {
936    pub fn build(self) -> DisposeBrowserContextParams<'a> {
937        DisposeBrowserContextParams {
938            browserContextId: self.browserContextId,
939        }
940    }
941}
942
943impl<'a> DisposeBrowserContextParams<'a> { pub const METHOD: &'static str = "Target.disposeBrowserContext"; }
944
945impl<'a> crate::CdpCommand<'a> for DisposeBrowserContextParams<'a> {
946    const METHOD: &'static str = "Target.disposeBrowserContext";
947    type Response = crate::EmptyReturns;
948}
949
950/// Returns information about a target.
951
952#[derive(Debug, Clone, Serialize, Deserialize, Default)]
953#[serde(rename_all = "camelCase")]
954pub struct GetTargetInfoParams<'a> {
955    #[serde(skip_serializing_if = "Option::is_none")]
956    targetId: Option<TargetID<'a>>,
957}
958
959impl<'a> GetTargetInfoParams<'a> {
960    pub fn builder() -> GetTargetInfoParamsBuilder<'a> {
961        GetTargetInfoParamsBuilder {
962            targetId: None,
963        }
964    }
965    pub fn targetId(&self) -> Option<&TargetID<'a>> { self.targetId.as_ref() }
966}
967
968#[derive(Default)]
969pub struct GetTargetInfoParamsBuilder<'a> {
970    targetId: Option<TargetID<'a>>,
971}
972
973impl<'a> GetTargetInfoParamsBuilder<'a> {
974    pub fn targetId(mut self, targetId: TargetID<'a>) -> Self { self.targetId = Some(targetId); self }
975    pub fn build(self) -> GetTargetInfoParams<'a> {
976        GetTargetInfoParams {
977            targetId: self.targetId,
978        }
979    }
980}
981
982/// Returns information about a target.
983
984#[derive(Debug, Clone, Serialize, Deserialize, Default)]
985#[serde(rename_all = "camelCase")]
986pub struct GetTargetInfoReturns<'a> {
987    targetInfo: TargetInfo<'a>,
988}
989
990impl<'a> GetTargetInfoReturns<'a> {
991    pub fn builder(targetInfo: TargetInfo<'a>) -> GetTargetInfoReturnsBuilder<'a> {
992        GetTargetInfoReturnsBuilder {
993            targetInfo: targetInfo,
994        }
995    }
996    pub fn targetInfo(&self) -> &TargetInfo<'a> { &self.targetInfo }
997}
998
999
1000pub struct GetTargetInfoReturnsBuilder<'a> {
1001    targetInfo: TargetInfo<'a>,
1002}
1003
1004impl<'a> GetTargetInfoReturnsBuilder<'a> {
1005    pub fn build(self) -> GetTargetInfoReturns<'a> {
1006        GetTargetInfoReturns {
1007            targetInfo: self.targetInfo,
1008        }
1009    }
1010}
1011
1012impl<'a> GetTargetInfoParams<'a> { pub const METHOD: &'static str = "Target.getTargetInfo"; }
1013
1014impl<'a> crate::CdpCommand<'a> for GetTargetInfoParams<'a> {
1015    const METHOD: &'static str = "Target.getTargetInfo";
1016    type Response = GetTargetInfoReturns<'a>;
1017}
1018
1019/// Retrieves a list of available targets.
1020
1021#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1022#[serde(rename_all = "camelCase")]
1023pub struct GetTargetsParams<'a> {
1024    /// Only targets matching filter will be reported. If filter is not specified
1025    /// and target discovery is currently enabled, a filter used for target discovery
1026    /// is used for consistency.
1027    #[serde(skip_serializing_if = "Option::is_none")]
1028    filter: Option<TargetFilter<'a>>,
1029}
1030
1031impl<'a> GetTargetsParams<'a> {
1032    pub fn builder() -> GetTargetsParamsBuilder<'a> {
1033        GetTargetsParamsBuilder {
1034            filter: None,
1035        }
1036    }
1037    pub fn filter(&self) -> Option<&TargetFilter<'a>> { self.filter.as_ref() }
1038}
1039
1040#[derive(Default)]
1041pub struct GetTargetsParamsBuilder<'a> {
1042    filter: Option<TargetFilter<'a>>,
1043}
1044
1045impl<'a> GetTargetsParamsBuilder<'a> {
1046    /// Only targets matching filter will be reported. If filter is not specified
1047    /// and target discovery is currently enabled, a filter used for target discovery
1048    /// is used for consistency.
1049    pub fn filter(mut self, filter: TargetFilter<'a>) -> Self { self.filter = Some(filter); self }
1050    pub fn build(self) -> GetTargetsParams<'a> {
1051        GetTargetsParams {
1052            filter: self.filter,
1053        }
1054    }
1055}
1056
1057/// Retrieves a list of available targets.
1058
1059#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1060#[serde(rename_all = "camelCase")]
1061pub struct GetTargetsReturns<'a> {
1062    /// The list of targets.
1063    targetInfos: Vec<TargetInfo<'a>>,
1064}
1065
1066impl<'a> GetTargetsReturns<'a> {
1067    pub fn builder(targetInfos: Vec<TargetInfo<'a>>) -> GetTargetsReturnsBuilder<'a> {
1068        GetTargetsReturnsBuilder {
1069            targetInfos: targetInfos,
1070        }
1071    }
1072    pub fn targetInfos(&self) -> &[TargetInfo<'a>] { &self.targetInfos }
1073}
1074
1075
1076pub struct GetTargetsReturnsBuilder<'a> {
1077    targetInfos: Vec<TargetInfo<'a>>,
1078}
1079
1080impl<'a> GetTargetsReturnsBuilder<'a> {
1081    pub fn build(self) -> GetTargetsReturns<'a> {
1082        GetTargetsReturns {
1083            targetInfos: self.targetInfos,
1084        }
1085    }
1086}
1087
1088impl<'a> GetTargetsParams<'a> { pub const METHOD: &'static str = "Target.getTargets"; }
1089
1090impl<'a> crate::CdpCommand<'a> for GetTargetsParams<'a> {
1091    const METHOD: &'static str = "Target.getTargets";
1092    type Response = GetTargetsReturns<'a>;
1093}
1094
1095/// Sends protocol message over session with given id.
1096/// Consider using flat mode instead; see commands attachToTarget, setAutoAttach,
1097/// and crbug.com/991325.
1098
1099#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1100#[serde(rename_all = "camelCase")]
1101pub struct SendMessageToTargetParams<'a> {
1102    message: Cow<'a, str>,
1103    /// Identifier of the session.
1104    #[serde(skip_serializing_if = "Option::is_none")]
1105    sessionId: Option<SessionID<'a>>,
1106    /// Deprecated.
1107    #[serde(skip_serializing_if = "Option::is_none")]
1108    targetId: Option<TargetID<'a>>,
1109}
1110
1111impl<'a> SendMessageToTargetParams<'a> {
1112    pub fn builder(message: impl Into<Cow<'a, str>>) -> SendMessageToTargetParamsBuilder<'a> {
1113        SendMessageToTargetParamsBuilder {
1114            message: message.into(),
1115            sessionId: None,
1116            targetId: None,
1117        }
1118    }
1119    pub fn message(&self) -> &str { self.message.as_ref() }
1120    pub fn sessionId(&self) -> Option<&SessionID<'a>> { self.sessionId.as_ref() }
1121    pub fn targetId(&self) -> Option<&TargetID<'a>> { self.targetId.as_ref() }
1122}
1123
1124
1125pub struct SendMessageToTargetParamsBuilder<'a> {
1126    message: Cow<'a, str>,
1127    sessionId: Option<SessionID<'a>>,
1128    targetId: Option<TargetID<'a>>,
1129}
1130
1131impl<'a> SendMessageToTargetParamsBuilder<'a> {
1132    /// Identifier of the session.
1133    pub fn sessionId(mut self, sessionId: SessionID<'a>) -> Self { self.sessionId = Some(sessionId); self }
1134    /// Deprecated.
1135    pub fn targetId(mut self, targetId: TargetID<'a>) -> Self { self.targetId = Some(targetId); self }
1136    pub fn build(self) -> SendMessageToTargetParams<'a> {
1137        SendMessageToTargetParams {
1138            message: self.message,
1139            sessionId: self.sessionId,
1140            targetId: self.targetId,
1141        }
1142    }
1143}
1144
1145impl<'a> SendMessageToTargetParams<'a> { pub const METHOD: &'static str = "Target.sendMessageToTarget"; }
1146
1147impl<'a> crate::CdpCommand<'a> for SendMessageToTargetParams<'a> {
1148    const METHOD: &'static str = "Target.sendMessageToTarget";
1149    type Response = crate::EmptyReturns;
1150}
1151
1152/// Controls whether to automatically attach to new targets which are considered
1153/// to be directly related to this one (for example, iframes or workers).
1154/// When turned on, attaches to all existing related targets as well. When turned off,
1155/// automatically detaches from all currently attached targets.
1156/// This also clears all targets added by 'autoAttachRelated' from the list of targets to watch
1157/// for creation of related targets.
1158/// You might want to call this recursively for auto-attached targets to attach
1159/// to all available targets.
1160
1161#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1162#[serde(rename_all = "camelCase")]
1163pub struct SetAutoAttachParams<'a> {
1164    /// Whether to auto-attach to related targets.
1165    autoAttach: bool,
1166    /// Whether to pause new targets when attaching to them. Use 'Runtime.runIfWaitingForDebugger'
1167    /// to run paused targets.
1168    waitForDebuggerOnStart: bool,
1169    /// Enables "flat" access to the session via specifying sessionId attribute in the commands.
1170    /// We plan to make this the default, deprecate non-flattened mode,
1171    /// and eventually retire it. See crbug.com/991325.
1172    #[serde(skip_serializing_if = "Option::is_none")]
1173    flatten: Option<bool>,
1174    /// Only targets matching filter will be attached.
1175    #[serde(skip_serializing_if = "Option::is_none")]
1176    filter: Option<TargetFilter<'a>>,
1177}
1178
1179impl<'a> SetAutoAttachParams<'a> {
1180    pub fn builder(autoAttach: bool, waitForDebuggerOnStart: bool) -> SetAutoAttachParamsBuilder<'a> {
1181        SetAutoAttachParamsBuilder {
1182            autoAttach: autoAttach,
1183            waitForDebuggerOnStart: waitForDebuggerOnStart,
1184            flatten: None,
1185            filter: None,
1186        }
1187    }
1188    pub fn autoAttach(&self) -> bool { self.autoAttach }
1189    pub fn waitForDebuggerOnStart(&self) -> bool { self.waitForDebuggerOnStart }
1190    pub fn flatten(&self) -> Option<bool> { self.flatten }
1191    pub fn filter(&self) -> Option<&TargetFilter<'a>> { self.filter.as_ref() }
1192}
1193
1194
1195pub struct SetAutoAttachParamsBuilder<'a> {
1196    autoAttach: bool,
1197    waitForDebuggerOnStart: bool,
1198    flatten: Option<bool>,
1199    filter: Option<TargetFilter<'a>>,
1200}
1201
1202impl<'a> SetAutoAttachParamsBuilder<'a> {
1203    /// Enables "flat" access to the session via specifying sessionId attribute in the commands.
1204    /// We plan to make this the default, deprecate non-flattened mode,
1205    /// and eventually retire it. See crbug.com/991325.
1206    pub fn flatten(mut self, flatten: bool) -> Self { self.flatten = Some(flatten); self }
1207    /// Only targets matching filter will be attached.
1208    pub fn filter(mut self, filter: TargetFilter<'a>) -> Self { self.filter = Some(filter); self }
1209    pub fn build(self) -> SetAutoAttachParams<'a> {
1210        SetAutoAttachParams {
1211            autoAttach: self.autoAttach,
1212            waitForDebuggerOnStart: self.waitForDebuggerOnStart,
1213            flatten: self.flatten,
1214            filter: self.filter,
1215        }
1216    }
1217}
1218
1219impl<'a> SetAutoAttachParams<'a> { pub const METHOD: &'static str = "Target.setAutoAttach"; }
1220
1221impl<'a> crate::CdpCommand<'a> for SetAutoAttachParams<'a> {
1222    const METHOD: &'static str = "Target.setAutoAttach";
1223    type Response = crate::EmptyReturns;
1224}
1225
1226/// Adds the specified target to the list of targets that will be monitored for any related target
1227/// creation (such as child frames, child workers and new versions of service worker) and reported
1228/// through 'attachedToTarget'. The specified target is also auto-attached.
1229/// This cancels the effect of any previous 'setAutoAttach' and is also cancelled by subsequent
1230/// 'setAutoAttach'. Only available at the Browser target.
1231
1232#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1233#[serde(rename_all = "camelCase")]
1234pub struct AutoAttachRelatedParams<'a> {
1235    targetId: TargetID<'a>,
1236    /// Whether to pause new targets when attaching to them. Use 'Runtime.runIfWaitingForDebugger'
1237    /// to run paused targets.
1238    waitForDebuggerOnStart: bool,
1239    /// Only targets matching filter will be attached.
1240    #[serde(skip_serializing_if = "Option::is_none")]
1241    filter: Option<TargetFilter<'a>>,
1242}
1243
1244impl<'a> AutoAttachRelatedParams<'a> {
1245    pub fn builder(targetId: TargetID<'a>, waitForDebuggerOnStart: bool) -> AutoAttachRelatedParamsBuilder<'a> {
1246        AutoAttachRelatedParamsBuilder {
1247            targetId: targetId,
1248            waitForDebuggerOnStart: waitForDebuggerOnStart,
1249            filter: None,
1250        }
1251    }
1252    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
1253    pub fn waitForDebuggerOnStart(&self) -> bool { self.waitForDebuggerOnStart }
1254    pub fn filter(&self) -> Option<&TargetFilter<'a>> { self.filter.as_ref() }
1255}
1256
1257
1258pub struct AutoAttachRelatedParamsBuilder<'a> {
1259    targetId: TargetID<'a>,
1260    waitForDebuggerOnStart: bool,
1261    filter: Option<TargetFilter<'a>>,
1262}
1263
1264impl<'a> AutoAttachRelatedParamsBuilder<'a> {
1265    /// Only targets matching filter will be attached.
1266    pub fn filter(mut self, filter: TargetFilter<'a>) -> Self { self.filter = Some(filter); self }
1267    pub fn build(self) -> AutoAttachRelatedParams<'a> {
1268        AutoAttachRelatedParams {
1269            targetId: self.targetId,
1270            waitForDebuggerOnStart: self.waitForDebuggerOnStart,
1271            filter: self.filter,
1272        }
1273    }
1274}
1275
1276impl<'a> AutoAttachRelatedParams<'a> { pub const METHOD: &'static str = "Target.autoAttachRelated"; }
1277
1278impl<'a> crate::CdpCommand<'a> for AutoAttachRelatedParams<'a> {
1279    const METHOD: &'static str = "Target.autoAttachRelated";
1280    type Response = crate::EmptyReturns;
1281}
1282
1283/// Controls whether to discover available targets and notify via
1284/// 'targetCreated/targetInfoChanged/targetDestroyed' events.
1285
1286#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1287#[serde(rename_all = "camelCase")]
1288pub struct SetDiscoverTargetsParams<'a> {
1289    /// Whether to discover available targets.
1290    discover: bool,
1291    /// Only targets matching filter will be attached. If 'discover' is false,
1292    /// 'filter' must be omitted or empty.
1293    #[serde(skip_serializing_if = "Option::is_none")]
1294    filter: Option<TargetFilter<'a>>,
1295}
1296
1297impl<'a> SetDiscoverTargetsParams<'a> {
1298    pub fn builder(discover: bool) -> SetDiscoverTargetsParamsBuilder<'a> {
1299        SetDiscoverTargetsParamsBuilder {
1300            discover: discover,
1301            filter: None,
1302        }
1303    }
1304    pub fn discover(&self) -> bool { self.discover }
1305    pub fn filter(&self) -> Option<&TargetFilter<'a>> { self.filter.as_ref() }
1306}
1307
1308
1309pub struct SetDiscoverTargetsParamsBuilder<'a> {
1310    discover: bool,
1311    filter: Option<TargetFilter<'a>>,
1312}
1313
1314impl<'a> SetDiscoverTargetsParamsBuilder<'a> {
1315    /// Only targets matching filter will be attached. If 'discover' is false,
1316    /// 'filter' must be omitted or empty.
1317    pub fn filter(mut self, filter: TargetFilter<'a>) -> Self { self.filter = Some(filter); self }
1318    pub fn build(self) -> SetDiscoverTargetsParams<'a> {
1319        SetDiscoverTargetsParams {
1320            discover: self.discover,
1321            filter: self.filter,
1322        }
1323    }
1324}
1325
1326impl<'a> SetDiscoverTargetsParams<'a> { pub const METHOD: &'static str = "Target.setDiscoverTargets"; }
1327
1328impl<'a> crate::CdpCommand<'a> for SetDiscoverTargetsParams<'a> {
1329    const METHOD: &'static str = "Target.setDiscoverTargets";
1330    type Response = crate::EmptyReturns;
1331}
1332
1333/// Enables target discovery for the specified locations, when 'setDiscoverTargets' was set to
1334/// 'true'.
1335
1336#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1337#[serde(rename_all = "camelCase")]
1338pub struct SetRemoteLocationsParams<'a> {
1339    /// List of remote locations.
1340    locations: Vec<RemoteLocation<'a>>,
1341}
1342
1343impl<'a> SetRemoteLocationsParams<'a> {
1344    pub fn builder(locations: Vec<RemoteLocation<'a>>) -> SetRemoteLocationsParamsBuilder<'a> {
1345        SetRemoteLocationsParamsBuilder {
1346            locations: locations,
1347        }
1348    }
1349    pub fn locations(&self) -> &[RemoteLocation<'a>] { &self.locations }
1350}
1351
1352
1353pub struct SetRemoteLocationsParamsBuilder<'a> {
1354    locations: Vec<RemoteLocation<'a>>,
1355}
1356
1357impl<'a> SetRemoteLocationsParamsBuilder<'a> {
1358    pub fn build(self) -> SetRemoteLocationsParams<'a> {
1359        SetRemoteLocationsParams {
1360            locations: self.locations,
1361        }
1362    }
1363}
1364
1365impl<'a> SetRemoteLocationsParams<'a> { pub const METHOD: &'static str = "Target.setRemoteLocations"; }
1366
1367impl<'a> crate::CdpCommand<'a> for SetRemoteLocationsParams<'a> {
1368    const METHOD: &'static str = "Target.setRemoteLocations";
1369    type Response = crate::EmptyReturns;
1370}
1371
1372/// Gets the targetId of the DevTools page target opened for the given target
1373/// (if any).
1374
1375#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1376#[serde(rename_all = "camelCase")]
1377pub struct GetDevToolsTargetParams<'a> {
1378    /// Page or tab target ID.
1379    targetId: TargetID<'a>,
1380}
1381
1382impl<'a> GetDevToolsTargetParams<'a> {
1383    pub fn builder(targetId: TargetID<'a>) -> GetDevToolsTargetParamsBuilder<'a> {
1384        GetDevToolsTargetParamsBuilder {
1385            targetId: targetId,
1386        }
1387    }
1388    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
1389}
1390
1391
1392pub struct GetDevToolsTargetParamsBuilder<'a> {
1393    targetId: TargetID<'a>,
1394}
1395
1396impl<'a> GetDevToolsTargetParamsBuilder<'a> {
1397    pub fn build(self) -> GetDevToolsTargetParams<'a> {
1398        GetDevToolsTargetParams {
1399            targetId: self.targetId,
1400        }
1401    }
1402}
1403
1404/// Gets the targetId of the DevTools page target opened for the given target
1405/// (if any).
1406
1407#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1408#[serde(rename_all = "camelCase")]
1409pub struct GetDevToolsTargetReturns<'a> {
1410    /// The targetId of DevTools page target if exists.
1411    #[serde(skip_serializing_if = "Option::is_none")]
1412    targetId: Option<TargetID<'a>>,
1413}
1414
1415impl<'a> GetDevToolsTargetReturns<'a> {
1416    pub fn builder() -> GetDevToolsTargetReturnsBuilder<'a> {
1417        GetDevToolsTargetReturnsBuilder {
1418            targetId: None,
1419        }
1420    }
1421    pub fn targetId(&self) -> Option<&TargetID<'a>> { self.targetId.as_ref() }
1422}
1423
1424#[derive(Default)]
1425pub struct GetDevToolsTargetReturnsBuilder<'a> {
1426    targetId: Option<TargetID<'a>>,
1427}
1428
1429impl<'a> GetDevToolsTargetReturnsBuilder<'a> {
1430    /// The targetId of DevTools page target if exists.
1431    pub fn targetId(mut self, targetId: TargetID<'a>) -> Self { self.targetId = Some(targetId); self }
1432    pub fn build(self) -> GetDevToolsTargetReturns<'a> {
1433        GetDevToolsTargetReturns {
1434            targetId: self.targetId,
1435        }
1436    }
1437}
1438
1439impl<'a> GetDevToolsTargetParams<'a> { pub const METHOD: &'static str = "Target.getDevToolsTarget"; }
1440
1441impl<'a> crate::CdpCommand<'a> for GetDevToolsTargetParams<'a> {
1442    const METHOD: &'static str = "Target.getDevToolsTarget";
1443    type Response = GetDevToolsTargetReturns<'a>;
1444}
1445
1446/// Opens a DevTools window for the target.
1447
1448#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1449#[serde(rename_all = "camelCase")]
1450pub struct OpenDevToolsParams<'a> {
1451    /// This can be the page or tab target ID.
1452    targetId: TargetID<'a>,
1453    /// The id of the panel we want DevTools to open initially. Currently
1454    /// supported panels are elements, console, network, sources, resources
1455    /// and performance.
1456    #[serde(skip_serializing_if = "Option::is_none")]
1457    panelId: Option<Cow<'a, str>>,
1458}
1459
1460impl<'a> OpenDevToolsParams<'a> {
1461    pub fn builder(targetId: TargetID<'a>) -> OpenDevToolsParamsBuilder<'a> {
1462        OpenDevToolsParamsBuilder {
1463            targetId: targetId,
1464            panelId: None,
1465        }
1466    }
1467    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
1468    pub fn panelId(&self) -> Option<&str> { self.panelId.as_deref() }
1469}
1470
1471
1472pub struct OpenDevToolsParamsBuilder<'a> {
1473    targetId: TargetID<'a>,
1474    panelId: Option<Cow<'a, str>>,
1475}
1476
1477impl<'a> OpenDevToolsParamsBuilder<'a> {
1478    /// The id of the panel we want DevTools to open initially. Currently
1479    /// supported panels are elements, console, network, sources, resources
1480    /// and performance.
1481    pub fn panelId(mut self, panelId: impl Into<Cow<'a, str>>) -> Self { self.panelId = Some(panelId.into()); self }
1482    pub fn build(self) -> OpenDevToolsParams<'a> {
1483        OpenDevToolsParams {
1484            targetId: self.targetId,
1485            panelId: self.panelId,
1486        }
1487    }
1488}
1489
1490/// Opens a DevTools window for the target.
1491
1492#[derive(Debug, Clone, Serialize, Deserialize, Default)]
1493#[serde(rename_all = "camelCase")]
1494pub struct OpenDevToolsReturns<'a> {
1495    /// The targetId of DevTools page target.
1496    targetId: TargetID<'a>,
1497}
1498
1499impl<'a> OpenDevToolsReturns<'a> {
1500    pub fn builder(targetId: TargetID<'a>) -> OpenDevToolsReturnsBuilder<'a> {
1501        OpenDevToolsReturnsBuilder {
1502            targetId: targetId,
1503        }
1504    }
1505    pub fn targetId(&self) -> &TargetID<'a> { &self.targetId }
1506}
1507
1508
1509pub struct OpenDevToolsReturnsBuilder<'a> {
1510    targetId: TargetID<'a>,
1511}
1512
1513impl<'a> OpenDevToolsReturnsBuilder<'a> {
1514    pub fn build(self) -> OpenDevToolsReturns<'a> {
1515        OpenDevToolsReturns {
1516            targetId: self.targetId,
1517        }
1518    }
1519}
1520
1521impl<'a> OpenDevToolsParams<'a> { pub const METHOD: &'static str = "Target.openDevTools"; }
1522
1523impl<'a> crate::CdpCommand<'a> for OpenDevToolsParams<'a> {
1524    const METHOD: &'static str = "Target.openDevTools";
1525    type Response = OpenDevToolsReturns<'a>;
1526}