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, Serialize, Deserialize, PartialEq, Eq)]
13#[serde(rename_all = "snake_case")]
14pub enum BrowserKind {
15 Chromium,
16 Firefox,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub struct SurfacePluginDescriptor {
21 pub id: &'static str,
22 pub family: SurfaceFamily,
23 pub version: &'static str,
24 pub description: &'static str,
25}
26
27pub trait SurfacePlugin: Send + Sync {
28 fn descriptor(&self) -> SurfacePluginDescriptor;
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
32pub struct ChromeLaunchInfo {
33 pub browser: String,
34 pub note: String,
35 pub cdp_websocket_url: String,
36 pub user_data_dir: String,
37 pub process_id: u32,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
41pub struct BrowserLaunchInfo {
42 pub browser_kind: BrowserKind,
43 pub browser: String,
44 pub note: String,
45 pub user_data_dir: String,
46 pub process_id: u32,
47 pub browser_session: BrowserSessionHandle,
48 pub initial_page: PageInfo,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
52pub struct ChromeTabInfo {
53 pub note: String,
54 pub target_id: String,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
58pub struct TabNavigationInfo {
59 pub url: String,
60 pub note: String,
61 pub page_session: PageSessionHandle,
62 pub automation: AutomationSessionInfo,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
66pub struct ChromiumBidiMapperInfo {
67 pub package_version: String,
68 pub mapper_target_id: String,
69 pub mapper_session_id: String,
70 pub note: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
74#[serde(tag = "kind", rename_all = "snake_case")]
75pub enum BrowserSessionHandle {
76 Chromium {
77 cdp_websocket_url: String,
78 },
79 Firefox {
80 connection_id: String,
81 bidi_session_id: String,
82 },
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
86#[serde(tag = "kind", rename_all = "snake_case")]
87pub enum PageSessionHandle {
88 Chromium {
89 target_id: String,
90 browsing_context_id: Option<String>,
91 },
92 Firefox {
93 browsing_context_id: String,
94 },
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
98pub struct PageInfo {
99 pub note: String,
100 pub page_session: PageSessionHandle,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
104pub struct AutomationSessionInfo {
105 pub bidi_session_id: String,
106 pub note: String,
107 pub mapper_target_id: Option<String>,
108 pub mapper_session_id: Option<String>,
109 pub package_version: Option<String>,
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
113pub struct ClickInfo {
114 pub css_selector: String,
115 pub note: String,
116 pub bidi_session_id: String,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
120pub struct ElementCountInfo {
121 pub css_selector: String,
122 pub count: u32,
123 pub note: String,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
127pub struct HighlightElementsInfo {
128 pub css_selector: String,
129 pub count: u32,
130 pub note: String,
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
134pub struct FocusInfo {
135 pub css_selector: String,
136 pub note: String,
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
140pub struct FillInfo {
141 pub css_selector: String,
142 pub value: String,
143 pub note: String,
144}
145
146#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
147pub struct HoverInfo {
148 pub css_selector: String,
149 pub note: String,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
153pub struct PressKeyInfo {
154 pub css_selector: String,
155 pub key: String,
156 pub note: String,
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
160pub struct TextInfo {
161 pub css_selector: String,
162 pub text: String,
163 pub note: String,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
167pub struct WaitForSelectorInfo {
168 pub css_selector: String,
169 pub visible: bool,
170 pub note: String,
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
174pub struct ScreenshotInfo {
175 pub png_data: Vec<u8>,
176 pub note: String,
177}
178
179#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
180#[serde(tag = "command", rename_all = "snake_case")]
181pub enum PluginCommand {
182 LaunchBrowser {
183 browser_kind: BrowserKind,
184 browser_binary: Option<String>,
185 },
186 OpenPage {
187 browser_session: BrowserSessionHandle,
188 },
189 ClosePage {
190 browser_session: BrowserSessionHandle,
191 page_session: PageSessionHandle,
192 },
193 NavigatePage {
194 browser_session: BrowserSessionHandle,
195 page_session: PageSessionHandle,
196 url: String,
197 },
198 ClickElement {
199 browser_session: BrowserSessionHandle,
200 page_session: PageSessionHandle,
201 css_selector: String,
202 },
203 CountElements {
204 browser_session: BrowserSessionHandle,
205 page_session: PageSessionHandle,
206 css_selector: String,
207 },
208 HighlightElements {
209 browser_session: BrowserSessionHandle,
210 page_session: PageSessionHandle,
211 css_selector: String,
212 duration_ms: u64,
213 },
214 FocusElement {
215 browser_session: BrowserSessionHandle,
216 page_session: PageSessionHandle,
217 css_selector: String,
218 },
219 FillElement {
220 browser_session: BrowserSessionHandle,
221 page_session: PageSessionHandle,
222 css_selector: String,
223 value: String,
224 },
225 HoverElement {
226 browser_session: BrowserSessionHandle,
227 page_session: PageSessionHandle,
228 css_selector: String,
229 },
230 PressKey {
231 browser_session: BrowserSessionHandle,
232 page_session: PageSessionHandle,
233 css_selector: String,
234 key: String,
235 text: Option<String>,
236 },
237 GetTextContent {
238 browser_session: BrowserSessionHandle,
239 page_session: PageSessionHandle,
240 css_selector: String,
241 },
242 GetInnerText {
243 browser_session: BrowserSessionHandle,
244 page_session: PageSessionHandle,
245 css_selector: String,
246 },
247 WaitForSelector {
248 browser_session: BrowserSessionHandle,
249 page_session: PageSessionHandle,
250 css_selector: String,
251 visible: bool,
252 },
253 Screenshot {
254 browser_session: BrowserSessionHandle,
255 page_session: PageSessionHandle,
256 full_page: bool,
257 },
258 OpenChromeWindow {
259 chrome_binary: Option<String>,
260 },
261 DiscoverInitialTab {
262 cdp_websocket_url: String,
263 },
264 OpenChromeTab {
265 cdp_websocket_url: String,
266 },
267 CloseBrowserProcess {
268 process_id: u32,
269 },
270 CloseChromeTab {
271 cdp_websocket_url: String,
272 target_id: String,
273 },
274 NavigateChromeTab {
275 cdp_websocket_url: String,
276 target_id: String,
277 url: String,
278 },
279 InjectChromiumBidiMapper {
280 cdp_websocket_url: String,
281 },
282 ResolveBidiContextForTab {
283 cdp_websocket_url: String,
284 mapper_target_id: Option<String>,
285 browsing_context_id: Option<String>,
286 url: Option<String>,
287 },
288 ClickElementViaCdp {
289 cdp_websocket_url: String,
290 target_id: String,
291 css_selector: String,
292 },
293 CountElementsViaCdp {
294 cdp_websocket_url: String,
295 target_id: String,
296 css_selector: String,
297 },
298 HighlightElementsViaCdp {
299 cdp_websocket_url: String,
300 target_id: String,
301 css_selector: String,
302 duration_ms: u64,
303 },
304 FocusElementViaCdp {
305 cdp_websocket_url: String,
306 target_id: String,
307 css_selector: String,
308 },
309 FillElementViaCdp {
310 cdp_websocket_url: String,
311 target_id: String,
312 css_selector: String,
313 value: String,
314 },
315 HoverElementViaCdp {
316 cdp_websocket_url: String,
317 target_id: String,
318 css_selector: String,
319 },
320 PressKeyViaCdp {
321 cdp_websocket_url: String,
322 target_id: String,
323 css_selector: String,
324 key: String,
325 text: Option<String>,
326 },
327 GetTextContentViaCdp {
328 cdp_websocket_url: String,
329 target_id: String,
330 css_selector: String,
331 },
332 GetInnerTextViaCdp {
333 cdp_websocket_url: String,
334 target_id: String,
335 css_selector: String,
336 },
337 WaitForSelectorViaCdp {
338 cdp_websocket_url: String,
339 target_id: String,
340 css_selector: String,
341 visible: bool,
342 },
343 ScreenshotViaCdp {
344 cdp_websocket_url: String,
345 target_id: String,
346 },
347}
348
349#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
350#[serde(tag = "result", rename_all = "snake_case")]
351pub enum PluginResult {
352 LaunchBrowser(BrowserLaunchInfo),
353 OpenPage(PageInfo),
354 ClosePage,
355 NavigatePage(TabNavigationInfo),
356 ClickElement(ClickInfo),
357 CountElements(ElementCountInfo),
358 HighlightElements(HighlightElementsInfo),
359 FocusElement(FocusInfo),
360 FillElement(FillInfo),
361 HoverElement(HoverInfo),
362 PressKey(PressKeyInfo),
363 GetTextContent(TextInfo),
364 GetInnerText(TextInfo),
365 WaitForSelector(WaitForSelectorInfo),
366 Screenshot(ScreenshotInfo),
367 OpenChromeWindow(ChromeLaunchInfo),
368 DiscoverInitialTab(ChromeTabInfo),
369 OpenChromeTab(ChromeTabInfo),
370 CloseBrowserProcess,
371 CloseChromeTab,
372 NavigateChromeTab(TabNavigationInfo),
373 InjectChromiumBidiMapper(ChromiumBidiMapperInfo),
374 ResolveBidiContextForTab {
375 browsing_context_id: String,
376 mapper: ChromiumBidiMapperInfo,
377 },
378 ClickElementViaCdp(ClickInfo),
379 CountElementsViaCdp(ElementCountInfo),
380 HighlightElementsViaCdp(HighlightElementsInfo),
381 FocusElementViaCdp(FocusInfo),
382 FillElementViaCdp(FillInfo),
383 HoverElementViaCdp(HoverInfo),
384 PressKeyViaCdp(PressKeyInfo),
385 GetTextContentViaCdp(TextInfo),
386 GetInnerTextViaCdp(TextInfo),
387 WaitForSelectorViaCdp(WaitForSelectorInfo),
388 ScreenshotViaCdp(ScreenshotInfo),
389}
390
391#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
392pub struct PluginEnvelope {
393 pub ok: bool,
394 pub result: Option<PluginResult>,
395 pub error: Option<String>,
396}