use std::{path::PathBuf, time::Duration};
pub(super) enum WaitStrategy {
Navigation,
Selector(String),
Millis(u64),
}
pub struct BrowserConfig {
pub(super) headless: bool,
pub(super) wait_strategy: WaitStrategy,
pub(super) timeout: Duration,
pub(super) viewport: (u32, u32),
pub(super) user_agent: Option<String>,
pub(super) executable: Option<PathBuf>,
pub(super) proxy: Option<String>,
pub(super) stealth: bool,
}
impl BrowserConfig {
pub fn headless() -> Self {
Self {
headless: true,
wait_strategy: WaitStrategy::Navigation,
timeout: Duration::from_secs(30),
viewport: (1920, 1080),
user_agent: None,
executable: None,
proxy: None,
stealth: false,
}
}
pub fn headed() -> Self {
Self {
headless: false,
..Self::headless()
}
}
pub fn wait_for_selector(mut self, selector: impl Into<String>) -> Self {
self.wait_strategy = WaitStrategy::Selector(selector.into());
self
}
pub fn wait_millis(mut self, ms: u64) -> Self {
self.wait_strategy = WaitStrategy::Millis(ms);
self
}
pub fn timeout(mut self, d: Duration) -> Self {
self.timeout = d;
self
}
pub fn viewport(mut self, width: u32, height: u32) -> Self {
self.viewport = (width, height);
self
}
pub fn user_agent(mut self, ua: impl Into<String>) -> Self {
self.user_agent = Some(ua.into());
self
}
pub fn executable(mut self, path: PathBuf) -> Self {
self.executable = Some(path);
self
}
pub fn proxy(mut self, url: impl Into<String>) -> Self {
self.proxy = Some(url.into());
self
}
pub fn stealth(mut self) -> Self {
self.stealth = true;
self
}
}