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#[cfg(feature = "clap")]
14pub const CODE_HELP: &str = "JavaScript source; omit to use --file";
15
16#[cfg(feature = "clap")]
17fn path_string() -> impl clap::builder::TypedValueParser<Value = String> {
18 use clap::builder::TypedValueParser;
19 clap::builder::PathBufValueParser::new().map(|path| path.to_string_lossy().into_owned())
20}
21
22#[cfg(feature = "clap")]
23fn input_mode() -> impl clap::builder::TypedValueParser<Value = crate::InputMode> {
24 use clap::builder::TypedValueParser;
25 clap::builder::PossibleValuesParser::new(["sequential", "bulk"]).map(|mode| {
26 match mode.as_str() {
27 "bulk" => crate::InputMode::Bulk,
28 _ => crate::InputMode::Sequential,
29 }
30 })
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
34#[cfg_attr(feature = "clap", derive(clap::Args))]
35pub struct OpenArgs {
36 #[cfg_attr(feature = "clap", arg(skip))]
37 #[serde(flatten)]
38 pub operation: crate::ActionSettings,
39 #[cfg_attr(
40 feature = "clap",
41 arg(help = "URL, or a path relative to the current page")
42 )]
43 pub url: String,
44 #[cfg_attr(feature = "clap", arg(skip))]
45 pub headers: Option<serde_json::Value>,
46 #[cfg_attr(
47 feature = "clap",
48 arg(long, help = "User-Agent header for this navigation")
49 )]
50 pub user_agent: Option<String>,
51 #[cfg_attr(
52 feature = "clap",
53 arg(long, help = "Disable the page's Content-Security-Policy")
54 )]
55 #[serde(default)]
56 pub bypass_csp: bool,
57 #[cfg_attr(
58 feature = "clap",
59 arg(
60 long,
61 value_name = "FILE",
62 help = "JavaScript source, or a .js file, to run on each new document before page scripts"
63 )
64 )]
65 pub inject_js: Option<String>,
66 #[cfg_attr(feature = "clap", arg(
67 long,
68 value_name = "FILE",
69 value_parser = path_string(),
70 help = "Restore a save-state file before navigating"
71 )
72 )]
73 pub load_state: Option<String>,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
77#[cfg_attr(feature = "clap", derive(clap::Args))]
78pub struct SnapshotArgs {
79 #[cfg_attr(feature = "clap", arg(short, long, help = "Only interactive nodes"))]
80 #[serde(default)]
81 pub interactive: bool,
82 #[cfg_attr(
83 feature = "clap",
84 arg(long, help = "Keep decorative and empty text nodes")
85 )]
86 #[serde(default)]
87 pub all: bool,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
91#[cfg_attr(feature = "clap", derive(clap::Args))]
92pub struct ObserveArgs {
93 #[cfg_attr(
94 feature = "clap",
95 arg(long, help = "Filter elements: inputs, buttons, or all")
96 )]
97 #[schemars(
98 description = "Filter: 'inputs' for form elements, 'buttons' for buttons and links, or 'all' for all observed elements."
99 )]
100 pub filter: Option<String>,
101 #[cfg_attr(feature = "clap", arg(long, help = "Maximum elements to return"))]
102 #[schemars(description = "Maximum elements to return.")]
103 pub max: Option<usize>,
104 #[cfg_attr(
105 feature = "clap",
106 arg(long, help = "Return structured element objects instead of text")
107 )]
108 #[serde(default)]
109 pub structured: bool,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
113#[cfg_attr(feature = "clap", derive(clap::Args))]
114pub struct ScreenshotArgs {
115 #[cfg_attr(feature = "clap", arg(
116 short,
117 long,
118 value_parser = path_string(),
119 help = "PNG path [default: eoka-screenshot-<ms>.png in the temp dir]"
120 )
121 )]
122 pub output: Option<String>,
123 #[cfg_attr(
124 feature = "clap",
125 arg(long, help = "Overlay numbered labels on interactive elements")
126 )]
127 #[serde(default)]
128 pub annotate: bool,
129 #[cfg_attr(feature = "clap", arg(long, help = "Image format [default: png]"))]
130 #[serde(default)]
131 #[schemars(description = "Image format; PNG when omitted.")]
132 pub format: Option<crate::sidecar::ScreenshotFormat>,
133 #[cfg_attr(feature = "clap", arg(long, help = "JPEG or WebP quality, 0 to 100"))]
134 #[serde(default)]
135 #[schemars(range(max = 100), description = "JPEG or WebP quality, 0 to 100.")]
136 pub quality: Option<u8>,
137 #[cfg_attr(
138 feature = "clap",
139 arg(
140 long,
141 conflicts_with = "clip",
142 help = "Capture the whole scrollable page"
143 )
144 )]
145 #[serde(default)]
146 #[schemars(description = "Capture the whole scrollable page instead of the viewport.")]
147 pub full_page: bool,
148 #[cfg_attr(feature = "clap", arg(
149 long,
150 value_name = "X,Y,WIDTH,HEIGHT",
151 value_parser = crate::sidecar::parse_clip,
152 help = "Capture a document-relative region in CSS pixels"
153 )
154 )]
155 #[serde(default)]
156 #[schemars(description = "Document-relative CSS pixel region; conflicts with full_page.")]
157 pub clip: Option<crate::sidecar::ScreenshotClip>,
158 #[cfg_attr(feature = "clap", arg(skip))]
159 #[serde(default)]
160 #[schemars(
161 description = "Return the image as base64 dataBase64 instead of writing a file; conflicts with output."
162 )]
163 pub inline: bool,
164}
165
166impl ScreenshotArgs {
167 pub fn validate(&self) -> Result<(), crate::sidecar::ServerError> {
168 crate::sidecar::validate_screenshot(
169 self.format,
170 self.quality,
171 self.clip.as_ref(),
172 Some(self.full_page),
173 )?;
174 if self.inline && self.output.is_some() {
175 return Err(crate::sidecar::ServerError::invalid_params(
176 "inline cannot be combined with output",
177 ));
178 }
179 if self.annotate
180 && (self.format.is_some()
181 || self.quality.is_some()
182 || self.clip.is_some()
183 || self.full_page)
184 {
185 return Err(crate::sidecar::ServerError::invalid_params(
186 "annotate cannot be combined with format, quality, clip or full page",
187 ));
188 }
189 Ok(())
190 }
191
192 pub fn options(&self) -> eoka::ScreenshotOptions {
193 crate::sidecar::screenshot_options(
194 self.format,
195 self.quality,
196 self.clip.as_ref(),
197 Some(self.full_page),
198 )
199 }
200
201 pub fn mime_type(&self) -> &'static str {
202 match self.format.unwrap_or(crate::sidecar::ScreenshotFormat::Png) {
203 crate::sidecar::ScreenshotFormat::Png => "image/png",
204 crate::sidecar::ScreenshotFormat::Jpeg => "image/jpeg",
205 crate::sidecar::ScreenshotFormat::Webp => "image/webp",
206 }
207 }
208
209 pub fn extension(&self) -> &'static str {
210 match self.format.unwrap_or(crate::sidecar::ScreenshotFormat::Png) {
211 crate::sidecar::ScreenshotFormat::Png => "png",
212 crate::sidecar::ScreenshotFormat::Jpeg => "jpg",
213 crate::sidecar::ScreenshotFormat::Webp => "webp",
214 }
215 }
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
219#[cfg_attr(feature = "clap", derive(clap::Args))]
220pub struct RecordingStartArgs {
221 #[cfg_attr(feature = "clap", arg(value_parser = path_string(), help = "MP4 file to write"))]
222 #[schemars(description = "Absolute path of the MP4 file to write.")]
223 pub path: String,
224 #[cfg_attr(
225 feature = "clap",
226 arg(
227 long = "id",
228 value_name = "ID",
229 help = "UUID naming this recording [default: generated]"
230 )
231 )]
232 #[serde(default)]
233 #[schemars(description = "UUID naming this recording; generated when omitted.")]
234 pub recording_id: Option<String>,
235 #[cfg_attr(feature = "clap", arg(long, help = "Frames per second, 1 to 120"))]
236 #[serde(default)]
237 #[schemars(range(min = 1, max = 120))]
238 pub fps: Option<u32>,
239 #[cfg_attr(
240 feature = "clap",
241 arg(long, help = "Scale frames down to at most this width")
242 )]
243 #[serde(default)]
244 pub max_width: Option<u32>,
245 #[cfg_attr(
246 feature = "clap",
247 arg(long, help = "Scale frames down to at most this height")
248 )]
249 #[serde(default)]
250 pub max_height: Option<u32>,
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
254#[cfg_attr(feature = "clap", derive(clap::Args))]
255pub struct RecordingIdArgs {
256 #[cfg_attr(
257 feature = "clap",
258 arg(value_name = "ID", help = "Recording ID from start")
259 )]
260 #[schemars(description = "Recording UUID returned by recording_start.")]
261 pub recording_id: String,
262}
263
264#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
265#[cfg_attr(feature = "clap", derive(clap::Args))]
266pub struct EmulateArgs {
267 #[cfg_attr(
268 feature = "clap",
269 arg(long, default_value = "390", help = "Viewport width in CSS pixels")
270 )]
271 #[serde(default = "default_viewport_width")]
272 pub width: u32,
273 #[cfg_attr(
274 feature = "clap",
275 arg(long, default_value = "844", help = "Viewport height in CSS pixels")
276 )]
277 #[serde(default = "default_viewport_height")]
278 pub height: u32,
279 #[cfg_attr(
280 feature = "clap",
281 arg(long, default_value = "2", help = "Device pixel ratio")
282 )]
283 #[serde(default = "default_device_pixel_ratio")]
284 pub dpr: f64,
285 #[cfg_attr(
286 feature = "clap",
287 arg(long, help = "Emulate a desktop instead of a touch mobile device")
288 )]
289 #[serde(default)]
290 pub desktop: bool,
291 #[cfg_attr(
292 feature = "clap",
293 arg(long, help = "Clear emulation and ignore the other flags")
294 )]
295 #[serde(default)]
296 pub reset: bool,
297}
298
299impl Default for EmulateArgs {
300 fn default() -> Self {
301 Self {
302 width: default_viewport_width(),
303 height: default_viewport_height(),
304 dpr: default_device_pixel_ratio(),
305 desktop: false,
306 reset: false,
307 }
308 }
309}
310
311#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
312#[cfg_attr(feature = "clap", derive(clap::Args))]
313pub struct TextArgs {
314 #[cfg_attr(feature = "clap", arg(help = "Text to search for"))]
315 #[schemars(description = "Text substring to search for, matched case-insensitively.")]
316 pub text: String,
317}
318
319#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
320#[cfg_attr(feature = "clap", derive(clap::Args))]
321pub struct TargetArgs {
322 #[cfg_attr(feature = "clap", arg(skip))]
323 #[serde(flatten)]
324 pub operation: crate::ActionSettings,
325 #[cfg_attr(feature = "clap", arg(help = TARGET_HELP))]
326 #[schemars(
327 description = "Target element. Supports scoped refs from view, text:Submit, placeholder:Email, role:button, css:form button, id:my-btn, or plain text search."
328 )]
329 pub target: String,
330}
331
332#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
333#[cfg_attr(feature = "clap", derive(clap::Args))]
334pub struct ClickArgs {
335 #[cfg_attr(feature = "clap", command(flatten))]
336 #[serde(flatten)]
337 pub element: TargetArgs,
338 #[cfg_attr(feature = "clap", arg(skip))]
339 #[serde(default, skip_serializing_if = "Option::is_none")]
340 pub intercept_nav: Option<NavIntercept>,
341}
342
343#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
344#[serde(rename_all = "lowercase")]
345#[schemars(
346 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."
347)]
348pub enum NavIntercept {
349 Block,
350 Allow,
351}
352
353#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
354pub struct HistoryGoArgs {
355 #[serde(flatten)]
356 pub operation: crate::ActionSettings,
357 #[schemars(description = "History delta: -1 for back, 1 for forward, -2 for back twice, etc.")]
358 pub delta: i32,
359}
360
361#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
362#[cfg_attr(feature = "clap", derive(clap::Args))]
363pub struct FillArgs {
364 #[cfg_attr(feature = "clap", arg(skip))]
365 #[serde(flatten)]
366 pub operation: crate::ActionSettings,
367 #[cfg_attr(feature = "clap", arg(help = TARGET_HELP))]
368 #[schemars(
369 description = "Target input. Supports scoped refs from view, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
370 )]
371 pub target: String,
372 #[cfg_attr(feature = "clap", arg(help = "Text to enter"))]
373 #[schemars(description = "Text to type into the element.")]
374 pub text: String,
375 #[cfg_attr(feature = "clap", arg(
376 long,
377 default_value = "sequential",
378 value_parser = input_mode(),
379 help = "sequential types native keystrokes; bulk sets the value at once"
380 )
381 )]
382 #[serde(default)]
383 pub input_mode: crate::InputMode,
384}
385
386#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
387#[cfg_attr(feature = "clap", derive(clap::Args))]
388pub struct SelectArgs {
389 #[cfg_attr(feature = "clap", arg(skip))]
390 #[serde(flatten)]
391 pub operation: crate::ActionSettings,
392 #[cfg_attr(feature = "clap", arg(help = TARGET_HELP))]
393 #[schemars(
394 description = "Target select element by scoped reference, text, CSS selector, id, or role."
395 )]
396 pub target: String,
397 #[cfg_attr(feature = "clap", arg(help = "Option value or visible label"))]
398 #[schemars(description = "Option value or visible text to select.")]
399 pub value: String,
400}
401
402#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
403#[cfg_attr(feature = "clap", derive(clap::Args))]
404pub struct KeyArgs {
405 #[cfg_attr(feature = "clap", arg(skip))]
406 #[serde(flatten)]
407 pub operation: crate::ActionSettings,
408 #[cfg_attr(
409 feature = "clap",
410 arg(help = "Key name or chord such as Enter, a, Shift+o, Control+a")
411 )]
412 #[schemars(
413 description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
414 )]
415 pub key: String,
416}
417
418#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
419#[cfg_attr(feature = "clap", derive(clap::Args))]
420pub struct HeldKeyArgs {
421 #[cfg_attr(feature = "clap", arg(help = "Key name such as Shift, Control or a"))]
422 #[schemars(description = "Key to hold or release, for example Shift, Control, or a.")]
423 pub key: String,
424}
425
426#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
427#[serde(rename_all = "lowercase")]
428pub enum MouseButton {
429 Left,
430 Middle,
431 Right,
432 Back,
433 Forward,
434}
435
436#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
437#[cfg_attr(feature = "clap", derive(clap::Args))]
438pub struct MouseButtonArgs {
439 #[cfg_attr(feature = "clap", arg(help = "Viewport X in CSS pixels"))]
440 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
441 pub x: f64,
442 #[cfg_attr(feature = "clap", arg(help = "Viewport Y in CSS pixels"))]
443 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
444 pub y: f64,
445 #[cfg_attr(feature = "clap", arg(skip = MouseButton::Left))]
446 #[schemars(description = "Mouse button to hold or release.")]
447 pub button: MouseButton,
448}
449
450#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
451#[cfg_attr(feature = "clap", derive(clap::Args))]
452pub struct MouseMoveArgs {
453 #[cfg_attr(feature = "clap", arg(help = "Viewport X in CSS pixels"))]
454 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
455 pub x: f64,
456 #[cfg_attr(feature = "clap", arg(help = "Viewport Y in CSS pixels"))]
457 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
458 pub y: f64,
459}
460
461#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
462#[cfg_attr(feature = "clap", derive(clap::Args))]
463pub struct ScriptArgs {
464 #[cfg_attr(feature = "clap", arg(skip))]
465 #[serde(default)]
466 pub arguments: Vec<serde_json::Value>,
467 #[cfg_attr(
468 feature = "clap",
469 arg(long, help = "Run CODE unchanged in global scope")
470 )]
471 #[serde(default)]
472 pub raw: bool,
473 #[cfg_attr(feature = "clap", arg(help = CODE_HELP))]
474 pub code: Option<String>,
475 #[cfg_attr(feature = "clap", arg(short, long, value_parser = path_string(), help = "Read JavaScript from a file"))]
476 pub file: Option<String>,
477 #[cfg_attr(feature = "clap", arg(skip))]
478 pub max_size: Option<usize>,
479 #[cfg_attr(
480 feature = "clap",
481 arg(long, help = "Do not await a returned promise; requires --raw")
482 )]
483 #[serde(default)]
484 pub no_await: bool,
485 #[cfg_attr(feature = "clap", arg(skip))]
486 #[serde(default)]
487 #[schemars(
488 description = "Treat code as function source and call it with arguments as written, without expression or statement wrapping; conflicts with raw."
489 )]
490 pub function: bool,
491 #[cfg_attr(feature = "clap", arg(skip))]
492 #[serde(default)]
493 #[schemars(
494 description = "With raw, return the expression's value as strict JSON, failing on values JSON cannot represent."
495 )]
496 pub json: bool,
497}
498
499#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
500#[cfg_attr(feature = "clap", derive(clap::Args))]
501pub struct FrameEvalArgs {
502 #[cfg_attr(
503 feature = "clap",
504 arg(
505 help = "CSS selector matching one frame, or id:<frame-id> from frames; no bare URL/index"
506 )
507 )]
508 #[schemars(
509 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."
510 )]
511 pub frame: String,
512 #[cfg_attr(feature = "clap", arg(help = CODE_HELP))]
513 pub code: Option<String>,
514 #[cfg_attr(feature = "clap", arg(short, long, value_parser = path_string(), help = "Read JavaScript from a file"))]
515 pub file: Option<String>,
516}
517
518#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
519#[cfg_attr(feature = "clap", derive(clap::Args))]
520pub struct FetchArgs {
521 #[cfg_attr(feature = "clap", arg(help = "URL to fetch from the page's context"))]
522 pub url: String,
523 #[cfg_attr(
524 feature = "clap",
525 arg(short, long, display_order = 0, help = "HTTP method [default: GET]")
526 )]
527 pub method: Option<String>,
528 #[cfg_attr(feature = "clap", arg(skip))]
529 pub headers: Option<serde_json::Value>,
530 #[cfg_attr(feature = "clap", arg(short, long, help = "Request body"))]
531 pub body: Option<String>,
532 #[cfg_attr(
533 feature = "clap",
534 arg(long, help = "Fetch redirect mode: follow, error or manual")
535 )]
536 pub redirect: Option<String>,
537 #[cfg_attr(
538 feature = "clap",
539 arg(
540 long,
541 help = "Print only the body; fails on binary or truncated bodies"
542 )
543 )]
544 #[serde(default)]
545 pub body_only: bool,
546 #[cfg_attr(
547 feature = "clap",
548 arg(
549 long,
550 help = "Raw text bytes to retain: default 8192, maximum 16777216; 0 means headers only"
551 )
552 )]
553 #[schemars(
554 description = "Raw text byte limit: default 8192, maximum 16777216; zero inspects headers only.",
555 range(max = 16777216)
556 )]
557 pub max_body: Option<usize>,
558}
559
560#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
561#[cfg_attr(feature = "clap", derive(clap::Args))]
562pub struct SetCookieArgs {
563 #[cfg_attr(feature = "clap", arg(help = "Cookie name"))]
564 pub name: String,
565 #[cfg_attr(feature = "clap", arg(help = "Cookie value"))]
566 pub value: String,
567 #[cfg_attr(
568 feature = "clap",
569 arg(long, help = "Cookie domain [default: current page]")
570 )]
571 pub domain: Option<String>,
572 #[cfg_attr(feature = "clap", arg(long, help = "Cookie path"))]
573 pub path: Option<String>,
574}
575
576#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
577#[cfg_attr(feature = "clap", derive(clap::Args))]
578pub struct DeleteCookieArgs {
579 #[cfg_attr(feature = "clap", arg(help = "Cookie name"))]
580 pub name: String,
581 #[cfg_attr(
582 feature = "clap",
583 arg(long, help = "Cookie domain [default: current page hostname]")
584 )]
585 pub domain: Option<String>,
586}
587
588#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
589#[cfg_attr(feature = "clap", derive(clap::Args))]
590pub struct StorageArgs {
591 #[cfg_attr(feature = "clap", arg(help = "Key to read; omit for every key"))]
592 pub key: Option<String>,
593 #[cfg_attr(
594 feature = "clap",
595 arg(long, help = "Use sessionStorage instead of localStorage")
596 )]
597 #[serde(default)]
598 pub session_storage: bool,
599}
600
601#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
602#[cfg_attr(feature = "clap", derive(clap::Args))]
603pub struct SetStorageArgs {
604 #[cfg_attr(feature = "clap", arg(help = "Storage key"))]
605 pub key: String,
606 #[cfg_attr(feature = "clap", arg(help = "Value to store"))]
607 pub value: String,
608 #[cfg_attr(
609 feature = "clap",
610 arg(long, help = "Use sessionStorage instead of localStorage")
611 )]
612 #[serde(default)]
613 pub session_storage: bool,
614}
615
616#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
617#[cfg_attr(feature = "clap", derive(clap::Args))]
618pub struct PathArgs {
619 #[cfg_attr(feature = "clap", arg(value_parser = path_string(), help = "State file to write; must end in .json"))]
620 #[schemars(description = "File path.")]
621 pub path: String,
622}
623
624#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
625#[cfg_attr(feature = "clap", derive(clap::Args))]
626pub struct LoadStateArgs {
627 #[cfg_attr(feature = "clap", arg(value_parser = path_string(), help = "State file written by save-state"))]
628 pub path: String,
629 #[cfg_attr(
630 feature = "clap",
631 arg(long, help = "Do not navigate to the saved URL first")
632 )]
633 #[serde(default)]
634 pub no_navigate: bool,
635}
636
637#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
638#[cfg_attr(feature = "clap", derive(clap::Args))]
639pub struct HeadersArgs {
640 #[cfg_attr(feature = "clap", arg(help = "Headers as a JSON object"))]
641 pub headers_json: String,
642}
643
644#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
645#[cfg_attr(feature = "clap", derive(clap::Args))]
646pub struct ConsoleArgs {
647 #[cfg_attr(
648 feature = "clap",
649 arg(long, help = "Clear captured output after reading")
650 )]
651 #[serde(default)]
652 pub clear: bool,
653 #[cfg_attr(
654 feature = "clap",
655 arg(long, help = "Only this level: log, warn, error, info or debug")
656 )]
657 pub level: Option<String>,
658}
659
660#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
661#[cfg_attr(feature = "clap", derive(clap::Args))]
662pub struct ClearFlagArgs {
663 #[cfg_attr(
664 feature = "clap",
665 arg(long, help = "Clear captured errors after reading")
666 )]
667 #[serde(default)]
668 pub clear: bool,
669}
670
671#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
672#[cfg_attr(feature = "clap", derive(clap::Args))]
673pub struct TabNewArgs {
674 #[cfg_attr(feature = "clap", arg(help = "URL to open [default: blank page]"))]
675 #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
676 pub url: Option<String>,
677}
678
679#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
680#[cfg_attr(feature = "clap", derive(clap::Args))]
681pub struct TabIdArgs {
682 #[cfg_attr(feature = "clap", arg(help = "Tab ID from tab list"))]
683 #[schemars(description = "Tab ID from list_tabs.")]
684 pub tab_id: String,
685}
686
687#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
688#[cfg_attr(feature = "clap", derive(clap::Args))]
689pub struct CloneFromArgs {
690 #[cfg_attr(
691 feature = "clap",
692 arg(help = "DevTools port or WebSocket URL of the running Chrome")
693 )]
694 pub source: String,
695 #[cfg_attr(feature = "clap", arg(long, value_parser = path_string(), help = "Write the snapshot to this state file"))]
696 pub to: Option<String>,
697}
698
699#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
700#[cfg_attr(feature = "clap", derive(clap::Args))]
701pub struct WaitArgs {
702 #[cfg_attr(feature = "clap", arg(skip))]
703 #[serde(default)]
704 pub expect: Option<crate::Expectation>,
705 #[cfg_attr(feature = "clap", arg(help = "Fixed delay in milliseconds"))]
706 pub ms: Option<u64>,
707 #[cfg_attr(feature = "clap", arg(long, help = "Wait until this text is visible"))]
708 pub text: Option<String>,
709 #[cfg_attr(
710 feature = "clap",
711 arg(long, help = "Wait until the URL contains this string")
712 )]
713 pub url: Option<String>,
714 #[cfg_attr(feature = "clap", arg(long, help = "Wait for network idle"))]
715 pub load: Option<String>,
716 #[cfg_attr(
717 feature = "clap",
718 arg(long, help = "Wait until this CSS selector reaches --state")
719 )]
720 #[serde(default)]
721 #[schemars(description = "CSS selector to wait for; see `state`.")]
722 pub selector: Option<String>,
723 #[cfg_attr(
724 feature = "clap",
725 arg(
726 long,
727 requires = "selector",
728 help = "Selector condition [default: visible]"
729 )
730 )]
731 #[serde(default)]
732 #[schemars(description = "What the selector must become. Defaults to visible.")]
733 pub state: Option<WaitSelectorState>,
734 #[cfg_attr(feature = "clap", arg(skip))]
735 #[serde(default)]
736 #[schemars(
737 description = "Wait until no XHR or fetch request has run for this many milliseconds."
738 )]
739 pub network_idle: Option<u64>,
740 #[cfg_attr(feature = "clap", arg(short, long, help = "Timeout in milliseconds"))]
741 pub timeout: Option<u64>,
742}
743
744#[derive(
745 Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, schemars::JsonSchema,
746)]
747#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
748#[serde(rename_all = "lowercase")]
749#[schemars(description = "The condition a `wait` selector must reach.")]
750pub enum WaitSelectorState {
751 #[schemars(description = "Present in the DOM, rendered or not.")]
752 Attached,
753 #[schemars(description = "Rendered with visible CSS and a nonzero box.")]
754 #[default]
755 Visible,
756 #[schemars(description = "Absent or no longer rendered.")]
757 Hidden,
758}
759
760#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
761#[cfg_attr(feature = "clap", derive(clap::Args))]
762pub struct DialogAcceptArgs {
763 #[cfg_attr(
764 feature = "clap",
765 arg(long, help = "Text to enter for a prompt() dialog")
766 )]
767 #[serde(default)]
768 #[schemars(
769 description = "Text to enter for a prompt() dialog; ignored for alert and confirm."
770 )]
771 pub prompt_text: Option<String>,
772}
773
774#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
775#[cfg_attr(feature = "clap", derive(clap::Args))]
776pub struct SelectorArgs {
777 #[cfg_attr(feature = "clap", arg(help = "CSS selector"))]
778 #[schemars(description = "CSS selector of the element.")]
779 pub selector: String,
780}
781
782#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
783#[cfg_attr(feature = "clap", derive(clap::Args))]
784pub struct AttributeArgs {
785 #[cfg_attr(feature = "clap", arg(help = "CSS selector"))]
786 #[schemars(description = "CSS selector of the element.")]
787 pub selector: String,
788 #[cfg_attr(feature = "clap", arg(help = "Attribute name, for example href"))]
789 #[schemars(description = "Attribute name, for example href.")]
790 pub name: String,
791}
792
793#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
794#[cfg_attr(feature = "clap", derive(clap::Args))]
795pub struct ClickShadowArgs {
796 #[cfg_attr(
797 feature = "clap",
798 arg(help = "CSS selector, matched through shadow roots")
799 )]
800 #[serde(deserialize_with = "shadow_selector")]
801 #[schemars(description = "CSS selector, matched through open and closed shadow roots.")]
802 pub selector: String,
803 #[cfg_attr(
804 feature = "clap",
805 arg(
806 long = "frame",
807 value_name = "FRAME",
808 help = "Frame ID from `eoka frames`; the top frame when omitted"
809 )
810 )]
811 #[serde(default)]
812 #[schemars(description = "Frame ID from `frames`; the top frame when omitted.")]
813 pub frame_id: Option<String>,
814 #[cfg_attr(
815 feature = "clap",
816 arg(long, default_value = "10000", help = "Deadline in milliseconds")
817 )]
818 #[serde(
819 default = "default_click_shadow_timeout_ms",
820 deserialize_with = "shadow_timeout"
821 )]
822 pub timeout_ms: u64,
823}
824
825fn default_click_shadow_timeout_ms() -> u64 {
826 10_000
827}
828
829fn shadow_selector<'de, D: serde::Deserializer<'de>>(d: D) -> Result<String, D::Error> {
830 let selector = String::deserialize(d)?;
831 if selector.trim().is_empty() || selector.len() > 4096 {
832 return Err(serde::de::Error::custom(
833 "selector must be 1..=4096 characters",
834 ));
835 }
836 Ok(selector)
837}
838
839fn shadow_timeout<'de, D: serde::Deserializer<'de>>(d: D) -> Result<u64, D::Error> {
840 let timeout = u64::deserialize(d)?;
841 if !(1..=60_000).contains(&timeout) {
842 return Err(serde::de::Error::custom(
843 "timeout_ms must be between 1 and 60000",
844 ));
845 }
846 Ok(timeout)
847}
848
849#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
850#[cfg_attr(feature = "clap", derive(clap::Args))]
851pub struct PathStringArgs {
852 #[cfg_attr(feature = "clap", arg(help = "Route path such as /dashboard"))]
853 #[schemars(description = "Target path, for example /docs or /about.")]
854 pub path: String,
855}
856
857#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
858#[cfg_attr(feature = "clap", derive(clap::Args))]
859pub struct FakeCameraArgs {
860 #[cfg_attr(feature = "clap", arg(value_parser = path_string(), help = "Video file to play as the camera"))]
861 pub file: String,
862 #[cfg_attr(
863 feature = "clap",
864 arg(long, help = "Loop the video instead of stopping at the end")
865 )]
866 #[serde(default)]
867 pub loop_video: bool,
868}
869
870#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
871#[cfg_attr(feature = "clap", derive(clap::Args))]
872pub struct WasmReadArgs {
873 #[cfg_attr(feature = "clap", arg(help = WASM_ADDR_HELP))]
874 pub addr: String,
875 #[cfg_attr(feature = "clap", arg(help = "Number of bytes"))]
876 pub len: usize,
877 #[cfg_attr(feature = "clap", arg(long, help = WASM_MEMORY_HELP))]
878 pub memory: Option<String>,
879}
880
881#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
882#[cfg_attr(feature = "clap", derive(clap::Args))]
883pub struct WasmWriteArgs {
884 #[cfg_attr(feature = "clap", arg(help = WASM_ADDR_HELP))]
885 pub addr: String,
886 #[cfg_attr(feature = "clap", arg(help = "Bytes as hex, such as deadbeef"))]
887 pub hex: String,
888 #[cfg_attr(feature = "clap", arg(long, help = WASM_MEMORY_HELP))]
889 pub memory: Option<String>,
890}
891
892#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
893#[cfg_attr(feature = "clap", derive(clap::Args))]
894pub struct WasmFindArgs {
895 #[cfg_attr(
896 feature = "clap",
897 arg(help = "Hex bytes to find; spaces allowed, such as \"ff d8 ff e0\"")
898 )]
899 pub pattern: String,
900 #[cfg_attr(feature = "clap", arg(long, help = "Start address [default: 0]"))]
901 pub start: Option<String>,
902 #[cfg_attr(
903 feature = "clap",
904 arg(long, help = "End address [default: end of memory]")
905 )]
906 pub end: Option<String>,
907 #[cfg_attr(
908 feature = "clap",
909 arg(long, default_value = "20", help = "Maximum matches")
910 )]
911 #[serde(default = "default_wasm_find_max")]
912 pub max: usize,
913 #[cfg_attr(feature = "clap", arg(long, help = WASM_MEMORY_HELP))]
914 pub memory: Option<String>,
915}
916
917impl Default for WasmFindArgs {
918 fn default() -> Self {
919 Self {
920 pattern: String::new(),
921 start: None,
922 end: None,
923 max: default_wasm_find_max(),
924 memory: None,
925 }
926 }
927}
928
929#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
930#[cfg_attr(feature = "clap", derive(clap::Args))]
931pub struct InterceptAddArgs {
932 #[cfg_attr(feature = "clap", arg(help = "URL glob such as */api/data*"))]
933 pub url_pattern: String,
934 #[cfg_attr(feature = "clap", arg(long, value_parser = path_string(), help = "Write matching requests to this file"))]
935 pub capture: Option<String>,
936 #[cfg_attr(feature = "clap", arg(long, value_parser = path_string(), help = "Serve this file's exact bytes as the response"))]
937 pub respond: Option<String>,
938 #[cfg_attr(
939 feature = "clap",
940 arg(long, default_value = "200", help = "Status code for --respond")
941 )]
942 #[serde(default = "default_intercept_status")]
943 pub status: u16,
944}
945
946impl Default for InterceptAddArgs {
947 fn default() -> Self {
948 Self {
949 url_pattern: String::new(),
950 capture: None,
951 respond: None,
952 status: default_intercept_status(),
953 }
954 }
955}
956
957#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
958#[cfg_attr(feature = "clap", derive(clap::Args))]
959pub struct IdArgs {
960 #[cfg_attr(feature = "clap", arg(help = "Rule ID from intercept list"))]
961 pub id: String,
962}
963
964#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
965#[cfg_attr(feature = "clap", derive(clap::Args))]
966pub struct ModeArgs {
967 #[cfg_attr(feature = "clap", arg(help = "block-all or allow-all"))]
968 pub mode: String,
969}
970
971#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
972#[cfg_attr(feature = "clap", derive(clap::Args))]
973pub struct DomainArgs {
974 #[cfg_attr(feature = "clap", arg(help = "Domain such as example.com"))]
975 pub domain: String,
976}
977
978#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
979#[cfg_attr(feature = "clap", derive(clap::Args))]
980pub struct CaptchaInjectArgs {
981 #[cfg_attr(feature = "clap", arg(help = "Token returned by captcha solve"))]
982 pub token: String,
983 #[cfg_attr(
984 feature = "clap",
985 arg(long, default_value = "auto", help = "auto, recaptcha or hcaptcha")
986 )]
987 #[serde(default = "default_captcha_type")]
988 pub captcha_type: String,
989 #[cfg_attr(
990 feature = "clap",
991 arg(long, help = "Page callback to call with the token")
992 )]
993 pub callback: Option<String>,
994 #[cfg_attr(feature = "clap", arg(long, help = "Target to click after injecting"))]
995 pub click_after: Option<String>,
996}
997
998#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
999#[cfg_attr(feature = "clap", derive(clap::Args))]
1000pub struct NetworkRecordStartArgs {
1001 #[cfg_attr(
1002 feature = "clap",
1003 arg(long = "pattern", help = "URL glob to record; repeat for several")
1004 )]
1005 #[serde(default)]
1006 pub patterns: Vec<String>,
1007 #[cfg_attr(feature = "clap", arg(long, help = "Record metadata only"))]
1008 #[serde(default)]
1009 pub no_bodies: bool,
1010 #[cfg_attr(
1011 feature = "clap",
1012 arg(long, default_value = "10485760", help = "Per-response body cap")
1013 )]
1014 #[serde(default = "default_max_body_bytes")]
1015 pub max_body_bytes: usize,
1016 #[cfg_attr(feature = "clap", arg(long, help = "Discard earlier entries first"))]
1017 #[serde(default)]
1018 pub clear: bool,
1019}
1020
1021#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
1022#[cfg_attr(feature = "clap", derive(clap::Args))]
1023pub struct NetworkLogArgs {
1024 #[cfg_attr(feature = "clap", arg(long, help = "Maximum entries to return"))]
1025 pub limit: Option<usize>,
1026 #[cfg_attr(feature = "clap", arg(long, help = "URL glob such as */api/*"))]
1027 pub pattern: Option<String>,
1028 #[cfg_attr(feature = "clap", arg(long, help = "Only this HTTP method"))]
1029 pub method: Option<String>,
1030 #[cfg_attr(feature = "clap", arg(long, help = "Only this response status"))]
1031 pub status: Option<u16>,
1032 #[cfg_attr(
1033 feature = "clap",
1034 arg(long, help = "Only entries after this request ID")
1035 )]
1036 pub since: Option<u64>,
1037 #[cfg_attr(feature = "clap", arg(long, help = "One line per request"))]
1038 #[serde(default)]
1039 pub compact: bool,
1040}
1041
1042#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
1043#[cfg_attr(feature = "clap", derive(clap::Args))]
1044pub struct NetworkShowArgs {
1045 #[cfg_attr(feature = "clap", arg(help = "Request ID from network log"))]
1046 pub id: u64,
1047 #[cfg_attr(feature = "clap", arg(long, help = "Include the response body"))]
1048 #[serde(default)]
1049 pub body: bool,
1050 #[cfg_attr(feature = "clap", arg(long, help = "Maximum body bytes to print"))]
1051 pub max_body: Option<usize>,
1052}
1053
1054#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
1055#[cfg_attr(feature = "clap", derive(clap::Args))]
1056pub struct NetworkWaitArgs {
1057 #[cfg_attr(feature = "clap", arg(long, help = "URL glob such as */api/*"))]
1058 pub pattern: Option<String>,
1059 #[cfg_attr(feature = "clap", arg(long, help = "Only this HTTP method"))]
1060 pub method: Option<String>,
1061 #[cfg_attr(feature = "clap", arg(long, help = "Only this response status"))]
1062 pub status: Option<u16>,
1063 #[cfg_attr(feature = "clap", arg(long, help = "Timeout in milliseconds"))]
1064 pub timeout: Option<u64>,
1065 #[cfg_attr(
1066 feature = "clap",
1067 arg(long, help = "Only match requests after this request ID")
1068 )]
1069 pub since: Option<u64>,
1070 #[cfg_attr(
1071 feature = "clap",
1072 arg(long, help = "Also match requests recorded before the wait started")
1073 )]
1074 #[serde(default)]
1075 pub include_existing: bool,
1076}
1077
1078#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
1079#[cfg_attr(feature = "clap", derive(clap::Args))]
1080pub struct NetworkExportArgs {
1081 #[cfg_attr(feature = "clap", arg(value_parser = path_string(), help = "File to write"))]
1082 pub path: String,
1083 #[cfg_attr(
1084 feature = "clap",
1085 arg(long, default_value = "har", help = "har or json")
1086 )]
1087 #[serde(default = "default_network_export_format")]
1088 pub format: String,
1089 #[cfg_attr(
1090 feature = "clap",
1091 arg(long, help = "Wait this long for in-flight requests before writing")
1092 )]
1093 pub settle_ms: Option<u64>,
1094}
1095
1096impl Default for NetworkExportArgs {
1097 fn default() -> Self {
1098 Self {
1099 path: String::new(),
1100 format: default_network_export_format(),
1101 settle_ms: None,
1102 }
1103 }
1104}
1105
1106fn default_max_body_bytes() -> usize {
1107 10 * 1024 * 1024
1108}
1109
1110fn default_network_export_format() -> String {
1111 "har".to_string()
1112}
1113
1114fn default_viewport_width() -> u32 {
1115 390
1116}
1117
1118fn default_viewport_height() -> u32 {
1119 844
1120}
1121
1122fn default_device_pixel_ratio() -> f64 {
1123 2.0
1124}
1125
1126fn default_wasm_find_max() -> usize {
1127 20
1128}
1129
1130fn default_intercept_status() -> u16 {
1131 200
1132}
1133
1134fn default_captcha_type() -> String {
1135 "auto".to_string()
1136}