Skip to main content

playhard_cdp/
protocol.rs

1use serde::{Deserialize, Serialize};
2
3/// Browser version payload.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct BrowserVersion {
6    /// Protocol version exposed by the browser.
7    #[serde(rename = "protocolVersion")]
8    pub protocol_version: String,
9    /// Browser product string.
10    pub product: String,
11    /// Browser revision.
12    pub revision: String,
13    /// User agent string.
14    #[serde(rename = "userAgent")]
15    pub user_agent: String,
16    /// JavaScript engine version.
17    #[serde(rename = "jsVersion")]
18    pub js_version: String,
19}
20
21/// Typed result for `Browser.getVersion`.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23pub struct BrowserGetVersionResult {
24    /// Browser version details.
25    pub version: BrowserVersion,
26}
27
28/// Typed params for `Browser.getVersion`.
29#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
30pub struct BrowserGetVersionParams {}
31
32/// Typed params for `Target.createTarget`.
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34pub struct TargetCreateTargetParams {
35    /// The target url.
36    pub url: String,
37    /// Whether the browser should open a new window.
38    #[serde(rename = "newWindow", skip_serializing_if = "Option::is_none")]
39    pub new_window: Option<bool>,
40}
41
42/// Typed result for `Target.createTarget`.
43#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44pub struct TargetCreateTargetResult {
45    /// Created target id.
46    #[serde(rename = "targetId")]
47    pub target_id: String,
48}
49
50/// Typed params for `Target.attachToTarget`.
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct TargetAttachToTargetParams {
53    /// Target id to attach to.
54    #[serde(rename = "targetId")]
55    pub target_id: String,
56    /// Whether the attachment should be flattened.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub flatten: Option<bool>,
59}
60
61/// Typed result for `Target.attachToTarget`.
62#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
63pub struct TargetAttachToTargetResult {
64    /// Session id for the attached target.
65    #[serde(rename = "sessionId")]
66    pub session_id: String,
67}
68
69/// Typed params for `Target.setAutoAttach`.
70#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
71pub struct TargetSetAutoAttachParams {
72    /// Whether targets should be auto-attached.
73    #[serde(rename = "autoAttach")]
74    pub auto_attach: bool,
75    /// Whether new targets should pause immediately after attachment.
76    #[serde(rename = "waitForDebuggerOnStart")]
77    pub wait_for_debugger_on_start: bool,
78    /// Whether flattened session mode should be used.
79    pub flatten: bool,
80}
81
82/// Typed params for `Target.setDiscoverTargets`.
83#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
84pub struct TargetSetDiscoverTargetsParams {
85    /// Whether Chrome should emit target discovery events.
86    pub discover: bool,
87}
88
89/// Typed params for `Page.enable`.
90#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
91pub struct PageEnableParams {}
92
93/// Typed params for `Page.setLifecycleEventsEnabled`.
94#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
95pub struct PageSetLifecycleEventsEnabledParams {
96    /// Whether lifecycle events should be emitted.
97    pub enabled: bool,
98}
99
100/// Typed params for `Runtime.enable`.
101#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
102pub struct RuntimeEnableParams {}
103
104/// Typed params for `Network.enable`.
105#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
106pub struct NetworkEnableParams {}
107
108/// Typed params for `Page.navigate`.
109#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
110pub struct PageNavigateParams {
111    /// Destination URL.
112    pub url: String,
113}
114
115/// Typed result for `Page.navigate`.
116#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
117pub struct PageNavigateResult {
118    /// Frame id, when available.
119    #[serde(rename = "frameId", skip_serializing_if = "Option::is_none")]
120    pub frame_id: Option<String>,
121    /// Loader id, when available.
122    #[serde(rename = "loaderId", skip_serializing_if = "Option::is_none")]
123    pub loader_id: Option<String>,
124}
125
126/// Page frame metadata.
127#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
128pub struct PageFrame {
129    /// Frame id.
130    pub id: String,
131    /// Parent frame id, when present.
132    #[serde(rename = "parentId", skip_serializing_if = "Option::is_none")]
133    pub parent_id: Option<String>,
134    /// Loader id, when present.
135    #[serde(rename = "loaderId", skip_serializing_if = "Option::is_none")]
136    pub loader_id: Option<String>,
137    /// Security origin.
138    #[serde(rename = "securityOrigin", skip_serializing_if = "Option::is_none")]
139    pub security_origin: Option<String>,
140    /// MIME type, when known.
141    #[serde(rename = "mimeType", skip_serializing_if = "Option::is_none")]
142    pub mime_type: Option<String>,
143    /// Frame name, when present.
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub name: Option<String>,
146    /// Current frame URL.
147    pub url: String,
148}
149
150/// Recursive frame tree payload.
151#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
152pub struct PageFrameTree {
153    /// The current frame.
154    pub frame: PageFrame,
155    /// Child frames.
156    #[serde(rename = "childFrames", default, skip_serializing_if = "Vec::is_empty")]
157    pub child_frames: Vec<PageFrameTree>,
158}
159
160/// Typed params for `Page.getFrameTree`.
161#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
162pub struct PageGetFrameTreeParams {}
163
164/// Typed result for `Page.getFrameTree`.
165#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
166pub struct PageGetFrameTreeResult {
167    /// The root frame tree.
168    #[serde(rename = "frameTree")]
169    pub frame_tree: PageFrameTree,
170}
171
172/// Typed params for `Page.createIsolatedWorld`.
173#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
174pub struct PageCreateIsolatedWorldParams {
175    /// Frame id that should receive the world.
176    #[serde(rename = "frameId")]
177    pub frame_id: String,
178    /// Optional world name.
179    #[serde(rename = "worldName", skip_serializing_if = "Option::is_none")]
180    pub world_name: Option<String>,
181    /// Whether access to the command line API should be granted.
182    #[serde(
183        rename = "grantUniveralAccess",
184        skip_serializing_if = "Option::is_none"
185    )]
186    pub grant_universal_access: Option<bool>,
187}
188
189/// Typed result for `Page.createIsolatedWorld`.
190#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
191pub struct PageCreateIsolatedWorldResult {
192    /// Execution context id for the new world.
193    #[serde(rename = "executionContextId")]
194    pub execution_context_id: i64,
195}
196
197/// Typed params for `Runtime.evaluate`.
198#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
199pub struct RuntimeEvaluateParams {
200    /// JavaScript expression to evaluate.
201    pub expression: String,
202    /// Await promise resolution before returning.
203    #[serde(rename = "awaitPromise", skip_serializing_if = "Option::is_none")]
204    pub await_promise: Option<bool>,
205    /// Return a JSON-serializable result by value.
206    #[serde(rename = "returnByValue", skip_serializing_if = "Option::is_none")]
207    pub return_by_value: Option<bool>,
208    /// Execution context id to target, when evaluating outside the main world.
209    #[serde(rename = "contextId", skip_serializing_if = "Option::is_none")]
210    pub context_id: Option<i64>,
211}
212
213/// Remote object returned by `Runtime.evaluate`.
214#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
215pub struct RemoteObject {
216    /// Remote object type.
217    #[serde(rename = "type")]
218    pub object_type: String,
219    /// String representation, if present.
220    #[serde(skip_serializing_if = "Option::is_none")]
221    pub description: Option<String>,
222    /// Remote object subtype, when present.
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub subtype: Option<String>,
225    /// Remote object id, when the result is kept remotely.
226    #[serde(rename = "objectId", skip_serializing_if = "Option::is_none")]
227    pub object_id: Option<String>,
228    /// JSON value representation.
229    #[serde(rename = "value", skip_serializing_if = "Option::is_none")]
230    pub value: Option<serde_json::Value>,
231}
232
233/// Typed result for `Runtime.evaluate`.
234#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
235pub struct RuntimeEvaluateResult {
236    /// Evaluation result.
237    pub result: RemoteObject,
238}
239
240/// Call argument for `Runtime.callFunctionOn`.
241#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
242pub struct RuntimeCallArgument {
243    /// Call argument value.
244    #[serde(skip_serializing_if = "Option::is_none")]
245    pub value: Option<serde_json::Value>,
246    /// Remote object id reference.
247    #[serde(rename = "objectId", skip_serializing_if = "Option::is_none")]
248    pub object_id: Option<String>,
249}
250
251/// Typed params for `Runtime.callFunctionOn`.
252#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
253pub struct RuntimeCallFunctionOnParams {
254    /// Target remote object id.
255    #[serde(rename = "objectId")]
256    pub object_id: String,
257    /// JavaScript function declaration.
258    #[serde(rename = "functionDeclaration")]
259    pub function_declaration: String,
260    /// Optional call arguments.
261    #[serde(default, skip_serializing_if = "Vec::is_empty")]
262    pub arguments: Vec<RuntimeCallArgument>,
263    /// Await promise resolution before returning.
264    #[serde(rename = "awaitPromise", skip_serializing_if = "Option::is_none")]
265    pub await_promise: Option<bool>,
266    /// Return a JSON-serializable result by value.
267    #[serde(rename = "returnByValue", skip_serializing_if = "Option::is_none")]
268    pub return_by_value: Option<bool>,
269}
270
271/// Typed result for `Runtime.callFunctionOn`.
272#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
273pub struct RuntimeCallFunctionOnResult {
274    /// Function call result.
275    pub result: RemoteObject,
276}
277
278/// Typed params for `Runtime.releaseObject`.
279#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
280pub struct RuntimeReleaseObjectParams {
281    /// Remote object id to release.
282    #[serde(rename = "objectId")]
283    pub object_id: String,
284}
285
286/// Typed params for `Page.captureScreenshot`.
287#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
288pub struct PageCaptureScreenshotParams {
289    /// Screenshot format.
290    #[serde(skip_serializing_if = "Option::is_none")]
291    pub format: Option<String>,
292}
293
294/// Typed result for `Page.captureScreenshot`.
295#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
296pub struct PageCaptureScreenshotResult {
297    /// Base64 encoded screenshot bytes.
298    pub data: String,
299}
300
301/// Typed params for `Input.dispatchKeyEvent`.
302#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
303pub struct InputDispatchKeyEventParams {
304    /// Event type.
305    #[serde(rename = "type")]
306    pub event_type: String,
307    /// Key value.
308    pub key: String,
309    /// Code value.
310    pub code: String,
311    /// Text payload, when present.
312    #[serde(skip_serializing_if = "Option::is_none")]
313    pub text: Option<String>,
314    /// Unmodified text payload, when present.
315    #[serde(rename = "unmodifiedText", skip_serializing_if = "Option::is_none")]
316    pub unmodified_text: Option<String>,
317    /// Windows virtual key code.
318    #[serde(rename = "windowsVirtualKeyCode")]
319    pub windows_virtual_key_code: i64,
320    /// Native virtual key code.
321    #[serde(rename = "nativeVirtualKeyCode")]
322    pub native_virtual_key_code: i64,
323}
324
325/// Typed params for `Input.insertText`.
326#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
327pub struct InputInsertTextParams {
328    /// Text to insert into the focused element.
329    pub text: String,
330}
331
332/// Typed params for `Fetch.enable`.
333#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
334pub struct FetchEnableParams {
335    /// Interception patterns.
336    #[serde(skip_serializing_if = "Option::is_none")]
337    pub patterns: Option<Vec<FetchPattern>>,
338}
339
340/// Typed fetch request pattern.
341#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
342pub struct FetchPattern {
343    /// URL pattern.
344    #[serde(rename = "urlPattern", skip_serializing_if = "Option::is_none")]
345    pub url_pattern: Option<String>,
346    /// Request stage.
347    #[serde(rename = "requestStage", skip_serializing_if = "Option::is_none")]
348    pub request_stage: Option<String>,
349}
350
351/// Typed fetch response header entry.
352#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
353pub struct FetchHeaderEntry {
354    /// Header name.
355    pub name: String,
356    /// Header value.
357    pub value: String,
358}
359
360/// Typed params for `Fetch.continueRequest`.
361#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
362pub struct FetchContinueRequestParams {
363    /// Request id.
364    #[serde(rename = "requestId")]
365    pub request_id: String,
366}
367
368/// Typed params for `Fetch.fulfillRequest`.
369#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
370pub struct FetchFulfillRequestParams {
371    /// Request id.
372    #[serde(rename = "requestId")]
373    pub request_id: String,
374    /// Response code.
375    #[serde(rename = "responseCode")]
376    pub response_code: u16,
377    /// Optional response headers.
378    #[serde(rename = "responseHeaders", skip_serializing_if = "Option::is_none")]
379    pub response_headers: Option<Vec<FetchHeaderEntry>>,
380    /// Optional response body.
381    #[serde(skip_serializing_if = "Option::is_none")]
382    pub body: Option<String>,
383    /// Optional response phrase.
384    #[serde(rename = "responsePhrase", skip_serializing_if = "Option::is_none")]
385    pub response_phrase: Option<String>,
386}
387
388/// Typed params for `Fetch.failRequest`.
389#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
390pub struct FetchFailRequestParams {
391    /// Request id.
392    #[serde(rename = "requestId")]
393    pub request_id: String,
394    /// Error reason.
395    #[serde(rename = "errorReason")]
396    pub error_reason: String,
397}
398
399/// Typed params for `Fetch.getResponseBody`.
400#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
401pub struct FetchGetResponseBodyParams {
402    /// Request id.
403    #[serde(rename = "requestId")]
404    pub request_id: String,
405}
406
407/// Typed result for `Fetch.getResponseBody`.
408#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
409pub struct FetchGetResponseBodyResult {
410    /// Response body payload.
411    pub body: String,
412    /// Whether the payload is base64 encoded.
413    #[serde(rename = "base64Encoded")]
414    pub base64_encoded: bool,
415}