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 Replay,
411}
412
413impl fmt::Display for RecordingAction {
414 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
415 match self {
416 Self::Start => f.write_str("start"),
417 Self::Stop => f.write_str("stop"),
418 Self::Checkpoint => f.write_str("checkpoint"),
419 Self::ListCheckpoints => f.write_str("list_checkpoints"),
420 Self::GetEvents => f.write_str("get_events"),
421 Self::EventsBetween => f.write_str("events_between"),
422 Self::GetReplay => f.write_str("get_replay"),
423 Self::Export => f.write_str("export"),
424 Self::Import => f.write_str("import"),
425 Self::Replay => f.write_str("replay"),
426 }
427 }
428}
429
430#[derive(Debug, Deserialize, JsonSchema)]
432pub struct RecordingParams {
433 pub action: RecordingAction,
435 pub session_id: Option<String>,
437 pub checkpoint_id: Option<String>,
439 pub checkpoint_label: Option<String>,
441 pub state: Option<serde_json::Value>,
443 pub from: Option<String>,
445 pub to: Option<String>,
447 pub since_index: Option<usize>,
449 pub session_json: Option<String>,
451 pub webview_label: Option<String>,
453}
454
455#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
459#[serde(rename_all = "snake_case")]
460pub enum InspectAction {
461 GetStyles,
463 GetBoundingBoxes,
465 Highlight,
467 ClearHighlights,
469 AuditAccessibility,
471 GetPerformance,
473}
474
475impl fmt::Display for InspectAction {
476 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
477 match self {
478 Self::GetStyles => f.write_str("get_styles"),
479 Self::GetBoundingBoxes => f.write_str("get_bounding_boxes"),
480 Self::Highlight => f.write_str("highlight"),
481 Self::ClearHighlights => f.write_str("clear_highlights"),
482 Self::AuditAccessibility => f.write_str("audit_accessibility"),
483 Self::GetPerformance => f.write_str("get_performance"),
484 }
485 }
486}
487
488#[derive(Debug, Deserialize, JsonSchema)]
490pub struct InspectParams {
491 pub action: InspectAction,
493 pub ref_id: Option<String>,
495 pub ref_ids: Option<Vec<String>>,
497 pub properties: Option<Vec<String>>,
499 pub color: Option<String>,
501 #[serde(rename = "highlight_label")]
503 pub label: Option<String>,
504 pub webview_label: Option<String>,
506}
507
508#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
512#[serde(rename_all = "snake_case")]
513pub enum CssAction {
514 Inject,
516 Remove,
518}
519
520impl fmt::Display for CssAction {
521 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
522 match self {
523 Self::Inject => f.write_str("inject"),
524 Self::Remove => f.write_str("remove"),
525 }
526 }
527}
528
529#[derive(Debug, Deserialize, JsonSchema)]
531pub struct CssParams {
532 pub action: CssAction,
534 pub css: Option<String>,
536 pub webview_label: Option<String>,
538}
539
540#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
544#[serde(rename_all = "snake_case")]
545pub enum LogsAction {
546 Console,
548 Network,
550 Ipc,
552 Navigation,
554 Dialogs,
556 Events,
558 SlowIpc,
560}
561
562impl fmt::Display for LogsAction {
563 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
564 match self {
565 Self::Console => f.write_str("console"),
566 Self::Network => f.write_str("network"),
567 Self::Ipc => f.write_str("ipc"),
568 Self::Navigation => f.write_str("navigation"),
569 Self::Dialogs => f.write_str("dialogs"),
570 Self::Events => f.write_str("events"),
571 Self::SlowIpc => f.write_str("slow_ipc"),
572 }
573 }
574}
575
576#[derive(Debug, Deserialize, JsonSchema)]
578pub struct LogsParams {
579 pub action: LogsAction,
581 pub since: Option<f64>,
583 pub filter: Option<String>,
585 pub limit: Option<usize>,
587 pub threshold_ms: Option<u64>,
589 pub wait_for_capture: Option<bool>,
593 pub webview_label: Option<String>,
595}