Skip to main content

allwright_plugin_sdk/
lib.rs

1use serde::{Deserialize, Serialize};
2
3pub const ALLWRIGHT_PLUGIN_API_VERSION: u32 = 1;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SurfaceFamily {
7    Web,
8    Mobile,
9    Desktop,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct SurfacePluginDescriptor {
14    pub id: &'static str,
15    pub family: SurfaceFamily,
16    pub version: &'static str,
17    pub description: &'static str,
18}
19
20pub trait SurfacePlugin: Send + Sync {
21    fn descriptor(&self) -> SurfacePluginDescriptor;
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
25pub struct ChromeLaunchInfo {
26    pub browser: String,
27    pub note: String,
28    pub cdp_websocket_url: String,
29    pub user_data_dir: String,
30    pub process_id: u32,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
34pub struct ChromeTabInfo {
35    pub note: String,
36    pub target_id: String,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
40pub struct TabNavigationInfo {
41    pub url: String,
42    pub note: String,
43    pub browsing_context_id: String,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
47pub struct ChromiumBidiMapperInfo {
48    pub package_version: String,
49    pub mapper_target_id: String,
50    pub mapper_session_id: String,
51    pub note: String,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
55pub struct ClickInfo {
56    pub css_selector: String,
57    pub note: String,
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
61pub struct ElementCountInfo {
62    pub css_selector: String,
63    pub count: u32,
64    pub note: String,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
68pub struct HighlightElementsInfo {
69    pub css_selector: String,
70    pub count: u32,
71    pub note: String,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
75pub struct FocusInfo {
76    pub css_selector: String,
77    pub note: String,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
81pub struct FillInfo {
82    pub css_selector: String,
83    pub value: String,
84    pub note: String,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
88pub struct HoverInfo {
89    pub css_selector: String,
90    pub note: String,
91}
92
93#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
94pub struct PressKeyInfo {
95    pub css_selector: String,
96    pub key: String,
97    pub note: String,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
101pub struct TextInfo {
102    pub css_selector: String,
103    pub text: String,
104    pub note: String,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
108pub struct WaitForSelectorInfo {
109    pub css_selector: String,
110    pub visible: bool,
111    pub note: String,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
115#[serde(tag = "command", rename_all = "snake_case")]
116pub enum PluginCommand {
117    OpenChromeWindow {
118        chrome_binary: Option<String>,
119    },
120    DiscoverInitialTab {
121        cdp_websocket_url: String,
122    },
123    OpenChromeTab {
124        cdp_websocket_url: String,
125    },
126    CloseBrowserProcess {
127        process_id: u32,
128    },
129    CloseChromeTab {
130        cdp_websocket_url: String,
131        target_id: String,
132    },
133    NavigateChromeTab {
134        cdp_websocket_url: String,
135        target_id: String,
136        url: String,
137    },
138    InjectChromiumBidiMapper {
139        cdp_websocket_url: String,
140    },
141    ResolveBidiContextForTab {
142        cdp_websocket_url: String,
143        mapper_target_id: Option<String>,
144        browsing_context_id: Option<String>,
145        url: Option<String>,
146    },
147    ClickElementViaCdp {
148        cdp_websocket_url: String,
149        target_id: String,
150        css_selector: String,
151    },
152    CountElementsViaCdp {
153        cdp_websocket_url: String,
154        target_id: String,
155        css_selector: String,
156    },
157    HighlightElementsViaCdp {
158        cdp_websocket_url: String,
159        target_id: String,
160        css_selector: String,
161        duration_ms: u64,
162    },
163    FocusElementViaCdp {
164        cdp_websocket_url: String,
165        target_id: String,
166        css_selector: String,
167    },
168    FillElementViaCdp {
169        cdp_websocket_url: String,
170        target_id: String,
171        css_selector: String,
172        value: String,
173    },
174    HoverElementViaCdp {
175        cdp_websocket_url: String,
176        target_id: String,
177        css_selector: String,
178    },
179    PressKeyViaCdp {
180        cdp_websocket_url: String,
181        target_id: String,
182        css_selector: String,
183        key: String,
184        text: Option<String>,
185    },
186    GetTextContentViaCdp {
187        cdp_websocket_url: String,
188        target_id: String,
189        css_selector: String,
190    },
191    GetInnerTextViaCdp {
192        cdp_websocket_url: String,
193        target_id: String,
194        css_selector: String,
195    },
196    WaitForSelectorViaCdp {
197        cdp_websocket_url: String,
198        target_id: String,
199        css_selector: String,
200        visible: bool,
201    },
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
205#[serde(tag = "result", rename_all = "snake_case")]
206pub enum PluginResult {
207    OpenChromeWindow(ChromeLaunchInfo),
208    DiscoverInitialTab(ChromeTabInfo),
209    OpenChromeTab(ChromeTabInfo),
210    CloseBrowserProcess,
211    CloseChromeTab,
212    NavigateChromeTab(TabNavigationInfo),
213    InjectChromiumBidiMapper(ChromiumBidiMapperInfo),
214    ResolveBidiContextForTab {
215        browsing_context_id: String,
216        mapper: ChromiumBidiMapperInfo,
217    },
218    ClickElementViaCdp(ClickInfo),
219    CountElementsViaCdp(ElementCountInfo),
220    HighlightElementsViaCdp(HighlightElementsInfo),
221    FocusElementViaCdp(FocusInfo),
222    FillElementViaCdp(FillInfo),
223    HoverElementViaCdp(HoverInfo),
224    PressKeyViaCdp(PressKeyInfo),
225    GetTextContentViaCdp(TextInfo),
226    GetInnerTextViaCdp(TextInfo),
227    WaitForSelectorViaCdp(WaitForSelectorInfo),
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
231pub struct PluginEnvelope {
232    pub ok: bool,
233    pub result: Option<PluginResult>,
234    pub error: Option<String>,
235}