viewpoint_cdp/protocol/target_domain/
mod.rs

1//! Target domain types.
2//!
3//! The Target domain supports inspecting, attaching to, and managing Chrome targets.
4
5use serde::{Deserialize, Serialize};
6
7/// Information about a target.
8#[derive(Debug, Clone, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct TargetInfo {
11    /// Target identifier.
12    pub target_id: String,
13    /// Target type (e.g., "page", "`background_page`", "`service_worker`").
14    #[serde(rename = "type")]
15    pub target_type: String,
16    /// Target title.
17    pub title: String,
18    /// Target URL.
19    pub url: String,
20    /// Whether the target is attached.
21    pub attached: bool,
22    /// Browser context ID if this target belongs to a context.
23    pub browser_context_id: Option<String>,
24    /// Opener target ID (the target that opened this one, for popups).
25    pub opener_id: Option<String>,
26}
27
28/// Parameters for Target.createBrowserContext.
29#[derive(Debug, Clone, Serialize, Default)]
30#[serde(rename_all = "camelCase")]
31pub struct CreateBrowserContextParams {
32    /// Whether to create a context without any proxy.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub dispose_on_detach: Option<bool>,
35    /// Proxy server, e.g., "<http://proxy.example.com:8080>".
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub proxy_server: Option<String>,
38    /// Bypass list for the proxy.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub proxy_bypass_list: Option<String>,
41}
42
43/// Result of Target.createBrowserContext.
44#[derive(Debug, Clone, Deserialize)]
45#[serde(rename_all = "camelCase")]
46pub struct CreateBrowserContextResult {
47    /// Browser context ID.
48    pub browser_context_id: String,
49}
50
51/// Parameters for Target.disposeBrowserContext.
52#[derive(Debug, Clone, Serialize)]
53#[serde(rename_all = "camelCase")]
54pub struct DisposeBrowserContextParams {
55    /// Browser context ID to dispose.
56    pub browser_context_id: String,
57}
58
59/// Parameters for Target.createTarget.
60#[derive(Debug, Clone, Serialize)]
61#[serde(rename_all = "camelCase")]
62pub struct CreateTargetParams {
63    /// The initial URL the page will be navigated to.
64    pub url: String,
65    /// Frame width in pixels. Browser-controlled if unset.
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub width: Option<u32>,
68    /// Frame height in pixels. Browser-controlled if unset.
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub height: Option<u32>,
71    /// Browser context to create the page in.
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub browser_context_id: Option<String>,
74    /// Whether to begin with background tab.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub background: Option<bool>,
77    /// Whether to create a new window.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub new_window: Option<bool>,
80}
81
82/// Result of Target.createTarget.
83#[derive(Debug, Clone, Deserialize)]
84#[serde(rename_all = "camelCase")]
85pub struct CreateTargetResult {
86    /// The ID of the created target.
87    pub target_id: String,
88}
89
90/// Parameters for Target.attachToTarget.
91#[derive(Debug, Clone, Serialize)]
92#[serde(rename_all = "camelCase")]
93pub struct AttachToTargetParams {
94    /// Target ID to attach to.
95    pub target_id: String,
96    /// Enables "flat" access to the session via specifying sessionId.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub flatten: Option<bool>,
99}
100
101/// Result of Target.attachToTarget.
102#[derive(Debug, Clone, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct AttachToTargetResult {
105    /// Session ID for the attached target.
106    pub session_id: String,
107}
108
109/// Parameters for Target.closeTarget.
110#[derive(Debug, Clone, Serialize)]
111#[serde(rename_all = "camelCase")]
112pub struct CloseTargetParams {
113    /// Target ID to close.
114    pub target_id: String,
115}
116
117/// Result of Target.closeTarget.
118#[derive(Debug, Clone, Deserialize)]
119pub struct CloseTargetResult {
120    /// Whether the target was closed successfully.
121    pub success: bool,
122}
123
124/// Parameters for Target.detachFromTarget.
125#[derive(Debug, Clone, Serialize)]
126#[serde(rename_all = "camelCase")]
127pub struct DetachFromTargetParams {
128    /// Session ID to detach from.
129    #[serde(skip_serializing_if = "Option::is_none")]
130    pub session_id: Option<String>,
131}
132
133/// Parameters for Target.getTargets.
134#[derive(Debug, Clone, Serialize, Default)]
135pub struct GetTargetsParams {
136    /// Filter targets by their types.
137    #[serde(skip_serializing_if = "Option::is_none")]
138    pub filter: Option<Vec<TargetFilter>>,
139}
140
141/// Target filter for getTargets.
142#[derive(Debug, Clone, Serialize)]
143#[serde(rename_all = "camelCase")]
144pub struct TargetFilter {
145    /// Target type to filter.
146    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
147    pub target_type: Option<String>,
148    /// Whether to exclude the target.
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub exclude: Option<bool>,
151}
152
153/// Result of Target.getTargets.
154#[derive(Debug, Clone, Deserialize)]
155#[serde(rename_all = "camelCase")]
156pub struct GetTargetsResult {
157    /// List of targets.
158    pub target_infos: Vec<TargetInfo>,
159}
160
161/// Result of Target.getBrowserContexts.
162#[derive(Debug, Clone, Deserialize)]
163#[serde(rename_all = "camelCase")]
164pub struct GetBrowserContextsResult {
165    /// List of browser context IDs.
166    pub browser_context_ids: Vec<String>,
167}
168
169/// Event: Target.targetCreated
170#[derive(Debug, Clone, Deserialize)]
171#[serde(rename_all = "camelCase")]
172pub struct TargetCreatedEvent {
173    /// Target info.
174    pub target_info: TargetInfo,
175}
176
177/// Event: Target.targetDestroyed
178#[derive(Debug, Clone, Deserialize)]
179#[serde(rename_all = "camelCase")]
180pub struct TargetDestroyedEvent {
181    /// Target ID.
182    pub target_id: String,
183}
184
185/// Event: Target.attachedToTarget
186#[derive(Debug, Clone, Deserialize)]
187#[serde(rename_all = "camelCase")]
188pub struct AttachedToTargetEvent {
189    /// Session ID.
190    pub session_id: String,
191    /// Target info.
192    pub target_info: TargetInfo,
193    /// Whether waiting for debugger.
194    pub waiting_for_debugger: bool,
195}