Skip to main content

roder_protocol/
chrome.rs

1//! Protocol-facing DTOs for the `chrome/*` app-server methods.
2//!
3//! The shared browser-bridge contract lives in [`roder_api::chrome`]; the status
4//! and tab/browser/permission record types are re-exported here so SDK clients
5//! and the app-server handlers share one definition. The request param structs
6//! below describe the JSON-RPC payloads accepted by `AppServer`.
7//!
8//! Browser page content, console output, and network metadata forwarded through
9//! these methods are **untrusted**: dispatch results are passed through verbatim
10//! as opaque `serde_json::Value` and must not be treated as instructions.
11
12use serde::{Deserialize, Serialize};
13
14pub use roder_api::chrome::{
15    ChromeBrowser, ChromeCommand, ChromeError, ChromePermissionMode, ChromeSitePermission,
16    ChromeStatus, ChromeTab,
17};
18
19/// Params for `chrome/enable`. Optionally sets the permission mode.
20#[derive(Debug, Clone, Default, Serialize, Deserialize)]
21#[serde(rename_all = "camelCase")]
22pub struct ChromeEnableParams {
23    /// `observe` | `assist` | `control`.
24    #[serde(default)]
25    pub mode: Option<String>,
26}
27
28/// Params for `chrome/setMode`.
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct ChromeSetModeParams {
32    /// `observe` | `assist` | `control`.
33    pub mode: String,
34}
35
36/// Params for `chrome/tabs/activate`.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct ChromeTabActivateParams {
40    pub tab_id: i64,
41}
42
43/// Params for `chrome/tabs/navigate`.
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(rename_all = "camelCase")]
46pub struct ChromeNavigateParams {
47    #[serde(default, skip_serializing_if = "Option::is_none")]
48    pub tab_id: Option<i64>,
49    pub url: String,
50}
51
52/// Params for `chrome/page/snapshot`.
53#[derive(Debug, Clone, Default, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct ChromePageSnapshotParams {
56    #[serde(default, skip_serializing_if = "Option::is_none")]
57    pub tab_id: Option<i64>,
58    /// Optional list of snapshot sections to include (e.g. `["dom","text"]`).
59    #[serde(default, skip_serializing_if = "Vec::is_empty")]
60    pub include: Vec<String>,
61}
62
63/// Params for `chrome/page/action`.
64///
65/// `action` selects the wire command (`page/<action>`); all other fields are
66/// forwarded to the extension untouched via [`extra`](Self::extra).
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(rename_all = "camelCase")]
69pub struct ChromePageActionParams {
70    /// One of: click, type, keypress, scroll, select, screenshot, highlight, eval.
71    pub action: String,
72    /// Remaining action-specific parameters, forwarded verbatim.
73    #[serde(flatten)]
74    pub extra: serde_json::Map<String, serde_json::Value>,
75}
76
77/// Params for `chrome/debug/console` and `chrome/debug/network`.
78#[derive(Debug, Clone, Default, Serialize, Deserialize)]
79#[serde(rename_all = "camelCase")]
80pub struct ChromeDebugReadParams {
81    #[serde(default, skip_serializing_if = "Option::is_none")]
82    pub tab_id: Option<i64>,
83    #[serde(default, skip_serializing_if = "Option::is_none")]
84    pub limit: Option<i64>,
85}
86
87/// Params for `chrome/permissions/list`.
88#[derive(Debug, Clone, Default, Serialize, Deserialize)]
89#[serde(rename_all = "camelCase")]
90pub struct ChromePermissionsListParams {
91    #[serde(default, skip_serializing_if = "Option::is_none")]
92    pub origin: Option<String>,
93}
94
95/// Params for `chrome/permissions/update`.
96#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(rename_all = "camelCase")]
98pub struct ChromePermissionsUpdateParams {
99    pub origin: String,
100    /// The permission bits to apply for `origin`, forwarded verbatim.
101    pub perms: serde_json::Value,
102}