1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
4pub struct OpenArgs {
5 pub url: String,
6 pub headers: Option<serde_json::Value>,
7 pub user_agent: Option<String>,
8 #[serde(default)]
9 pub bypass_csp: bool,
10 pub inject_js: Option<String>,
11 pub load_state: Option<String>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
15pub struct SnapshotArgs {
16 #[serde(default)]
17 pub interactive: bool,
18 #[serde(default)]
19 pub all: bool,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
23pub struct ObserveArgs {
24 #[schemars(
25 description = "Filter: 'inputs' for form elements, 'buttons' for buttons and links, or 'all' for all observed elements."
26 )]
27 pub filter: Option<String>,
28 #[schemars(description = "Maximum elements to return.")]
29 pub max: Option<usize>,
30 #[serde(default)]
31 pub structured: bool,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
35pub struct ScreenshotArgs {
36 pub output: Option<String>,
37 #[serde(default)]
38 pub annotate: bool,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
42pub struct EmulateArgs {
43 #[serde(default = "default_viewport_width")]
44 pub width: u32,
45 #[serde(default = "default_viewport_height")]
46 pub height: u32,
47 #[serde(default = "default_device_pixel_ratio")]
48 pub dpr: f64,
49 #[serde(default)]
50 pub desktop: bool,
51 #[serde(default)]
52 pub reset: bool,
53}
54
55impl Default for EmulateArgs {
56 fn default() -> Self {
57 Self {
58 width: default_viewport_width(),
59 height: default_viewport_height(),
60 dpr: default_device_pixel_ratio(),
61 desktop: false,
62 reset: false,
63 }
64 }
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
68pub struct TextArgs {
69 #[schemars(description = "Text substring to search for, matched case-insensitively.")]
70 pub text: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
74pub struct TargetArgs {
75 #[schemars(
76 description = "Target element. Supports index, snapshot refs like @e1, text:Submit, placeholder:Email, role:button, css:form button, id:my-btn, or plain text search."
77 )]
78 pub target: String,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
82pub struct FillArgs {
83 #[schemars(
84 description = "Target input. Supports index, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
85 )]
86 pub target: String,
87 #[schemars(description = "Text to type into the element.")]
88 pub text: String,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
92pub struct SelectArgs {
93 #[schemars(description = "Target select element by index, text, CSS selector, id, or role.")]
94 pub target: String,
95 #[schemars(description = "Option value or visible text to select.")]
96 pub value: String,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
100pub struct KeyArgs {
101 #[schemars(
102 description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
103 )]
104 pub key: String,
105}
106
107#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
108#[serde(rename_all = "lowercase")]
109pub enum MouseButton {
110 Left,
111 Middle,
112 Right,
113 Back,
114 Forward,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
118pub struct MouseButtonArgs {
119 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
120 pub x: f64,
121 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
122 pub y: f64,
123 #[schemars(description = "Mouse button to hold or release.")]
124 pub button: MouseButton,
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
128pub struct MouseMoveArgs {
129 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
130 pub x: f64,
131 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
132 pub y: f64,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
136pub struct ScriptArgs {
137 pub code: Option<String>,
138 pub file: Option<String>,
139 pub max_size: Option<usize>,
140 #[serde(default)]
141 pub no_await: bool,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
145pub struct FrameEvalArgs {
146 #[schemars(description = "CSS selector for the iframe in the active page.")]
147 pub frame: String,
148 pub code: Option<String>,
149 pub file: Option<String>,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
153pub struct FetchArgs {
154 pub url: String,
155 pub method: Option<String>,
156 pub headers: Option<serde_json::Value>,
157 pub body: Option<String>,
158 pub redirect: Option<String>,
159 #[serde(default)]
160 pub body_only: bool,
161 pub max_body: Option<usize>,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
165pub struct SetCookieArgs {
166 pub name: String,
167 pub value: String,
168 pub domain: Option<String>,
169 pub path: Option<String>,
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
173pub struct DeleteCookieArgs {
174 pub name: String,
175 pub domain: Option<String>,
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
179pub struct StorageArgs {
180 pub key: Option<String>,
181 #[serde(default)]
182 pub session_storage: bool,
183}
184
185#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
186pub struct SetStorageArgs {
187 pub key: String,
188 pub value: String,
189 #[serde(default)]
190 pub session_storage: bool,
191}
192
193#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
194pub struct PathArgs {
195 #[schemars(description = "File path.")]
196 pub path: String,
197}
198
199#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
200pub struct LoadStateArgs {
201 pub path: String,
202 #[serde(default)]
203 pub no_navigate: bool,
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
207pub struct HeadersArgs {
208 pub headers_json: String,
209}
210
211#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
212pub struct ConsoleArgs {
213 #[serde(default)]
214 pub clear: bool,
215 pub level: Option<String>,
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
219pub struct ClearFlagArgs {
220 #[serde(default)]
221 pub clear: bool,
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
225pub struct TabNewArgs {
226 #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
227 pub url: Option<String>,
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
231pub struct TabIdArgs {
232 #[schemars(description = "Tab ID from list_tabs.")]
233 pub tab_id: String,
234}
235
236#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
237pub struct CloneFromArgs {
238 pub source: String,
239 pub to: Option<String>,
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
243pub struct WaitArgs {
244 pub ms: Option<u64>,
245 pub text: Option<String>,
246 pub url: Option<String>,
247 pub load: Option<String>,
248 pub timeout: Option<u64>,
249}
250
251#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
252pub struct PathStringArgs {
253 #[schemars(description = "Target path, for example /docs or /about.")]
254 pub path: String,
255}
256
257#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
258pub struct FakeCameraArgs {
259 pub file: String,
260 #[serde(default)]
261 pub loop_video: bool,
262}
263
264#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
265pub struct WasmReadArgs {
266 pub addr: String,
267 pub len: usize,
268 pub memory: Option<String>,
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
272pub struct WasmWriteArgs {
273 pub addr: String,
274 pub hex: String,
275 pub memory: Option<String>,
276}
277
278#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
279pub struct WasmFindArgs {
280 pub pattern: String,
281 pub start: Option<String>,
282 pub end: Option<String>,
283 #[serde(default = "default_wasm_find_max")]
284 pub max: usize,
285 pub memory: Option<String>,
286}
287
288impl Default for WasmFindArgs {
289 fn default() -> Self {
290 Self {
291 pattern: String::new(),
292 start: None,
293 end: None,
294 max: default_wasm_find_max(),
295 memory: None,
296 }
297 }
298}
299
300#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
301pub struct InterceptAddArgs {
302 pub url_pattern: String,
303 pub capture: Option<String>,
304 pub respond: Option<String>,
305 #[serde(default = "default_intercept_status")]
306 pub status: u16,
307}
308
309impl Default for InterceptAddArgs {
310 fn default() -> Self {
311 Self {
312 url_pattern: String::new(),
313 capture: None,
314 respond: None,
315 status: default_intercept_status(),
316 }
317 }
318}
319
320#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
321pub struct IdArgs {
322 pub id: String,
323}
324
325#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
326pub struct ModeArgs {
327 pub mode: String,
328}
329
330#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
331pub struct DomainArgs {
332 pub domain: String,
333}
334
335#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
336pub struct CaptchaInjectArgs {
337 pub token: String,
338 #[serde(default = "default_captcha_type")]
339 pub captcha_type: String,
340 pub callback: Option<String>,
341 pub click_after: Option<String>,
342}
343
344#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
345pub struct NetworkRecordStartArgs {
346 #[serde(default)]
347 pub patterns: Vec<String>,
348 #[serde(default)]
349 pub no_bodies: bool,
350 #[serde(default = "default_max_body_bytes")]
351 pub max_body_bytes: usize,
352 #[serde(default)]
353 pub clear: bool,
354}
355
356#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
357pub struct NetworkLogArgs {
358 pub limit: Option<usize>,
359 pub pattern: Option<String>,
360 pub method: Option<String>,
361 pub status: Option<u16>,
362 pub since: Option<u64>,
363 #[serde(default)]
364 pub compact: bool,
365}
366
367#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
368pub struct NetworkShowArgs {
369 pub id: u64,
370 #[serde(default)]
371 pub body: bool,
372 pub max_body: Option<usize>,
373}
374
375#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
376pub struct NetworkWaitArgs {
377 pub pattern: Option<String>,
378 pub method: Option<String>,
379 pub status: Option<u16>,
380 pub timeout: Option<u64>,
381 pub since: Option<u64>,
382 #[serde(default)]
383 pub include_existing: bool,
384}
385
386#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
387pub struct NetworkExportArgs {
388 pub path: String,
389 #[serde(default = "default_network_export_format")]
390 pub format: String,
391 pub settle_ms: Option<u64>,
392}
393
394impl Default for NetworkExportArgs {
395 fn default() -> Self {
396 Self {
397 path: String::new(),
398 format: default_network_export_format(),
399 settle_ms: None,
400 }
401 }
402}
403
404fn default_max_body_bytes() -> usize {
405 10 * 1024 * 1024
406}
407
408fn default_network_export_format() -> String {
409 "har".to_string()
410}
411
412fn default_viewport_width() -> u32 {
413 390
414}
415
416fn default_viewport_height() -> u32 {
417 844
418}
419
420fn default_device_pixel_ratio() -> f64 {
421 2.0
422}
423
424fn default_wasm_find_max() -> usize {
425 20
426}
427
428fn default_intercept_status() -> u16 {
429 200
430}
431
432fn default_captcha_type() -> String {
433 "auto".to_string()
434}