Overview
The Config class manages browser configuration options. While you can create Config instances directly, most users should use thestart() function which handles configuration automatically.
Constructor
Parameters
Directory to store browser user data. Must be unique if using multiple browsers. If not specified, a temporary directory is created.
Launch browser in headless mode (no visible window).
Path to browser executable. If not specified, auto-detects Chrome or Brave.
Which browser to use:
"chrome", "brave", or "auto" (tries Chrome first, then Brave).Additional command-line arguments for the browser.Example:
["--some-chromeparam=somevalue", "--some-other-param=someval"]Enable browser sandboxing. When False, adds
--no-sandbox to browser parameters. Automatically set to False when running as root on Linux.Language string (e.g.,
"en-US") to use instead of the default "en-US,en;q=0.9".Host address for connecting to an existing debuggable browser.
Port number for connecting to an existing debuggable browser.
Enable expert mode. Includes parameters like
--disable-web-security and --disable-site-isolation-trials, plus debugging scripts (e.g., ensuring shadow-root is always “open”).Timeout in seconds between browser connection attempts.
Maximum number of connection attempts.
Custom user agent string.
Disable WebRTC to prevent IP leaks.
Disable WebGL.
Additional keyword arguments accessible as attributes.
Properties
user_data_dir
Get or set the user data directory.browser_args
Get the combined list of browser arguments.uses_custom_data_dir
Check if a custom user data directory was set.True if user specified a custom data directory.
Methods
add_argument()
Add a custom browser argument.Browser command-line argument (e.g.,
"--disable-gpu").headless, data-dir, no-sandbox, or lang - use Config properties instead.
add_extension()
Add a browser extension to load.Path to extension folder (containing manifest) or extension file (.crx).
_call_()
Get the list of arguments to pass to the browser.Complete list of browser command-line arguments.
Default browser arguments
The Config class includes these default arguments:Helper functions
find_executable()
Find the browser executable path.Browser to find:
"chrome", "brave", or "auto".Path to the browser executable.
FileNotFoundError if no browser is found.
temp_profile_dir()
Generate a temporary profile directory path.Path to temporary directory.
is_root()
Check if running as root/administrator.True if running with elevated privileges.
Examples
Basic configuration
Custom configuration
Add custom arguments
Add extension
Connect to existing browser
Expert mode
Multiple browser instances
Get final arguments
Reuse configuration template
Notes
- Config instances are typically created once and reused
- When using multiple browsers, each must have a unique
user_data_dir - If
user_data_diris not specified, a temporary directory is created and cleaned up automatically - On Linux as root,
sandboxis automatically set to False - The
expertmode is useful for debugging but may reduce security - Custom arguments cannot override certain protected parameters
Related
- start() - Recommended way to start browser with configuration
- Browser - Browser class that uses Config
- Browser.create() - Alternative to start() for creating browsers