1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
4pub struct OpenArgs {
5 #[serde(flatten)]
6 pub operation: crate::ActionSettings,
7 pub url: String,
8 pub headers: Option<serde_json::Value>,
9 pub user_agent: Option<String>,
10 #[serde(default)]
11 pub bypass_csp: bool,
12 pub inject_js: Option<String>,
13 pub load_state: Option<String>,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
17pub struct SnapshotArgs {
18 #[serde(default)]
19 pub interactive: bool,
20 #[serde(default)]
21 pub all: bool,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
25pub struct ObserveArgs {
26 #[schemars(
27 description = "Filter: 'inputs' for form elements, 'buttons' for buttons and links, or 'all' for all observed elements."
28 )]
29 pub filter: Option<String>,
30 #[schemars(description = "Maximum elements to return.")]
31 pub max: Option<usize>,
32 #[serde(default)]
33 pub structured: bool,
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
37pub struct ScreenshotArgs {
38 pub output: Option<String>,
39 #[serde(default)]
40 pub annotate: bool,
41 #[serde(default)]
42 #[schemars(description = "Image format; PNG when omitted.")]
43 pub format: Option<crate::sidecar::ScreenshotFormat>,
44 #[serde(default)]
45 #[schemars(range(max = 100), description = "JPEG or WebP quality, 0 to 100.")]
46 pub quality: Option<u8>,
47 #[serde(default)]
48 #[schemars(description = "Document-relative CSS pixel region; conflicts with full_page.")]
49 pub clip: Option<crate::sidecar::ScreenshotClip>,
50 #[serde(default)]
51 #[schemars(description = "Capture the whole scrollable page instead of the viewport.")]
52 pub full_page: bool,
53 #[serde(default)]
54 #[schemars(
55 description = "Return the image as base64 dataBase64 instead of writing a file; conflicts with output and annotate."
56 )]
57 pub inline: bool,
58}
59
60impl ScreenshotArgs {
61 pub fn validate(&self) -> Result<(), crate::sidecar::ServerError> {
62 crate::sidecar::validate_screenshot(
63 self.format,
64 self.quality,
65 self.clip.as_ref(),
66 Some(self.full_page),
67 )?;
68 if self.inline && (self.output.is_some() || self.annotate) {
69 return Err(crate::sidecar::ServerError::invalid_params(
70 "inline cannot be combined with output or annotate",
71 ));
72 }
73 if self.annotate
74 && (self.format.is_some()
75 || self.quality.is_some()
76 || self.clip.is_some()
77 || self.full_page)
78 {
79 return Err(crate::sidecar::ServerError::invalid_params(
80 "annotate cannot be combined with format, quality, clip or full page",
81 ));
82 }
83 Ok(())
84 }
85
86 pub fn options(&self) -> eoka::ScreenshotOptions {
87 crate::sidecar::screenshot_options(
88 self.format,
89 self.quality,
90 self.clip.as_ref(),
91 Some(self.full_page),
92 )
93 }
94
95 pub fn mime_type(&self) -> &'static str {
96 match self.format.unwrap_or(crate::sidecar::ScreenshotFormat::Png) {
97 crate::sidecar::ScreenshotFormat::Png => "image/png",
98 crate::sidecar::ScreenshotFormat::Jpeg => "image/jpeg",
99 crate::sidecar::ScreenshotFormat::Webp => "image/webp",
100 }
101 }
102
103 pub fn extension(&self) -> &'static str {
104 match self.format.unwrap_or(crate::sidecar::ScreenshotFormat::Png) {
105 crate::sidecar::ScreenshotFormat::Png => "png",
106 crate::sidecar::ScreenshotFormat::Jpeg => "jpg",
107 crate::sidecar::ScreenshotFormat::Webp => "webp",
108 }
109 }
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
113pub struct RecordingStartArgs {
114 #[schemars(description = "Absolute path of the MP4 file to write.")]
115 pub path: String,
116 #[serde(default)]
117 #[schemars(description = "UUID naming this recording; generated when omitted.")]
118 pub recording_id: Option<String>,
119 #[serde(default)]
120 pub max_width: Option<u32>,
121 #[serde(default)]
122 pub max_height: Option<u32>,
123 #[serde(default)]
124 #[schemars(range(min = 1, max = 120))]
125 pub fps: Option<u32>,
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
129pub struct RecordingIdArgs {
130 #[schemars(description = "Recording UUID returned by recording_start.")]
131 pub recording_id: String,
132}
133
134#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
135pub struct EmulateArgs {
136 #[serde(default = "default_viewport_width")]
137 pub width: u32,
138 #[serde(default = "default_viewport_height")]
139 pub height: u32,
140 #[serde(default = "default_device_pixel_ratio")]
141 pub dpr: f64,
142 #[serde(default)]
143 pub desktop: bool,
144 #[serde(default)]
145 pub reset: bool,
146}
147
148impl Default for EmulateArgs {
149 fn default() -> Self {
150 Self {
151 width: default_viewport_width(),
152 height: default_viewport_height(),
153 dpr: default_device_pixel_ratio(),
154 desktop: false,
155 reset: false,
156 }
157 }
158}
159
160#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
161pub struct TextArgs {
162 #[schemars(description = "Text substring to search for, matched case-insensitively.")]
163 pub text: String,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
167pub struct TargetArgs {
168 #[serde(flatten)]
169 pub operation: crate::ActionSettings,
170 #[schemars(
171 description = "Target element. Supports scoped refs from view, text:Submit, placeholder:Email, role:button, css:form button, id:my-btn, or plain text search."
172 )]
173 pub target: String,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
177pub struct FillArgs {
178 #[serde(flatten)]
179 pub operation: crate::ActionSettings,
180 #[schemars(
181 description = "Target input. Supports scoped refs from view, text:Email, placeholder:Enter code, css:input.search, id:email-field, or plain text search."
182 )]
183 pub target: String,
184 #[schemars(description = "Text to type into the element.")]
185 pub text: String,
186 #[serde(default)]
187 pub input_mode: crate::InputMode,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
191pub struct SelectArgs {
192 #[serde(flatten)]
193 pub operation: crate::ActionSettings,
194 #[schemars(
195 description = "Target select element by scoped reference, text, CSS selector, id, or role."
196 )]
197 pub target: String,
198 #[schemars(description = "Option value or visible text to select.")]
199 pub value: String,
200}
201
202#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
203pub struct KeyArgs {
204 #[serde(flatten)]
205 pub operation: crate::ActionSettings,
206 #[schemars(
207 description = "Key to press, for example Enter, Tab, Escape, ArrowDown, or Backspace."
208 )]
209 pub key: String,
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
213pub struct HeldKeyArgs {
214 #[schemars(description = "Key to hold or release, for example Shift, Control, or a.")]
215 pub key: String,
216}
217
218#[derive(Debug, Clone, Copy, Serialize, Deserialize, schemars::JsonSchema)]
219#[serde(rename_all = "lowercase")]
220pub enum MouseButton {
221 Left,
222 Middle,
223 Right,
224 Back,
225 Forward,
226}
227
228#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
229pub struct MouseButtonArgs {
230 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
231 pub x: f64,
232 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
233 pub y: f64,
234 #[schemars(description = "Mouse button to hold or release.")]
235 pub button: MouseButton,
236}
237
238#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
239pub struct MouseMoveArgs {
240 #[schemars(description = "Viewport horizontal coordinate in CSS pixels.")]
241 pub x: f64,
242 #[schemars(description = "Viewport vertical coordinate in CSS pixels.")]
243 pub y: f64,
244}
245
246#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
247pub struct ScriptArgs {
248 #[serde(default)]
249 pub arguments: Vec<serde_json::Value>,
250 #[serde(default)]
251 pub raw: bool,
252 pub code: Option<String>,
253 pub file: Option<String>,
254 pub max_size: Option<usize>,
255 #[serde(default)]
256 pub no_await: bool,
257 #[serde(default)]
258 #[schemars(
259 description = "Treat code as function source and call it with arguments as written, without expression or statement wrapping; conflicts with raw."
260 )]
261 pub function: bool,
262 #[serde(default)]
263 #[schemars(
264 description = "With raw, return the expression's value as strict JSON, failing on values JSON cannot represent."
265 )]
266 pub json: bool,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
270pub struct FrameEvalArgs {
271 #[schemars(
272 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."
273 )]
274 pub frame: String,
275 pub code: Option<String>,
276 pub file: Option<String>,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
280pub struct FetchArgs {
281 pub url: String,
282 pub method: Option<String>,
283 pub headers: Option<serde_json::Value>,
284 pub body: Option<String>,
285 pub redirect: Option<String>,
286 #[serde(default)]
287 pub body_only: bool,
288 #[schemars(
289 description = "Raw text byte limit: default 8192, maximum 16777216; zero inspects headers only.",
290 range(max = 16777216)
291 )]
292 pub max_body: Option<usize>,
293}
294
295#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
296pub struct SetCookieArgs {
297 pub name: String,
298 pub value: String,
299 pub domain: Option<String>,
300 pub path: Option<String>,
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
304pub struct DeleteCookieArgs {
305 pub name: String,
306 pub domain: Option<String>,
307}
308
309#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
310pub struct StorageArgs {
311 pub key: Option<String>,
312 #[serde(default)]
313 pub session_storage: bool,
314}
315
316#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
317pub struct SetStorageArgs {
318 pub key: String,
319 pub value: String,
320 #[serde(default)]
321 pub session_storage: bool,
322}
323
324#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
325pub struct PathArgs {
326 #[schemars(description = "File path.")]
327 pub path: String,
328}
329
330#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
331pub struct LoadStateArgs {
332 pub path: String,
333 #[serde(default)]
334 pub no_navigate: bool,
335}
336
337#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
338pub struct HeadersArgs {
339 pub headers_json: String,
340}
341
342#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
343pub struct ConsoleArgs {
344 #[serde(default)]
345 pub clear: bool,
346 pub level: Option<String>,
347}
348
349#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
350pub struct ClearFlagArgs {
351 #[serde(default)]
352 pub clear: bool,
353}
354
355#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
356pub struct TabNewArgs {
357 #[schemars(description = "Optional URL to navigate to. If omitted, opens a blank tab.")]
358 pub url: Option<String>,
359}
360
361#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
362pub struct TabIdArgs {
363 #[schemars(description = "Tab ID from list_tabs.")]
364 pub tab_id: String,
365}
366
367#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
368pub struct CloneFromArgs {
369 pub source: String,
370 pub to: Option<String>,
371}
372
373#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
374pub struct WaitArgs {
375 #[serde(default)]
376 pub expect: Option<crate::Expectation>,
377 pub ms: Option<u64>,
378 pub text: Option<String>,
379 pub url: Option<String>,
380 pub load: Option<String>,
381 #[serde(default)]
382 #[schemars(description = "CSS selector to wait for; see `state`.")]
383 pub selector: Option<String>,
384 #[serde(default)]
385 #[schemars(description = "What the selector must become. Defaults to visible.")]
386 pub state: Option<WaitSelectorState>,
387 pub timeout: Option<u64>,
388}
389
390#[derive(
391 Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, schemars::JsonSchema,
392)]
393#[serde(rename_all = "lowercase")]
394#[schemars(description = "The condition a `wait` selector must reach.")]
395pub enum WaitSelectorState {
396 #[schemars(description = "Present in the DOM, rendered or not.")]
397 Attached,
398 #[schemars(description = "Rendered with visible CSS and a nonzero box.")]
399 #[default]
400 Visible,
401 #[schemars(description = "Absent or no longer rendered.")]
402 Hidden,
403}
404
405#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
406pub struct DialogAcceptArgs {
407 #[serde(default)]
408 #[schemars(
409 description = "Text to enter for a prompt() dialog; ignored for alert and confirm."
410 )]
411 pub prompt_text: Option<String>,
412}
413
414#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
415pub struct SelectorArgs {
416 #[schemars(description = "CSS selector of the element.")]
417 pub selector: String,
418}
419
420#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
421pub struct AttributeArgs {
422 #[schemars(description = "CSS selector of the element.")]
423 pub selector: String,
424 #[schemars(description = "Attribute name, for example href.")]
425 pub name: String,
426}
427
428#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
429pub struct ClickShadowArgs {
430 #[serde(deserialize_with = "shadow_selector")]
431 #[schemars(description = "CSS selector, matched through open and closed shadow roots.")]
432 pub selector: String,
433 #[serde(default)]
434 #[schemars(description = "Frame ID from `frames`; the top frame when omitted.")]
435 pub frame_id: Option<String>,
436 #[serde(
437 default = "default_click_shadow_timeout_ms",
438 deserialize_with = "shadow_timeout"
439 )]
440 pub timeout_ms: u64,
441}
442
443fn default_click_shadow_timeout_ms() -> u64 {
444 10_000
445}
446
447fn shadow_selector<'de, D: serde::Deserializer<'de>>(d: D) -> Result<String, D::Error> {
448 let selector = String::deserialize(d)?;
449 if selector.trim().is_empty() || selector.len() > 4096 {
450 return Err(serde::de::Error::custom(
451 "selector must be 1..=4096 characters",
452 ));
453 }
454 Ok(selector)
455}
456
457fn shadow_timeout<'de, D: serde::Deserializer<'de>>(d: D) -> Result<u64, D::Error> {
458 let timeout = u64::deserialize(d)?;
459 if !(1..=60_000).contains(&timeout) {
460 return Err(serde::de::Error::custom(
461 "timeout_ms must be between 1 and 60000",
462 ));
463 }
464 Ok(timeout)
465}
466
467#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
468pub struct PathStringArgs {
469 #[schemars(description = "Target path, for example /docs or /about.")]
470 pub path: String,
471}
472
473#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
474pub struct FakeCameraArgs {
475 pub file: String,
476 #[serde(default)]
477 pub loop_video: bool,
478}
479
480#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
481pub struct WasmReadArgs {
482 pub addr: String,
483 pub len: usize,
484 pub memory: Option<String>,
485}
486
487#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
488pub struct WasmWriteArgs {
489 pub addr: String,
490 pub hex: String,
491 pub memory: Option<String>,
492}
493
494#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
495pub struct WasmFindArgs {
496 pub pattern: String,
497 pub start: Option<String>,
498 pub end: Option<String>,
499 #[serde(default = "default_wasm_find_max")]
500 pub max: usize,
501 pub memory: Option<String>,
502}
503
504impl Default for WasmFindArgs {
505 fn default() -> Self {
506 Self {
507 pattern: String::new(),
508 start: None,
509 end: None,
510 max: default_wasm_find_max(),
511 memory: None,
512 }
513 }
514}
515
516#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
517pub struct InterceptAddArgs {
518 pub url_pattern: String,
519 pub capture: Option<String>,
520 pub respond: Option<String>,
521 #[serde(default = "default_intercept_status")]
522 pub status: u16,
523}
524
525impl Default for InterceptAddArgs {
526 fn default() -> Self {
527 Self {
528 url_pattern: String::new(),
529 capture: None,
530 respond: None,
531 status: default_intercept_status(),
532 }
533 }
534}
535
536#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
537pub struct IdArgs {
538 pub id: String,
539}
540
541#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
542pub struct ModeArgs {
543 pub mode: String,
544}
545
546#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
547pub struct DomainArgs {
548 pub domain: String,
549}
550
551#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
552pub struct CaptchaInjectArgs {
553 pub token: String,
554 #[serde(default = "default_captcha_type")]
555 pub captcha_type: String,
556 pub callback: Option<String>,
557 pub click_after: Option<String>,
558}
559
560#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
561pub struct NetworkRecordStartArgs {
562 #[serde(default)]
563 pub patterns: Vec<String>,
564 #[serde(default)]
565 pub no_bodies: bool,
566 #[serde(default = "default_max_body_bytes")]
567 pub max_body_bytes: usize,
568 #[serde(default)]
569 pub clear: bool,
570}
571
572#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
573pub struct NetworkLogArgs {
574 pub limit: Option<usize>,
575 pub pattern: Option<String>,
576 pub method: Option<String>,
577 pub status: Option<u16>,
578 pub since: Option<u64>,
579 #[serde(default)]
580 pub compact: bool,
581}
582
583#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
584pub struct NetworkShowArgs {
585 pub id: u64,
586 #[serde(default)]
587 pub body: bool,
588 pub max_body: Option<usize>,
589}
590
591#[derive(Debug, Clone, Serialize, Deserialize, Default, schemars::JsonSchema)]
592pub struct NetworkWaitArgs {
593 pub pattern: Option<String>,
594 pub method: Option<String>,
595 pub status: Option<u16>,
596 pub timeout: Option<u64>,
597 pub since: Option<u64>,
598 #[serde(default)]
599 pub include_existing: bool,
600}
601
602#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
603pub struct NetworkExportArgs {
604 pub path: String,
605 #[serde(default = "default_network_export_format")]
606 pub format: String,
607 pub settle_ms: Option<u64>,
608}
609
610impl Default for NetworkExportArgs {
611 fn default() -> Self {
612 Self {
613 path: String::new(),
614 format: default_network_export_format(),
615 settle_ms: None,
616 }
617 }
618}
619
620fn default_max_body_bytes() -> usize {
621 10 * 1024 * 1024
622}
623
624fn default_network_export_format() -> String {
625 "har".to_string()
626}
627
628fn default_viewport_width() -> u32 {
629 390
630}
631
632fn default_viewport_height() -> u32 {
633 844
634}
635
636fn default_device_pixel_ratio() -> f64 {
637 2.0
638}
639
640fn default_wasm_find_max() -> usize {
641 20
642}
643
644fn default_intercept_status() -> u16 {
645 200
646}
647
648fn default_captcha_type() -> String {
649 "auto".to_string()
650}