Skip to main content

cdp_driver/
action.rs

1//! The vocabulary of browser operations.
2
3use serde::{Deserialize, Serialize};
4
5/// A single browser operation, dispatched by
6/// [`BrowserAgent::execute`](crate::agent::BrowserAgent::execute).
7///
8/// Serializes to/from the same shape
9/// [`BrowserAgent::execute_json`](crate::agent::BrowserAgent::execute_json) parses
10/// (field names map to lower_snake_case action names, e.g. `Navigate { url }` <->
11/// `{"action": "navigate", "url": "..."}`), so it doubles as an LLM tool-call schema.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub enum BrowserAction {
14    Navigate {
15        url: String,
16    },
17    GoBack,
18    GoForward,
19    Reload,
20
21    Click {
22        selector: Option<String>,
23        x: Option<f64>,
24        y: Option<f64>,
25    },
26    Type {
27        text: String,
28        selector: Option<String>,
29    },
30    Fill {
31        selector: String,
32        value: String,
33    },
34    Submit {
35        selector: Option<String>,
36    },
37    PressKey {
38        key: String,
39    },
40
41    GetTitle,
42    GetUrl,
43    GetText,
44    GetContent {
45        selector: Option<String>,
46    },
47    GetLinks,
48    GetAttributes {
49        selector: String,
50    },
51    Exists {
52        selector: String,
53    },
54
55    Screenshot {
56        path: Option<String>,
57    },
58    Evaluate {
59        expression: String,
60    },
61
62    Wait {
63        ms: u64,
64    },
65    WaitForSelector {
66        selector: String,
67        timeout_ms: u64,
68    },
69
70    Scroll {
71        x: f64,
72        y: f64,
73    },
74    SetViewport {
75        width: i32,
76        height: i32,
77        mobile: bool,
78    },
79    GetMetrics,
80}