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