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 #[serde(flatten)]
76 pub operation: crate::ActionSettings,
77 #[schemars(
78 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."
79 )]
80 pub target: String,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
84pub struct FillArgs {
85 #[serde(flatten)]
86 pub operation: crate::ActionSettings,
87 #[schemars(
88 description = "Target input. Supports index, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
89 )]
90 pub target: String,
91 #[schemars(description = "Text to type into the element.")]
92 pub text: String,
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
96pub struct SelectArgs {
97 #[serde(flatten)]
98 pub operation: crate::ActionSettings,
99 #[schemars(description = "Target select element by index, text, CSS selector, id, or role.")]
100 pub target: String,
101 #[schemars(description = "Option value or visible text to select.")]
102 pub value: String,
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
106pub struct KeyArgs {
107 #[serde(flatten)]
108 pub operation: crate::ActionSettings,
109 #[schemars(
110 description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
111 )]
112 pub key: String,
113}
114
115#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
116#[serde(rename_all = "lowercase")]
117pub enum MouseButton {
118 Left,
119 Middle,
120 Right,
121 Back,
122 Forward,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
126pub struct MouseButtonArgs {
127 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
128 pub x: f64,
129 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
130 pub y: f64,
131 #[schemars(description = "Mouse button to hold or release.")]
132 pub button: MouseButton,
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
136pub struct MouseMoveArgs {
137 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
138 pub x: f64,
139 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
140 pub y: f64,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
144pub struct ScriptArgs {
145 pub code: Option<String>,
146 pub file: Option<String>,
147 pub max_size: Option<usize>,
148 #[serde(default)]
149 pub no_await: bool,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
153pub struct FrameEvalArgs {
154 #[schemars(
155 description = "CSS selector matching exactly one iframe/frame in the top document, or id:<frame-id> from frames for explicit/nested selection. Bare URLs and indices are not supported. Evaluation uses an isolated world, not page-owned JavaScript globals."
156 )]
157 pub frame: String,
158 pub code: Option<String>,
159 pub file: Option<String>,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
163pub struct FetchArgs {
164 pub url: String,
165 pub method: Option<String>,
166 pub headers: Option<serde_json::Value>,
167 pub body: Option<String>,
168 pub redirect: Option<String>,
169 #[serde(default)]
170 pub body_only: bool,
171 #[schemars(
172 description = "Raw text byte limit: default 8192, maximum 16777216; zero inspects headers only.",
173 range(max = 16777216)
174 )]
175 pub max_body: Option<usize>,
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
179pub struct SetCookieArgs {
180 pub name: String,
181 pub value: String,
182 pub domain: Option<String>,
183 pub path: Option<String>,
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
187pub struct DeleteCookieArgs {
188 pub name: String,
189 pub domain: Option<String>,
190}
191
192#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
193pub struct StorageArgs {
194 pub key: Option<String>,
195 #[serde(default)]
196 pub session_storage: bool,
197}
198
199#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
200pub struct SetStorageArgs {
201 pub key: String,
202 pub value: String,
203 #[serde(default)]
204 pub session_storage: bool,
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
208pub struct PathArgs {
209 #[schemars(description = "File path.")]
210 pub path: String,
211}
212
213#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
214pub struct LoadStateArgs {
215 pub path: String,
216 #[serde(default)]
217 pub no_navigate: bool,
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
221pub struct HeadersArgs {
222 pub headers_json: String,
223}
224
225#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
226pub struct ConsoleArgs {
227 #[serde(default)]
228 pub clear: bool,
229 pub level: Option<String>,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
233pub struct ClearFlagArgs {
234 #[serde(default)]
235 pub clear: bool,
236}
237
238#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
239pub struct TabNewArgs {
240 #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
241 pub url: Option<String>,
242}
243
244#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
245pub struct TabIdArgs {
246 #[schemars(description = "Tab ID from list_tabs.")]
247 pub tab_id: String,
248}
249
250#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
251pub struct CloneFromArgs {
252 pub source: String,
253 pub to: Option<String>,
254}
255
256#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
257pub struct WaitArgs {
258 pub ms: Option<u64>,
259 pub text: Option<String>,
260 pub url: Option<String>,
261 pub load: Option<String>,
262 pub timeout: Option<u64>,
263}
264
265#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
266pub struct PathStringArgs {
267 #[schemars(description = "Target path, for example /docs or /about.")]
268 pub path: String,
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
272pub struct FakeCameraArgs {
273 pub file: String,
274 #[serde(default)]
275 pub loop_video: bool,
276}
277
278#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
279pub struct WasmReadArgs {
280 pub addr: String,
281 pub len: usize,
282 pub memory: Option<String>,
283}
284
285#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
286pub struct WasmWriteArgs {
287 pub addr: String,
288 pub hex: String,
289 pub memory: Option<String>,
290}
291
292#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
293pub struct WasmFindArgs {
294 pub pattern: String,
295 pub start: Option<String>,
296 pub end: Option<String>,
297 #[serde(default = "default_wasm_find_max")]
298 pub max: usize,
299 pub memory: Option<String>,
300}
301
302impl Default for WasmFindArgs {
303 fn default() -> Self {
304 Self {
305 pattern: String::new(),
306 start: None,
307 end: None,
308 max: default_wasm_find_max(),
309 memory: None,
310 }
311 }
312}
313
314#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
315pub struct InterceptAddArgs {
316 pub url_pattern: String,
317 pub capture: Option<String>,
318 pub respond: Option<String>,
319 #[serde(default = "default_intercept_status")]
320 pub status: u16,
321}
322
323impl Default for InterceptAddArgs {
324 fn default() -> Self {
325 Self {
326 url_pattern: String::new(),
327 capture: None,
328 respond: None,
329 status: default_intercept_status(),
330 }
331 }
332}
333
334#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
335pub struct IdArgs {
336 pub id: String,
337}
338
339#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
340pub struct ModeArgs {
341 pub mode: String,
342}
343
344#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
345pub struct DomainArgs {
346 pub domain: String,
347}
348
349#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
350pub struct CaptchaInjectArgs {
351 pub token: String,
352 #[serde(default = "default_captcha_type")]
353 pub captcha_type: String,
354 pub callback: Option<String>,
355 pub click_after: Option<String>,
356}
357
358#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
359pub struct NetworkRecordStartArgs {
360 #[serde(default)]
361 pub patterns: Vec<String>,
362 #[serde(default)]
363 pub no_bodies: bool,
364 #[serde(default = "default_max_body_bytes")]
365 pub max_body_bytes: usize,
366 #[serde(default)]
367 pub clear: bool,
368}
369
370#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
371pub struct NetworkLogArgs {
372 pub limit: Option<usize>,
373 pub pattern: Option<String>,
374 pub method: Option<String>,
375 pub status: Option<u16>,
376 pub since: Option<u64>,
377 #[serde(default)]
378 pub compact: bool,
379}
380
381#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
382pub struct NetworkShowArgs {
383 pub id: u64,
384 #[serde(default)]
385 pub body: bool,
386 pub max_body: Option<usize>,
387}
388
389#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
390pub struct NetworkWaitArgs {
391 pub pattern: Option<String>,
392 pub method: Option<String>,
393 pub status: Option<u16>,
394 pub timeout: Option<u64>,
395 pub since: Option<u64>,
396 #[serde(default)]
397 pub include_existing: bool,
398}
399
400#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
401pub struct NetworkExportArgs {
402 pub path: String,
403 #[serde(default = "default_network_export_format")]
404 pub format: String,
405 pub settle_ms: Option<u64>,
406}
407
408impl Default for NetworkExportArgs {
409 fn default() -> Self {
410 Self {
411 path: String::new(),
412 format: default_network_export_format(),
413 settle_ms: None,
414 }
415 }
416}
417
418fn default_max_body_bytes() -> usize {
419 10 * 1024 * 1024
420}
421
422fn default_network_export_format() -> String {
423 "har".to_string()
424}
425
426fn default_viewport_width() -> u32 {
427 390
428}
429
430fn default_viewport_height() -> u32 {
431 844
432}
433
434fn default_device_pixel_ratio() -> f64 {
435 2.0
436}
437
438fn default_wasm_find_max() -> usize {
439 20
440}
441
442fn default_intercept_status() -> u16 {
443 200
444}
445
446fn default_captcha_type() -> String {
447 "auto".to_string()
448}