1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
9#[serde(rename_all = "snake_case")]
10pub enum StorageType {
11 Local,
13 Session,
15}
16
17impl StorageType {
18 #[must_use]
20 pub fn js_property(self) -> &'static str {
21 match self {
22 Self::Local => "localStorage",
23 Self::Session => "sessionStorage",
24 }
25 }
26}
27
28impl fmt::Display for StorageType {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::Local => f.write_str("local"),
32 Self::Session => f.write_str("session"),
33 }
34 }
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
39#[serde(rename_all = "snake_case")]
40pub enum DialogType {
41 Alert,
43 Confirm,
45 Prompt,
47}
48
49impl DialogType {
50 #[must_use]
52 pub fn as_str(self) -> &'static str {
53 match self {
54 Self::Alert => "alert",
55 Self::Confirm => "confirm",
56 Self::Prompt => "prompt",
57 }
58 }
59}
60
61impl fmt::Display for DialogType {
62 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63 f.write_str(self.as_str())
64 }
65}
66
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
69#[serde(rename_all = "snake_case")]
70pub enum DialogAction {
71 Accept,
73 Dismiss,
75}
76
77impl DialogAction {
78 #[must_use]
80 pub fn as_str(self) -> &'static str {
81 match self {
82 Self::Accept => "accept",
83 Self::Dismiss => "dismiss",
84 }
85 }
86}
87
88impl fmt::Display for DialogAction {
89 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
90 f.write_str(self.as_str())
91 }
92}
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
98#[serde(rename_all = "snake_case")]
99pub enum InteractAction {
100 Click,
102 DoubleClick,
104 Hover,
106 Focus,
108 ScrollIntoView,
110 SelectOption,
112}
113
114impl fmt::Display for InteractAction {
115 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
116 match self {
117 Self::Click => f.write_str("click"),
118 Self::DoubleClick => f.write_str("double_click"),
119 Self::Hover => f.write_str("hover"),
120 Self::Focus => f.write_str("focus"),
121 Self::ScrollIntoView => f.write_str("scroll_into_view"),
122 Self::SelectOption => f.write_str("select_option"),
123 }
124 }
125}
126
127#[derive(Debug, Deserialize, JsonSchema)]
129pub struct InteractParams {
130 pub action: InteractAction,
132 pub ref_id: Option<String>,
134 pub values: Option<Vec<String>>,
136 pub x: Option<f64>,
138 pub y: Option<f64>,
140 pub webview_label: Option<String>,
142}
143
144#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
148#[serde(rename_all = "snake_case")]
149pub enum InputAction {
150 Fill,
152 TypeText,
154 PressKey,
156}
157
158impl fmt::Display for InputAction {
159 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
160 match self {
161 Self::Fill => f.write_str("fill"),
162 Self::TypeText => f.write_str("type_text"),
163 Self::PressKey => f.write_str("press_key"),
164 }
165 }
166}
167
168#[derive(Debug, Deserialize, JsonSchema)]
170pub struct InputParams {
171 pub action: InputAction,
173 pub ref_id: Option<String>,
175 pub value: Option<String>,
177 pub text: Option<String>,
179 pub key: Option<String>,
181 pub webview_label: Option<String>,
183}
184
185#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
189#[serde(rename_all = "snake_case")]
190pub enum WindowAction {
191 GetState,
193 List,
195 Manage,
197 Resize,
199 MoveTo,
201 SetTitle,
203}
204
205impl fmt::Display for WindowAction {
206 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
207 match self {
208 Self::GetState => f.write_str("get_state"),
209 Self::List => f.write_str("list"),
210 Self::Manage => f.write_str("manage"),
211 Self::Resize => f.write_str("resize"),
212 Self::MoveTo => f.write_str("move_to"),
213 Self::SetTitle => f.write_str("set_title"),
214 }
215 }
216}
217
218#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
220#[serde(rename_all = "snake_case")]
221pub enum ManageAction {
222 Minimize,
224 Unminimize,
226 Maximize,
228 Unmaximize,
230 Close,
232 Focus,
234 Show,
236 Hide,
238 Fullscreen,
240 Unfullscreen,
242 AlwaysOnTop,
244 NotAlwaysOnTop,
246}
247
248impl ManageAction {
249 #[must_use]
251 pub fn as_str(self) -> &'static str {
252 match self {
253 Self::Minimize => "minimize",
254 Self::Unminimize => "unminimize",
255 Self::Maximize => "maximize",
256 Self::Unmaximize => "unmaximize",
257 Self::Close => "close",
258 Self::Focus => "focus",
259 Self::Show => "show",
260 Self::Hide => "hide",
261 Self::Fullscreen => "fullscreen",
262 Self::Unfullscreen => "unfullscreen",
263 Self::AlwaysOnTop => "always_on_top",
264 Self::NotAlwaysOnTop => "not_always_on_top",
265 }
266 }
267}
268
269impl fmt::Display for ManageAction {
270 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
271 f.write_str(self.as_str())
272 }
273}
274
275#[derive(Debug, Deserialize, JsonSchema)]
277pub struct WindowParams {
278 pub action: WindowAction,
280 pub label: Option<String>,
282 pub manage_action: Option<ManageAction>,
284 pub width: Option<u32>,
286 pub height: Option<u32>,
288 pub x: Option<i32>,
290 pub y: Option<i32>,
292 pub title: Option<String>,
294}
295
296#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
300#[serde(rename_all = "snake_case")]
301pub enum StorageAction {
302 Get,
304 Set,
306 Delete,
308 GetCookies,
310}
311
312impl fmt::Display for StorageAction {
313 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
314 match self {
315 Self::Get => f.write_str("get"),
316 Self::Set => f.write_str("set"),
317 Self::Delete => f.write_str("delete"),
318 Self::GetCookies => f.write_str("get_cookies"),
319 }
320 }
321}
322
323#[derive(Debug, Deserialize, JsonSchema)]
325pub struct StorageParams {
326 pub action: StorageAction,
328 pub storage_type: Option<StorageType>,
330 pub key: Option<String>,
332 pub value: Option<serde_json::Value>,
334 pub webview_label: Option<String>,
336}
337
338#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
342#[serde(rename_all = "snake_case")]
343pub enum NavigateAction {
344 GoTo,
346 GoBack,
348 GetHistory,
350 SetDialogResponse,
352 GetDialogLog,
354}
355
356impl fmt::Display for NavigateAction {
357 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
358 match self {
359 Self::GoTo => f.write_str("go_to"),
360 Self::GoBack => f.write_str("go_back"),
361 Self::GetHistory => f.write_str("get_history"),
362 Self::SetDialogResponse => f.write_str("set_dialog_response"),
363 Self::GetDialogLog => f.write_str("get_dialog_log"),
364 }
365 }
366}
367
368#[derive(Debug, Deserialize, JsonSchema)]
370pub struct NavigateParams {
371 pub action: NavigateAction,
373 pub url: Option<String>,
375 pub dialog_type: Option<DialogType>,
377 pub dialog_action: Option<DialogAction>,
379 pub text: Option<String>,
381 pub webview_label: Option<String>,
383}
384
385#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
389#[serde(rename_all = "snake_case")]
390pub enum RecordingAction {
391 Start,
393 Stop,
395 Checkpoint,
397 ListCheckpoints,
399 GetEvents,
401 EventsBetween,
403 GetReplay,
405 Export,
407 Import,
409}
410
411impl fmt::Display for RecordingAction {
412 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
413 match self {
414 Self::Start => f.write_str("start"),
415 Self::Stop => f.write_str("stop"),
416 Self::Checkpoint => f.write_str("checkpoint"),
417 Self::ListCheckpoints => f.write_str("list_checkpoints"),
418 Self::GetEvents => f.write_str("get_events"),
419 Self::EventsBetween => f.write_str("events_between"),
420 Self::GetReplay => f.write_str("get_replay"),
421 Self::Export => f.write_str("export"),
422 Self::Import => f.write_str("import"),
423 }
424 }
425}
426
427#[derive(Debug, Deserialize, JsonSchema)]
429pub struct RecordingParams {
430 pub action: RecordingAction,
432 pub session_id: Option<String>,
434 pub checkpoint_id: Option<String>,
436 pub checkpoint_label: Option<String>,
438 pub state: Option<serde_json::Value>,
440 pub from: Option<String>,
442 pub to: Option<String>,
444 pub since_index: Option<usize>,
446 pub session_json: Option<String>,
448}
449
450#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
454#[serde(rename_all = "snake_case")]
455pub enum InspectAction {
456 GetStyles,
458 GetBoundingBoxes,
460 Highlight,
462 ClearHighlights,
464 AuditAccessibility,
466 GetPerformance,
468}
469
470impl fmt::Display for InspectAction {
471 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
472 match self {
473 Self::GetStyles => f.write_str("get_styles"),
474 Self::GetBoundingBoxes => f.write_str("get_bounding_boxes"),
475 Self::Highlight => f.write_str("highlight"),
476 Self::ClearHighlights => f.write_str("clear_highlights"),
477 Self::AuditAccessibility => f.write_str("audit_accessibility"),
478 Self::GetPerformance => f.write_str("get_performance"),
479 }
480 }
481}
482
483#[derive(Debug, Deserialize, JsonSchema)]
485pub struct InspectParams {
486 pub action: InspectAction,
488 pub ref_id: Option<String>,
490 pub ref_ids: Option<Vec<String>>,
492 pub properties: Option<Vec<String>>,
494 pub color: Option<String>,
496 #[serde(rename = "highlight_label")]
498 pub label: Option<String>,
499 pub webview_label: Option<String>,
501}
502
503#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
507#[serde(rename_all = "snake_case")]
508pub enum CssAction {
509 Inject,
511 Remove,
513}
514
515impl fmt::Display for CssAction {
516 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
517 match self {
518 Self::Inject => f.write_str("inject"),
519 Self::Remove => f.write_str("remove"),
520 }
521 }
522}
523
524#[derive(Debug, Deserialize, JsonSchema)]
526pub struct CssParams {
527 pub action: CssAction,
529 pub css: Option<String>,
531 pub webview_label: Option<String>,
533}
534
535#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
539#[serde(rename_all = "snake_case")]
540pub enum LogsAction {
541 Console,
543 Network,
545 Ipc,
547 Navigation,
549 Dialogs,
551 Events,
553 SlowIpc,
555}
556
557impl fmt::Display for LogsAction {
558 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
559 match self {
560 Self::Console => f.write_str("console"),
561 Self::Network => f.write_str("network"),
562 Self::Ipc => f.write_str("ipc"),
563 Self::Navigation => f.write_str("navigation"),
564 Self::Dialogs => f.write_str("dialogs"),
565 Self::Events => f.write_str("events"),
566 Self::SlowIpc => f.write_str("slow_ipc"),
567 }
568 }
569}
570
571#[derive(Debug, Deserialize, JsonSchema)]
573pub struct LogsParams {
574 pub action: LogsAction,
576 pub since: Option<f64>,
578 pub filter: Option<String>,
580 pub limit: Option<usize>,
582 pub threshold_ms: Option<u64>,
584 pub wait_for_capture: Option<bool>,
588 pub webview_label: Option<String>,
590}