Skip to main content

browsr_types/
agent.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// Supported proxy options for the embedded Chromium browser
5#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
6#[serde(tag = "kind", content = "address", rename_all = "snake_case")]
7pub enum BrowserProxy {
8    /// Route traffic through an HTTPS proxy at the provided host:port
9    Https(String),
10    /// Route traffic through a SOCKS5 proxy at the provided host:port
11    Socks5(String),
12}
13
14/// Chromium driver configuration shared across orchestrator + CLI
15#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
16#[serde(default, deny_unknown_fields)]
17pub struct BrowsrClientConfig {
18    /// Preferred viewport size (defaults to 1920x1080)
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub window_size: Option<(u32, u32)>,
21    /// Whether to run Chromium in headless mode
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub headless: Option<bool>,
24    /// Enable stealth adjustments to reduce detection heuristics
25    pub enable_stealth_mode: bool,
26    /// Enable Spider's "real" emulation for fonts, media, etc.
27    pub enable_real_emulation: bool,
28    /// Optional proxy information passed to Chromium
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub proxy: Option<BrowserProxy>,
31    /// Model settings for structured extraction (loaded from browsr.toml) - stored as JSON to avoid circular dependencies
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub analysis_model_settings: Option<serde_json::Value>,
34    /// Custom user agent string (defaults to modern Chrome on macOS)
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub user_agent: Option<String>,
37    /// Generate a random modern Chrome user agent on session start (overrides user_agent if set)
38    #[serde(default)]
39    pub use_random_user_agent: bool,
40    /// Disable automation detection features (webdriver flag, etc.)
41    #[serde(default = "default_true")]
42    pub disable_automation_detection: bool,
43}
44
45fn default_true() -> bool {
46    true
47}
48
49impl Default for BrowsrClientConfig {
50    fn default() -> Self {
51        Self {
52            window_size: None,
53            headless: Some(true),
54            enable_stealth_mode: true,
55            enable_real_emulation: true,
56            proxy: None,
57            analysis_model_settings: None,
58            user_agent: None,
59            use_random_user_agent: false,
60            disable_automation_detection: true,
61        }
62    }
63}
64
65/// Serializable cookie representation used for session persistence
66#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
67#[serde(deny_unknown_fields)]
68pub struct BrowserCookie {
69    pub name: String,
70    pub value: String,
71    #[serde(default, skip_serializing_if = "Option::is_none")]
72    pub domain: Option<String>,
73    #[serde(default, skip_serializing_if = "Option::is_none")]
74    pub path: Option<String>,
75    #[serde(default, skip_serializing_if = "Option::is_none")]
76    pub expires: Option<f64>,
77    #[serde(default)]
78    pub http_only: bool,
79    #[serde(default)]
80    pub secure: bool,
81    #[serde(default, skip_serializing_if = "Option::is_none")]
82    pub same_site: Option<String>,
83    #[serde(default, skip_serializing_if = "Option::is_none")]
84    pub priority: Option<String>,
85    #[serde(default, skip_serializing_if = "Option::is_none")]
86    pub source_scheme: Option<String>,
87}
88
89/// Captured browser state (cookies + last URL)
90#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
91pub struct BrowserSessionState {
92    pub cookies: Vec<BrowserCookie>,
93    #[serde(default, skip_serializing_if = "Option::is_none")]
94    pub last_url: Option<String>,
95    #[schemars(with = "String")]
96    pub captured_at: chrono::DateTime<chrono::Utc>,
97}
98
99/// Persisted browser session entry keyed by user id
100#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
101pub struct BrowserSessionRecord {
102    pub user_id: String,
103    pub state: BrowserSessionState,
104    #[schemars(with = "String")]
105    pub updated_at: chrono::DateTime<chrono::Utc>,
106}