create_chrome_options

Function create_chrome_options 

Source
pub fn create_chrome_options(
    chrome_path: Option<&str>,
) -> Result<LaunchOptions<'static>, Box<dyn Error + Send + Sync>>
Expand description

Create Chrome launch options with optional custom path.

This function generates production-ready Chrome launch options with:

  • Memory optimization flags
  • GPU acceleration disabled (for headless stability)
  • Unnecessary features disabled
  • Security settings for automation

§Parameters

  • chrome_path - Optional custom Chrome binary path. If None, auto-detects.

§Returns

LaunchOptions configured for stable headless operation.

§Errors

Returns error if options builder fails (rare, usually a bug).

§Chrome Flags Applied

§Memory and Performance

  • --disable-dev-shm-usage - Use /tmp instead of /dev/shm (container-friendly)
  • --disable-crash-reporter - No crash reporting
  • --max_old_space_size=1024 - Limit V8 heap to 1GB

§GPU and Rendering

  • --disable-gpu-compositing
  • --disable-software-rasterizer
  • --disable-accelerated-2d-canvas
  • --disable-gl-drawing-for-tests
  • --disable-webgl
  • --disable-webgl2

§Disabled Features

  • --disable-extensions
  • --disable-plugins
  • --disable-sync
  • --disable-default-apps

§Security and Automation

  • --disable-web-security - Allow cross-origin requests (for scraping)
  • --enable-automation - Mark as automated browser

§Stability

  • --disable-background-timer-throttling
  • --disable-backgrounding-occluded-windows
  • --disable-hang-monitor
  • --disable-popup-blocking
  • --disable-renderer-backgrounding
  • --disable-ipc-flooding-protection

§Example

use html2pdf_api::create_chrome_options;

// Auto-detect Chrome path
let options = create_chrome_options(None)?;

// Custom Chrome path
let options = create_chrome_options(Some("/usr/bin/chromium"))?;