viewpoint_core/browser/launcher/
user_data.rs

1//! User data directory configuration for browser profiles.
2
3use std::path::PathBuf;
4
5/// User data directory configuration for browser profiles.
6///
7/// Controls how the browser manages user data (cookies, localStorage, settings).
8/// The default is [`UserDataDir::Temp`], which creates an isolated temporary
9/// directory that is automatically cleaned up when the browser closes.
10///
11/// # Breaking Change
12///
13/// Prior to this change, browsers used the system default profile (`~/.config/chromium/`)
14/// by default. To restore the old behavior, use [`UserDataDir::System`] explicitly:
15///
16/// ```no_run
17/// use viewpoint_core::Browser;
18///
19/// # async fn example() -> Result<(), viewpoint_core::CoreError> {
20/// let browser = Browser::launch()
21///     .user_data_dir_system()
22///     .launch()
23///     .await?;
24/// # Ok(())
25/// # }
26/// ```
27#[derive(Debug, Clone)]
28pub enum UserDataDir {
29    /// Create a unique temporary directory per session.
30    ///
31    /// This is the default mode. Each browser instance gets its own isolated
32    /// profile that is automatically deleted when the browser closes or is dropped.
33    /// This prevents conflicts when running multiple browser instances concurrently.
34    Temp,
35
36    /// Copy a template profile to a temporary directory.
37    ///
38    /// The template directory contents are copied to a new temporary directory.
39    /// The temporary directory is cleaned up when the browser closes.
40    /// The original template directory is unchanged.
41    ///
42    /// Use this when you need pre-configured settings, extensions, or cookies
43    /// as a starting point, but still want isolation between sessions.
44    TempFromTemplate(PathBuf),
45
46    /// Use a persistent directory for browser data.
47    ///
48    /// Browser state (cookies, localStorage, settings) persists in the specified
49    /// directory across browser restarts. The directory is NOT cleaned up when
50    /// the browser closes.
51    ///
52    /// Note: Using the same persistent directory for multiple concurrent browser
53    /// instances will cause profile lock conflicts.
54    Persist(PathBuf),
55
56    /// Use the system default profile.
57    ///
58    /// On Linux, this is typically `~/.config/chromium/`.
59    /// No `--user-data-dir` flag is passed to Chromium.
60    ///
61    /// **Warning**: This can cause conflicts if another Chromium instance is running,
62    /// or if a previous session crashed without proper cleanup. Prefer [`UserDataDir::Temp`]
63    /// for automation scenarios.
64    System,
65}