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    #[serde(default, skip_serializing_if = "Option::is_none")]
242    pub partition_key: Option<CookiePartition>,
243}
244
245#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
246#[serde(rename_all = "camelCase")]
247pub struct CookiePartition {
248    pub top_level_site: String,
249    #[serde(default)]
250    pub has_cross_site_ancestor: bool,
251}
252
253#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
254#[serde(untagged)]
255pub enum StorageRead {
256    Item(Option<String>),
257    Entries(BTreeMap<String, String>),
258}
259
260#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
261#[serde(rename_all = "camelCase")]
262pub struct StorageDump {
263    pub local_storage: BTreeMap<String, String>,
264    pub session_storage: BTreeMap<String, String>,
265}
266
267#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
268#[serde(rename_all = "lowercase")]
269pub enum ConsoleLevel {
270    Log,
271    Warn,
272    Error,
273    Info,
274    Debug,
275}
276
277#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
278pub struct ConsoleEntry {
279    pub level: ConsoleLevel,
280    pub text: String,
281    pub ts: u64,
282}
283
284#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
285pub struct PageError {
286    pub message: String,
287    pub source: String,
288    pub line: u64,
289    pub col: u64,
290    pub stack: String,
291    pub ts: u64,
292}
293
294#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
295pub enum SpaRouter {
296    ReactRouter,
297    NextJs,
298    VueRouter,
299    AngularRouter,
300    HistoryApi,
301    Unknown,
302}
303
304#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
305pub struct SpaInfo {
306    pub router_type: SpaRouter,
307    pub current_path: String,
308    pub can_navigate: bool,
309}
310
311#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
312pub struct WasmMemory {
313    pub path: String,
314    #[serde(rename = "type")]
315    pub kind: String,
316    pub size: u64,
317    pub pages: f64,
318}
319
320#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
321pub struct InterceptRuleSummary {
322    pub id: usize,
323    pub pattern: String,
324    pub capture: Option<String>,
325    pub respond: Option<String>,
326    pub status: u16,
327}
328
329#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
330pub struct InterceptLogRecord {
331    pub rule_id: usize,
332    pub url: String,
333    pub method: String,
334    pub has_body: bool,
335    pub action: String,
336    pub session_id: Option<String>,
337    pub network_id: Option<String>,
338    pub network_entry_id: Option<u64>,
339}
340
341#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
342#[serde(rename_all = "kebab-case")]
343pub enum ScriptMode {
344    AllowAll,
345    BlockAll,
346}
347
348#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
349pub struct ScriptPolicy {
350    pub mode: ScriptMode,
351    pub allow: Vec<String>,
352    pub block: Vec<String>,
353}
354
355#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
356pub struct CaptchaDetection {
357    pub detected: bool,
358    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
359    pub captcha_type: Option<String>,
360    #[serde(default, skip_serializing_if = "Option::is_none")]
361    pub sitekey: Option<String>,
362}
363
364#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
365pub struct CaptchaInjectResult {
366    #[serde(flatten)]
367    pub injection: crate::sidecar::CaptchaInjection,
368    #[serde(default, skip_serializing_if = "Option::is_none")]
369    pub click_after: Option<ClickAfter>,
370    #[serde(default, skip_serializing_if = "Option::is_none")]
371    pub next_action: Option<String>,
372}
373
374#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
375pub struct ClickAfter {
376    pub target: String,
377    pub clicked: String,
378}