Skip to main content

Module factory

Module factory 

Source
Expand description

Browser factory implementations.

This module provides the BrowserFactory trait and implementations for creating browser instances.

§Overview

The factory pattern abstracts browser creation, allowing:

  • Different browser implementations (Chrome, Chromium, etc.)
  • Custom launch configurations
  • Mock factories for testing

§Available Factories

FactoryDescription
ChromeBrowserFactoryCreates Chrome/Chromium browsers
mock::MockBrowserFactoryFor testing (feature-gated)

§Example

use html2pdf_api::{BrowserFactory, ChromeBrowserFactory};

// Create factory with auto-detected Chrome
let factory = ChromeBrowserFactory::with_defaults();

// Create a browser
let browser = factory.create()?;

§Custom Factory

You can implement BrowserFactory for custom browser creation:

use html2pdf_api::{BrowserFactory, BrowserPoolError, Result};
use headless_chrome::Browser;

struct MyCustomFactory {
    // your configuration
}

impl BrowserFactory for MyCustomFactory {
    fn create(&self) -> Result<Browser> {
        // Your custom browser creation logic
        todo!()
    }
}

Modules§

mock
Mock browser factory for testing.

Structs§

ChromeBrowserFactory
Factory for creating Chrome/Chromium browser instances.

Traits§

BrowserFactory
Trait for browser factory pattern.

Functions§

create_chrome_options
Create Chrome launch options with optional custom path.