1use serde::{Deserialize, Serialize};
2
3#[cfg(feature = "clap")]
4pub const TARGET_HELP: &str =
5 "text:Submit (or bare text), placeholder:Email, css:#id, id:login, role:button, or a target from view";
6#[cfg(feature = "clap")]
7const WASM_ADDR_HELP: &str = "Address, decimal or 0x-prefixed hex";
8#[cfg(feature = "clap")]
9const WASM_MEMORY_HELP: &str =
10 "JavaScript expression for the WebAssembly.Memory [default: auto-detect]";
11#[cfg(feature = "clap")]
12pub(crate) const OPERATION_ID_HELP: &str = "Operation ID returned by the action";
13
14#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
15pub struct OpenArgs {
16 #[serde(flatten)]
17 pub operation: crate::ActionSettings,
18 pub url: String,
19 pub headers: Option<serde_json::Value>,
20 pub user_agent: Option<String>,
21 #[serde(default)]
22 pub bypass_csp: bool,
23 pub inject_js: Option<String>,
24 pub load_state: Option<String>,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
28#[cfg_attr(feature = "clap", derive(clap::Args))]
29pub struct SnapshotArgs {
30 #[cfg_attr(feature = "clap", arg(short, long, help = "Only interactive nodes"))]
31 #[serde(default)]
32 pub interactive: bool,
33 #[cfg_attr(
34 feature = "clap",
35 arg(long, help = "Keep decorative and empty text nodes")
36 )]
37 #[serde(default)]
38 pub all: bool,
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
42pub struct ObserveArgs {
43 #[schemars(
44 description = "Filter: 'inputs' for form elements, 'buttons' for buttons and links, or 'all' for all observed elements."
45 )]
46 pub filter: Option<String>,
47 #[schemars(description = "Maximum elements to return.")]
48 pub max: Option<usize>,
49 #[serde(default)]
50 pub structured: bool,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
54pub struct ScreenshotArgs {
55 pub output: Option<String>,
56 #[serde(default)]
57 pub annotate: bool,
58 #[serde(default)]
59 #[schemars(description = "Image format; PNG when omitted.")]
60 pub format: Option<crate::sidecar::ScreenshotFormat>,
61 #[serde(default)]
62 #[schemars(range(max = 100), description = "JPEG or WebP quality, 0 to 100.")]
63 pub quality: Option<u8>,
64 #[serde(default)]
65 #[schemars(description = "Document-relative CSS pixel region; conflicts with full_page.")]
66 pub clip: Option<crate::sidecar::ScreenshotClip>,
67 #[serde(default)]
68 #[schemars(description = "Capture the whole scrollable page instead of the viewport.")]
69 pub full_page: bool,
70 #[serde(default)]
71 #[schemars(
72 description = "Return the image as base64 dataBase64 instead of writing a file; conflicts with output."
73 )]
74 pub inline: bool,
75}
76
77impl ScreenshotArgs {
78 pub fn validate(&self) -> Result<(), crate::sidecar::ServerError> {
79 crate::sidecar::validate_screenshot(
80 self.format,
81 self.quality,
82 self.clip.as_ref(),
83 Some(self.full_page),
84 )?;
85 if self.inline && self.output.is_some() {
86 return Err(crate::sidecar::ServerError::invalid_params(
87 "inline cannot be combined with output",
88 ));
89 }
90 if self.annotate
91 && (self.format.is_some()
92 || self.quality.is_some()
93 || self.clip.is_some()
94 || self.full_page)
95 {
96 return Err(crate::sidecar::ServerError::invalid_params(
97 "annotate cannot be combined with format, quality, clip or full page",
98 ));
99 }
100 Ok(())
101 }
102
103 pub fn options(&self) -> eoka::ScreenshotOptions {
104 crate::sidecar::screenshot_options(
105 self.format,
106 self.quality,
107 self.clip.as_ref(),
108 Some(self.full_page),
109 )
110 }
111
112 pub fn mime_type(&self) -> &'static str {
113 match self.format.unwrap_or(crate::sidecar::ScreenshotFormat::Png) {
114 crate::sidecar::ScreenshotFormat::Png => "image/png",
115 crate::sidecar::ScreenshotFormat::Jpeg => "image/jpeg",
116 crate::sidecar::ScreenshotFormat::Webp => "image/webp",
117 }
118 }
119
120 pub fn extension(&self) -> &'static str {
121 match self.format.unwrap_or(crate::sidecar::ScreenshotFormat::Png) {
122 crate::sidecar::ScreenshotFormat::Png => "png",
123 crate::sidecar::ScreenshotFormat::Jpeg => "jpg",
124 crate::sidecar::ScreenshotFormat::Webp => "webp",
125 }
126 }
127}
128
129#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
130pub struct RecordingStartArgs {
131 #[schemars(description = "Absolute path of the MP4 file to write.")]
132 pub path: String,
133 #[serde(default)]
134 #[schemars(description = "UUID naming this recording; generated when omitted.")]
135 pub recording_id: Option<String>,
136 #[serde(default)]
137 pub max_width: Option<u32>,
138 #[serde(default)]
139 pub max_height: Option<u32>,
140 #[serde(default)]
141 #[schemars(range(min = 1, max = 120))]
142 pub fps: Option<u32>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
146pub struct RecordingIdArgs {
147 #[schemars(description = "Recording UUID returned by recording_start.")]
148 pub recording_id: String,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
152#[cfg_attr(feature = "clap", derive(clap::Args))]
153pub struct EmulateArgs {
154 #[cfg_attr(
155 feature = "clap",
156 arg(long, default_value = "390", help = "Viewport width in CSS pixels")
157 )]
158 #[serde(default = "default_viewport_width")]
159 pub width: u32,
160 #[cfg_attr(
161 feature = "clap",
162 arg(long, default_value = "844", help = "Viewport height in CSS pixels")
163 )]
164 #[serde(default = "default_viewport_height")]
165 pub height: u32,
166 #[cfg_attr(
167 feature = "clap",
168 arg(long, default_value = "2", help = "Device pixel ratio")
169 )]
170 #[serde(default = "default_device_pixel_ratio")]
171 pub dpr: f64,
172 #[cfg_attr(
173 feature = "clap",
174 arg(long, help = "Emulate a desktop instead of a touch mobile device")
175 )]
176 #[serde(default)]
177 pub desktop: bool,
178 #[cfg_attr(
179 feature = "clap",
180 arg(long, help = "Clear emulation and ignore the other flags")
181 )]
182 #[serde(default)]
183 pub reset: bool,
184}
185
186impl Default for EmulateArgs {
187 fn default() -> Self {
188 Self {
189 width: default_viewport_width(),
190 height: default_viewport_height(),
191 dpr: default_device_pixel_ratio(),
192 desktop: false,
193 reset: false,
194 }
195 }
196}
197
198#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
199#[cfg_attr(feature = "clap", derive(clap::Args))]
200pub struct TextArgs {
201 #[cfg_attr(feature = "clap", arg(help = "Text to search for"))]
202 #[schemars(description = "Text substring to search for, matched case-insensitively.")]
203 pub text: String,
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
207#[cfg_attr(feature = "clap", derive(clap::Args))]
208pub struct TargetArgs {
209 #[cfg_attr(feature = "clap", arg(skip))]
210 #[serde(flatten)]
211 pub operation: crate::ActionSettings,
212 #[cfg_attr(feature = "clap", arg(help = TARGET_HELP))]
213 #[schemars(
214 description = "Target element. Supports scoped refs from view, text:Submit, placeholder:Email, role:button, css:form button, id:my-btn, or plain text search."
215 )]
216 pub target: String,
217}
218
219#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
220pub struct ClickArgs {
221 #[serde(flatten)]
222 pub element: TargetArgs,
223 #[serde(default, skip_serializing_if = "Option::is_none")]
224 pub intercept_nav: Option<NavIntercept>,
225}
226
227#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
228#[serde(rename_all = "lowercase")]
229#[schemars(
230 description = "Install a history.pushState/replaceState diagnostic before the click and record the attempted navigation in window.__eoka_nav. block keeps the page where it is; allow lets the history change through. Requires expect; location navigation cannot be intercepted."
231)]
232pub enum NavIntercept {
233 Block,
234 Allow,
235}
236
237#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
238pub struct HistoryGoArgs {
239 #[serde(flatten)]
240 pub operation: crate::ActionSettings,
241 #[schemars(description = "History delta: -1 for back, 1 for forward, -2 for back twice, etc.")]
242 pub delta: i32,
243}
244
245#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
246pub struct FillArgs {
247 #[serde(flatten)]
248 pub operation: crate::ActionSettings,
249 #[schemars(
250 description = "Target input. Supports scoped refs from view, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
251 )]
252 pub target: String,
253 #[schemars(description = "Text to type into the element.")]
254 pub text: String,
255 #[serde(default)]
256 pub input_mode: crate::InputMode,
257}
258
259#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
260#[cfg_attr(feature = "clap", derive(clap::Args))]
261pub struct SelectArgs {
262 #[cfg_attr(feature = "clap", arg(skip))]
263 #[serde(flatten)]
264 pub operation: crate::ActionSettings,
265 #[cfg_attr(feature = "clap", arg(help = TARGET_HELP))]
266 #[schemars(
267 description = "Target select element by scoped reference, text, CSS selector, id, or role."
268 )]
269 pub target: String,
270 #[cfg_attr(feature = "clap", arg(help = "Option value or visible label"))]
271 #[schemars(description = "Option value or visible text to select.")]
272 pub value: String,
273}
274
275#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
276#[cfg_attr(feature = "clap", derive(clap::Args))]
277pub struct KeyArgs {
278 #[cfg_attr(feature = "clap", arg(skip))]
279 #[serde(flatten)]
280 pub operation: crate::ActionSettings,
281 #[cfg_attr(
282 feature = "clap",
283 arg(help = "Key name or chord such as Enter, a, Shift+o, Control+a")
284 )]
285 #[schemars(
286 description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
287 )]
288 pub key: String,
289}
290
291#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
292#[cfg_attr(feature = "clap", derive(clap::Args))]
293pub struct HeldKeyArgs {
294 #[cfg_attr(feature = "clap", arg(help = "Key name such as Shift, Control or a"))]
295 #[schemars(description = "Key to hold or release, for example Shift, Control, or a.")]
296 pub key: String,
297}
298
299#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
300#[serde(rename_all = "lowercase")]
301pub enum MouseButton {
302 Left,
303 Middle,
304 Right,
305 Back,
306 Forward,
307}
308
309#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
310pub struct MouseButtonArgs {
311 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
312 pub x: f64,
313 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
314 pub y: f64,
315 #[schemars(description = "Mouse button to hold or release.")]
316 pub button: MouseButton,
317}
318
319#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
320#[cfg_attr(feature = "clap", derive(clap::Args))]
321pub struct MouseMoveArgs {
322 #[cfg_attr(feature = "clap", arg(help = "Viewport X in CSS pixels"))]
323 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
324 pub x: f64,
325 #[cfg_attr(feature = "clap", arg(help = "Viewport Y in CSS pixels"))]
326 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
327 pub y: f64,
328}
329
330#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
331pub struct ScriptArgs {
332 #[serde(default)]
333 pub arguments: Vec<serde_json::Value>,
334 #[serde(default)]
335 pub raw: bool,
336 pub code: Option<String>,
337 pub file: Option<String>,
338 pub max_size: Option<usize>,
339 #[serde(default)]
340 pub no_await: bool,
341 #[serde(default)]
342 #[schemars(
343 description = "Treat code as function source and call it with arguments as written, without expression or statement wrapping; conflicts with raw."
344 )]
345 pub function: bool,
346 #[serde(default)]
347 #[schemars(
348 description = "With raw, return the expression's value as strict JSON, failing on values JSON cannot represent."
349 )]
350 pub json: bool,
351}
352
353#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
354pub struct FrameEvalArgs {
355 #[schemars(
356 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."
357 )]
358 pub frame: String,
359 pub code: Option<String>,
360 pub file: Option<String>,
361}
362
363#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
364pub struct FetchArgs {
365 pub url: String,
366 pub method: Option<String>,
367 pub headers: Option<serde_json::Value>,
368 pub body: Option<String>,
369 pub redirect: Option<String>,
370 #[serde(default)]
371 pub body_only: bool,
372 #[schemars(
373 description = "Raw text byte limit: default 8192, maximum 16777216; zero inspects headers only.",
374 range(max = 16777216)
375 )]
376 pub max_body: Option<usize>,
377}
378
379#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
380#[cfg_attr(feature = "clap", derive(clap::Args))]
381pub struct SetCookieArgs {
382 #[cfg_attr(feature = "clap", arg(help = "Cookie name"))]
383 pub name: String,
384 #[cfg_attr(feature = "clap", arg(help = "Cookie value"))]
385 pub value: String,
386 #[cfg_attr(
387 feature = "clap",
388 arg(long, help = "Cookie domain [default: current page]")
389 )]
390 pub domain: Option<String>,
391 #[cfg_attr(feature = "clap", arg(long, help = "Cookie path"))]
392 pub path: Option<String>,
393}
394
395#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
396#[cfg_attr(feature = "clap", derive(clap::Args))]
397pub struct DeleteCookieArgs {
398 #[cfg_attr(feature = "clap", arg(help = "Cookie name"))]
399 pub name: String,
400 #[cfg_attr(
401 feature = "clap",
402 arg(long, help = "Cookie domain [default: current page hostname]")
403 )]
404 pub domain: Option<String>,
405}
406
407#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
408#[cfg_attr(feature = "clap", derive(clap::Args))]
409pub struct StorageArgs {
410 #[cfg_attr(feature = "clap", arg(help = "Key to read; omit for every key"))]
411 pub key: Option<String>,
412 #[cfg_attr(
413 feature = "clap",
414 arg(long, help = "Use sessionStorage instead of localStorage")
415 )]
416 #[serde(default)]
417 pub session_storage: bool,
418}
419
420#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
421#[cfg_attr(feature = "clap", derive(clap::Args))]
422pub struct SetStorageArgs {
423 #[cfg_attr(feature = "clap", arg(help = "Storage key"))]
424 pub key: String,
425 #[cfg_attr(feature = "clap", arg(help = "Value to store"))]
426 pub value: String,
427 #[cfg_attr(
428 feature = "clap",
429 arg(long, help = "Use sessionStorage instead of localStorage")
430 )]
431 #[serde(default)]
432 pub session_storage: bool,
433}
434
435#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
436pub struct PathArgs {
437 #[schemars(description = "File path.")]
438 pub path: String,
439}
440
441#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
442pub struct LoadStateArgs {
443 pub path: String,
444 #[serde(default)]
445 pub no_navigate: bool,
446}
447
448#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
449#[cfg_attr(feature = "clap", derive(clap::Args))]
450pub struct HeadersArgs {
451 #[cfg_attr(feature = "clap", arg(help = "Headers as a JSON object"))]
452 pub headers_json: String,
453}
454
455#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
456#[cfg_attr(feature = "clap", derive(clap::Args))]
457pub struct ConsoleArgs {
458 #[cfg_attr(
459 feature = "clap",
460 arg(long, help = "Clear captured output after reading")
461 )]
462 #[serde(default)]
463 pub clear: bool,
464 #[cfg_attr(
465 feature = "clap",
466 arg(long, help = "Only this level: log, warn, error, info or debug")
467 )]
468 pub level: Option<String>,
469}
470
471#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
472#[cfg_attr(feature = "clap", derive(clap::Args))]
473pub struct ClearFlagArgs {
474 #[cfg_attr(
475 feature = "clap",
476 arg(long, help = "Clear captured errors after reading")
477 )]
478 #[serde(default)]
479 pub clear: bool,
480}
481
482#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
483#[cfg_attr(feature = "clap", derive(clap::Args))]
484pub struct TabNewArgs {
485 #[cfg_attr(feature = "clap", arg(help = "URL to open [default: blank page]"))]
486 #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
487 pub url: Option<String>,
488}
489
490#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
491#[cfg_attr(feature = "clap", derive(clap::Args))]
492pub struct TabIdArgs {
493 #[cfg_attr(feature = "clap", arg(help = "Tab ID from tab list"))]
494 #[schemars(description = "Tab ID from list_tabs.")]
495 pub tab_id: String,
496}
497
498#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
499pub struct CloneFromArgs {
500 pub source: String,
501 pub to: Option<String>,
502}
503
504#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
505pub struct WaitArgs {
506 #[serde(default)]
507 pub expect: Option<crate::Expectation>,
508 pub ms: Option<u64>,
509 pub text: Option<String>,
510 pub url: Option<String>,
511 pub load: Option<String>,
512 #[serde(default)]
513 #[schemars(description = "CSS selector to wait for; see `state`.")]
514 pub selector: Option<String>,
515 #[serde(default)]
516 #[schemars(description = "What the selector must become. Defaults to visible.")]
517 pub state: Option<WaitSelectorState>,
518 #[serde(default)]
519 #[schemars(
520 description = "Wait until no XHR or fetch request has run for this many milliseconds."
521 )]
522 pub network_idle: Option<u64>,
523 pub timeout: Option<u64>,
524}
525
526#[derive(
527 Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, schemars::JsonSchema,
528)]
529#[serde(rename_all = "lowercase")]
530#[schemars(description = "The condition a `wait` selector must reach.")]
531pub enum WaitSelectorState {
532 #[schemars(description = "Present in the DOM, rendered or not.")]
533 Attached,
534 #[schemars(description = "Rendered with visible CSS and a nonzero box.")]
535 #[default]
536 Visible,
537 #[schemars(description = "Absent or no longer rendered.")]
538 Hidden,
539}
540
541#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
542#[cfg_attr(feature = "clap", derive(clap::Args))]
543pub struct DialogAcceptArgs {
544 #[cfg_attr(
545 feature = "clap",
546 arg(long, help = "Text to enter for a prompt() dialog")
547 )]
548 #[serde(default)]
549 #[schemars(
550 description = "Text to enter for a prompt() dialog; ignored for alert and confirm."
551 )]
552 pub prompt_text: Option<String>,
553}
554
555#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
556#[cfg_attr(feature = "clap", derive(clap::Args))]
557pub struct SelectorArgs {
558 #[cfg_attr(feature = "clap", arg(help = "CSS selector"))]
559 #[schemars(description = "CSS selector of the element.")]
560 pub selector: String,
561}
562
563#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
564#[cfg_attr(feature = "clap", derive(clap::Args))]
565pub struct AttributeArgs {
566 #[cfg_attr(feature = "clap", arg(help = "CSS selector"))]
567 #[schemars(description = "CSS selector of the element.")]
568 pub selector: String,
569 #[cfg_attr(feature = "clap", arg(help = "Attribute name, for example href"))]
570 #[schemars(description = "Attribute name, for example href.")]
571 pub name: String,
572}
573
574#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
575#[cfg_attr(feature = "clap", derive(clap::Args))]
576pub struct ClickShadowArgs {
577 #[cfg_attr(
578 feature = "clap",
579 arg(help = "CSS selector, matched through shadow roots")
580 )]
581 #[serde(deserialize_with = "shadow_selector")]
582 #[schemars(description = "CSS selector, matched through open and closed shadow roots.")]
583 pub selector: String,
584 #[cfg_attr(
585 feature = "clap",
586 arg(
587 long = "frame",
588 value_name = "FRAME",
589 help = "Frame ID from `eoka frames`; the top frame when omitted"
590 )
591 )]
592 #[serde(default)]
593 #[schemars(description = "Frame ID from `frames`; the top frame when omitted.")]
594 pub frame_id: Option<String>,
595 #[cfg_attr(
596 feature = "clap",
597 arg(long, default_value = "10000", help = "Deadline in milliseconds")
598 )]
599 #[serde(
600 default = "default_click_shadow_timeout_ms",
601 deserialize_with = "shadow_timeout"
602 )]
603 pub timeout_ms: u64,
604}
605
606fn default_click_shadow_timeout_ms() -> u64 {
607 10_000
608}
609
610fn shadow_selector<'de, D: serde::Deserializer<'de>>(d: D) -> Result<String, D::Error> {
611 let selector = String::deserialize(d)?;
612 if selector.trim().is_empty() || selector.len() > 4096 {
613 return Err(serde::de::Error::custom(
614 "selector must be 1..=4096 characters",
615 ));
616 }
617 Ok(selector)
618}
619
620fn shadow_timeout<'de, D: serde::Deserializer<'de>>(d: D) -> Result<u64, D::Error> {
621 let timeout = u64::deserialize(d)?;
622 if !(1..=60_000).contains(&timeout) {
623 return Err(serde::de::Error::custom(
624 "timeout_ms must be between 1 and 60000",
625 ));
626 }
627 Ok(timeout)
628}
629
630#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
631#[cfg_attr(feature = "clap", derive(clap::Args))]
632pub struct PathStringArgs {
633 #[cfg_attr(feature = "clap", arg(help = "Route path such as /dashboard"))]
634 #[schemars(description = "Target path, for example /docs or /about.")]
635 pub path: String,
636}
637
638#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
639pub struct FakeCameraArgs {
640 pub file: String,
641 #[serde(default)]
642 pub loop_video: bool,
643}
644
645#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
646#[cfg_attr(feature = "clap", derive(clap::Args))]
647pub struct WasmReadArgs {
648 #[cfg_attr(feature = "clap", arg(help = WASM_ADDR_HELP))]
649 pub addr: String,
650 #[cfg_attr(feature = "clap", arg(help = "Number of bytes"))]
651 pub len: usize,
652 #[cfg_attr(feature = "clap", arg(long, help = WASM_MEMORY_HELP))]
653 pub memory: Option<String>,
654}
655
656#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
657#[cfg_attr(feature = "clap", derive(clap::Args))]
658pub struct WasmWriteArgs {
659 #[cfg_attr(feature = "clap", arg(help = WASM_ADDR_HELP))]
660 pub addr: String,
661 #[cfg_attr(feature = "clap", arg(help = "Bytes as hex, such as deadbeef"))]
662 pub hex: String,
663 #[cfg_attr(feature = "clap", arg(long, help = WASM_MEMORY_HELP))]
664 pub memory: Option<String>,
665}
666
667#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
668#[cfg_attr(feature = "clap", derive(clap::Args))]
669pub struct WasmFindArgs {
670 #[cfg_attr(
671 feature = "clap",
672 arg(help = "Hex bytes to find; spaces allowed, such as \"ff d8 ff e0\"")
673 )]
674 pub pattern: String,
675 #[cfg_attr(feature = "clap", arg(long, help = "Start address [default: 0]"))]
676 pub start: Option<String>,
677 #[cfg_attr(
678 feature = "clap",
679 arg(long, help = "End address [default: end of memory]")
680 )]
681 pub end: Option<String>,
682 #[cfg_attr(
683 feature = "clap",
684 arg(long, default_value = "20", help = "Maximum matches")
685 )]
686 #[serde(default = "default_wasm_find_max")]
687 pub max: usize,
688 #[cfg_attr(feature = "clap", arg(long, help = WASM_MEMORY_HELP))]
689 pub memory: Option<String>,
690}
691
692impl Default for WasmFindArgs {
693 fn default() -> Self {
694 Self {
695 pattern: String::new(),
696 start: None,
697 end: None,
698 max: default_wasm_find_max(),
699 memory: None,
700 }
701 }
702}
703
704#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
705pub struct InterceptAddArgs {
706 pub url_pattern: String,
707 pub capture: Option<String>,
708 pub respond: Option<String>,
709 #[serde(default = "default_intercept_status")]
710 pub status: u16,
711}
712
713impl Default for InterceptAddArgs {
714 fn default() -> Self {
715 Self {
716 url_pattern: String::new(),
717 capture: None,
718 respond: None,
719 status: default_intercept_status(),
720 }
721 }
722}
723
724#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
725pub struct IdArgs {
726 pub id: String,
727}
728
729#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
730#[cfg_attr(feature = "clap", derive(clap::Args))]
731pub struct ModeArgs {
732 #[cfg_attr(feature = "clap", arg(help = "block-all or allow-all"))]
733 pub mode: String,
734}
735
736#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
737#[cfg_attr(feature = "clap", derive(clap::Args))]
738pub struct DomainArgs {
739 #[cfg_attr(feature = "clap", arg(help = "Domain such as example.com"))]
740 pub domain: String,
741}
742
743#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
744pub struct CaptchaInjectArgs {
745 pub token: String,
746 #[serde(default = "default_captcha_type")]
747 pub captcha_type: String,
748 pub callback: Option<String>,
749 pub click_after: Option<String>,
750}
751
752#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
753#[cfg_attr(feature = "clap", derive(clap::Args))]
754pub struct NetworkRecordStartArgs {
755 #[cfg_attr(
756 feature = "clap",
757 arg(long = "pattern", help = "URL glob to record; repeat for several")
758 )]
759 #[serde(default)]
760 pub patterns: Vec<String>,
761 #[cfg_attr(feature = "clap", arg(long, help = "Record metadata only"))]
762 #[serde(default)]
763 pub no_bodies: bool,
764 #[cfg_attr(
765 feature = "clap",
766 arg(long, default_value = "10485760", help = "Per-response body cap")
767 )]
768 #[serde(default = "default_max_body_bytes")]
769 pub max_body_bytes: usize,
770 #[cfg_attr(feature = "clap", arg(long, help = "Discard earlier entries first"))]
771 #[serde(default)]
772 pub clear: bool,
773}
774
775#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
776#[cfg_attr(feature = "clap", derive(clap::Args))]
777pub struct NetworkLogArgs {
778 #[cfg_attr(feature = "clap", arg(long, help = "Maximum entries to return"))]
779 pub limit: Option<usize>,
780 #[cfg_attr(feature = "clap", arg(long, help = "URL glob such as */api/*"))]
781 pub pattern: Option<String>,
782 #[cfg_attr(feature = "clap", arg(long, help = "Only this HTTP method"))]
783 pub method: Option<String>,
784 #[cfg_attr(feature = "clap", arg(long, help = "Only this response status"))]
785 pub status: Option<u16>,
786 #[cfg_attr(
787 feature = "clap",
788 arg(long, help = "Only entries after this request ID")
789 )]
790 pub since: Option<u64>,
791 #[cfg_attr(feature = "clap", arg(long, help = "One line per request"))]
792 #[serde(default)]
793 pub compact: bool,
794}
795
796#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
797#[cfg_attr(feature = "clap", derive(clap::Args))]
798pub struct NetworkShowArgs {
799 #[cfg_attr(feature = "clap", arg(help = "Request ID from network log"))]
800 pub id: u64,
801 #[cfg_attr(feature = "clap", arg(long, help = "Include the response body"))]
802 #[serde(default)]
803 pub body: bool,
804 #[cfg_attr(feature = "clap", arg(long, help = "Maximum body bytes to print"))]
805 pub max_body: Option<usize>,
806}
807
808#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
809#[cfg_attr(feature = "clap", derive(clap::Args))]
810pub struct NetworkWaitArgs {
811 #[cfg_attr(feature = "clap", arg(long, help = "URL glob such as */api/*"))]
812 pub pattern: Option<String>,
813 #[cfg_attr(feature = "clap", arg(long, help = "Only this HTTP method"))]
814 pub method: Option<String>,
815 #[cfg_attr(feature = "clap", arg(long, help = "Only this response status"))]
816 pub status: Option<u16>,
817 #[cfg_attr(feature = "clap", arg(long, help = "Timeout in milliseconds"))]
818 pub timeout: Option<u64>,
819 #[cfg_attr(
820 feature = "clap",
821 arg(long, help = "Only match requests after this request ID")
822 )]
823 pub since: Option<u64>,
824 #[cfg_attr(
825 feature = "clap",
826 arg(long, help = "Also match requests recorded before the wait started")
827 )]
828 #[serde(default)]
829 pub include_existing: bool,
830}
831
832#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
833pub struct NetworkExportArgs {
834 pub path: String,
835 #[serde(default = "default_network_export_format")]
836 pub format: String,
837 pub settle_ms: Option<u64>,
838}
839
840impl Default for NetworkExportArgs {
841 fn default() -> Self {
842 Self {
843 path: String::new(),
844 format: default_network_export_format(),
845 settle_ms: None,
846 }
847 }
848}
849
850fn default_max_body_bytes() -> usize {
851 10 * 1024 * 1024
852}
853
854fn default_network_export_format() -> String {
855 "har".to_string()
856}
857
858fn default_viewport_width() -> u32 {
859 390
860}
861
862fn default_viewport_height() -> u32 {
863 844
864}
865
866fn default_device_pixel_ratio() -> f64 {
867 2.0
868}
869
870fn default_wasm_find_max() -> usize {
871 20
872}
873
874fn default_intercept_status() -> u16 {
875 200
876}
877
878fn default_captcha_type() -> String {
879 "auto".to_string()
880}