spider/features/
webdriver_common.rs1use std::time::Duration;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, strum::EnumString, strum::Display)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum WebDriverBrowser {
7 #[default]
8 #[cfg_attr(feature = "serde", serde(rename = "chrome"))]
9 Chrome,
11 #[cfg_attr(feature = "serde", serde(rename = "firefox"))]
12 Firefox,
14 #[cfg_attr(feature = "serde", serde(rename = "edge"))]
15 Edge,
17}
18
19#[derive(Debug, Clone, PartialEq)]
21#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22pub struct WebDriverConfig {
23 pub server_url: String,
25 pub browser: WebDriverBrowser,
27 pub headless: bool,
29 pub browser_args: Option<Vec<String>>,
31 pub timeout: Option<Duration>,
33 pub proxy: Option<String>,
35 pub user_agent: Option<String>,
37 pub viewport_width: Option<u32>,
39 pub viewport_height: Option<u32>,
41 pub accept_insecure_certs: bool,
43 pub page_load_strategy: Option<String>,
45}
46
47impl Default for WebDriverConfig {
48 fn default() -> Self {
49 Self {
50 server_url: "http://localhost:4444".to_string(),
51 browser: WebDriverBrowser::Chrome,
52 headless: true,
53 browser_args: None,
54 timeout: Some(Duration::from_secs(60)),
55 proxy: None,
56 user_agent: None,
57 viewport_width: None,
58 viewport_height: None,
59 accept_insecure_certs: false,
60 page_load_strategy: None,
61 }
62 }
63}
64
65impl WebDriverConfig {
66 pub fn new() -> Self {
68 Self::default()
69 }
70
71 pub fn with_server_url(mut self, server_url: impl Into<String>) -> Self {
73 self.server_url = server_url.into();
74 self
75 }
76
77 pub fn with_browser(mut self, browser: WebDriverBrowser) -> Self {
79 self.browser = browser;
80 self
81 }
82
83 pub fn with_headless(mut self, headless: bool) -> Self {
85 self.headless = headless;
86 self
87 }
88
89 pub fn with_browser_args(mut self, args: Vec<String>) -> Self {
91 self.browser_args = Some(args);
92 self
93 }
94
95 pub fn with_timeout(mut self, timeout: Duration) -> Self {
97 self.timeout = Some(timeout);
98 self
99 }
100
101 pub fn with_proxy(mut self, proxy: impl Into<String>) -> Self {
103 self.proxy = Some(proxy.into());
104 self
105 }
106
107 pub fn with_user_agent(mut self, user_agent: impl Into<String>) -> Self {
109 self.user_agent = Some(user_agent.into());
110 self
111 }
112
113 pub fn with_viewport(mut self, width: u32, height: u32) -> Self {
115 self.viewport_width = Some(width);
116 self.viewport_height = Some(height);
117 self
118 }
119
120 pub fn with_accept_insecure_certs(mut self, accept: bool) -> Self {
122 self.accept_insecure_certs = accept;
123 self
124 }
125
126 pub fn with_page_load_strategy(mut self, strategy: impl Into<String>) -> Self {
128 self.page_load_strategy = Some(strategy.into());
129 self
130 }
131
132 pub fn build(self) -> Self {
134 self
135 }
136}
137
138#[derive(Debug, Clone, Default, PartialEq)]
140#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
141pub struct WebDriverInterceptConfiguration {
142 pub enabled: bool,
144}
145
146impl WebDriverInterceptConfiguration {
147 pub fn new(enabled: bool) -> Self {
149 Self { enabled }
150 }
151}