Skip to main content

eoka_protocol/
results.rs

1use std::collections::BTreeMap;
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
7pub struct PageInfo {
8    pub url: String,
9    pub title: String,
10}
11
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
13pub struct AttributeValue {
14    pub value: Option<String>,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
18pub struct Existence {
19    pub exists: bool,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
23pub struct FrameSummary {
24    pub id: String,
25    pub url: String,
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub name: Option<String>,
28}
29
30#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
31pub struct ShadowClick {
32    pub frame_id: String,
33    pub selector: String,
34    pub x: f64,
35    pub y: f64,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
39#[serde(rename_all = "lowercase")]
40pub enum SessionMode {
41    Headless,
42    Headed,
43    Connect,
44    Reuse,
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
48#[serde(rename_all = "camelCase")]
49pub struct SessionHello {
50    pub protocol: crate::sidecar::ProtocolVersion,
51    pub server_version: String,
52    pub session: String,
53    pub mode: SessionMode,
54    pub configuration_fingerprint: String,
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub command_limit_ms: Option<u64>,
57    #[serde(default, skip_serializing_if = "Option::is_none")]
58    pub activity: Option<SessionActivity>,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
62pub struct SessionActivity {
63    pub busy: Option<BusyCommand>,
64    pub queued: usize,
65    pub blocker: Option<SessionBlocker>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
69pub struct BusyCommand {
70    pub cmd: String,
71    pub for_ms: u64,
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
75pub struct SessionBlocker {
76    #[serde(flatten)]
77    pub blocker: BlockerSummary,
78    pub description: String,
79    pub hint: String,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
83#[serde(tag = "kind", rename_all = "snake_case")]
84pub enum BlockerSummary {
85    Dialog {
86        dialog_type: String,
87        message: String,
88        url: String,
89        for_ms: u64,
90    },
91    Navigation {
92        url: Option<String>,
93        for_ms: u64,
94    },
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
98#[serde(untagged)]
99pub enum ActionCommandResult {
100    Action(crate::ActionResult),
101    Download(crate::DownloadResult),
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
105#[serde(untagged)]
106pub enum ScrollResult {
107    Scrolled(String),
108    Action(Box<crate::ActionResult>),
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
112#[serde(untagged)]
113pub enum ObserveResult {
114    Text(String),
115    Structured(StructuredObservation),
116}
117
118#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
119pub struct StructuredObservation {
120    pub text: String,
121    pub elements: Vec<ObservedElement>,
122    pub page: Option<crate::PageContext>,
123}
124
125#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
126pub struct ObservedElement {
127    pub index: usize,
128    pub selector: String,
129    pub text: String,
130    pub role: Option<String>,
131    pub tag: String,
132    pub visible: bool,
133    pub disabled: bool,
134    pub checked: bool,
135    pub placeholder: Option<String>,
136    pub input_type: Option<String>,
137    pub value: Option<String>,
138    pub bbox: ElementBox,
139}
140
141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
142pub struct ElementBox {
143    pub x: f64,
144    pub y: f64,
145    pub width: f64,
146    pub height: f64,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
150#[serde(untagged)]
151pub enum ScreenshotResult {
152    Inline(InlineScreenshot),
153    File(ScreenshotFile),
154}
155
156#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
157#[serde(rename_all = "camelCase")]
158pub struct InlineScreenshot {
159    pub data_base64: String,
160    #[serde(default, skip_serializing_if = "Option::is_none")]
161    pub elements: Option<String>,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
165#[serde(rename_all = "camelCase")]
166pub struct ScreenshotFile {
167    pub path: String,
168    pub size: usize,
169    pub mime_type: String,
170    pub bytes: u64,
171    #[serde(default, skip_serializing_if = "Option::is_none")]
172    pub elements: Option<String>,
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
176#[serde(untagged)]
177pub enum EmulateResult {
178    Viewport(Viewport),
179    Cleared(String),
180}
181
182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
183pub struct Viewport {
184    pub width: u32,
185    pub height: u32,
186    pub dpr: f64,
187    pub mobile: bool,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
191#[serde(untagged)]
192pub enum FetchResult {
193    Body(String),
194    Response(FetchedResponse),
195}
196
197#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
198#[serde(rename_all = "camelCase")]
199pub struct FetchedResponse {
200    pub url: String,
201    pub status: u16,
202    pub status_text: String,
203    #[serde(rename = "type")]
204    pub kind: String,
205    pub redirected: bool,
206    pub headers: BTreeMap<String, String>,
207    pub body: String,
208    pub truncated: bool,
209    pub bytes_read: usize,
210    pub body_omitted: Option<String>,
211}
212
213impl From<eoka::BoundedFetchResponse> for FetchedResponse {
214    fn from(response: eoka::BoundedFetchResponse) -> Self {
215        Self {
216            url: response.url,
217            status: response.status,
218            status_text: response.status_text,
219            kind: response.r#type,
220            redirected: response.redirected,
221            headers: response.headers.into_iter().collect(),
222            body: response.body,
223            truncated: response.truncated,
224            bytes_read: response.bytes_read,
225            body_omitted: response.body_omitted,
226        }
227    }
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
231#[serde(rename_all = "camelCase")]
232pub struct Cookie {
233    pub name: String,
234    pub value: String,
235    pub domain: String,
236    pub path: String,
237    pub http_only: bool,
238    pub secure: bool,
239    pub same_site: Option<String>,
240    pub expires: Option<f64>,
241}
242
243#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
244#[serde(untagged)]
245pub enum StorageRead {
246    Item(Option<String>),
247    Entries(BTreeMap<String, String>),
248}
249
250#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
251#[serde(rename_all = "camelCase")]
252pub struct StorageDump {
253    pub local_storage: BTreeMap<String, String>,
254    pub session_storage: BTreeMap<String, String>,
255}
256
257#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
258#[serde(rename_all = "lowercase")]
259pub enum ConsoleLevel {
260    Log,
261    Warn,
262    Error,
263    Info,
264    Debug,
265}
266
267#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
268pub struct ConsoleEntry {
269    pub level: ConsoleLevel,
270    pub text: String,
271    pub ts: u64,
272}
273
274#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
275pub struct PageError {
276    pub message: String,
277    pub source: String,
278    pub line: u64,
279    pub col: u64,
280    pub stack: String,
281    pub ts: u64,
282}
283
284#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
285pub enum SpaRouter {
286    ReactRouter,
287    NextJs,
288    VueRouter,
289    AngularRouter,
290    HistoryApi,
291    Unknown,
292}
293
294#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
295pub struct SpaInfo {
296    pub router_type: SpaRouter,
297    pub current_path: String,
298    pub can_navigate: bool,
299}
300
301#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
302pub struct WasmMemory {
303    pub path: String,
304    #[serde(rename = "type")]
305    pub kind: String,
306    pub size: u64,
307    pub pages: f64,
308}
309
310#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
311pub struct InterceptRuleSummary {
312    pub id: usize,
313    pub pattern: String,
314    pub capture: Option<String>,
315    pub respond: Option<String>,
316    pub status: u16,
317}
318
319#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
320pub struct InterceptLogRecord {
321    pub rule_id: usize,
322    pub url: String,
323    pub method: String,
324    pub has_body: bool,
325    pub action: String,
326    pub session_id: Option<String>,
327    pub network_id: Option<String>,
328    pub network_entry_id: Option<u64>,
329}
330
331#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
332#[serde(rename_all = "kebab-case")]
333pub enum ScriptMode {
334    AllowAll,
335    BlockAll,
336}
337
338#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
339pub struct ScriptPolicy {
340    pub mode: ScriptMode,
341    pub allow: Vec<String>,
342    pub block: Vec<String>,
343}
344
345#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
346pub struct CaptchaDetection {
347    pub detected: bool,
348    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
349    pub captcha_type: Option<String>,
350    #[serde(default, skip_serializing_if = "Option::is_none")]
351    pub sitekey: Option<String>,
352}
353
354#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
355pub struct CaptchaInjectResult {
356    #[serde(flatten)]
357    pub injection: crate::sidecar::CaptchaInjection,
358    #[serde(default, skip_serializing_if = "Option::is_none")]
359    pub click_after: Option<ClickAfter>,
360    #[serde(default, skip_serializing_if = "Option::is_none")]
361    pub next_action: Option<String>,
362}
363
364#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
365pub struct ClickAfter {
366    pub target: String,
367    pub clicked: String,
368}