cdp_html_shot/browser/
browser_builder.rs

1use anyhow::Result;
2
3use crate::Browser;
4use crate::browser::browser_config::BrowserConfig;
5
6/// Builder for configuring and creating Browser instances.
7pub struct BrowserBuilder {
8    config: BrowserConfig,
9}
10
11impl BrowserBuilder {
12    /// Create a new BrowserBuilder with default configuration.
13    pub fn new() -> Self {
14        Self {
15            config: BrowserConfig::new()
16                .expect("Failed to create default browser config")
17        }
18    }
19
20    /// Set whether the browser should run in headless mode.
21    pub fn headless(mut self, headless: bool) -> Self {
22        self.config.headless = headless;
23        self
24    }
25
26    /// Configure additional options here as needed.
27    // pub fn with_option(mut self, option: Option) -> Self { ... }
28
29    /// Build and launch the browser with the configured options.
30    pub async fn build(self) -> Result<Browser> {
31        Browser::create_browser(self.config).await
32    }
33}
34
35impl Default for BrowserBuilder {
36    fn default() -> Self {
37        Self::new()
38    }
39}