Config class controls browser launch parameters, behavior, and Chrome command-line arguments. It provides a flexible way to customize your browser automation setup.
Creating a configuration
You can create a Config object explicitly or let the browser create one automatically:When you don’t provide a Config object, nodriver creates one with sensible defaults automatically.
Configuration parameters
User data directory
Specify where browser profile data is stored:Path to the browser profile directory. If not specified, a temporary directory is created and cleaned up on exit.
- Persist cookies and login sessions between runs
- Maintain browser extensions
- Store cached data
When you provide a custom
user_data_dir, it will NOT be automatically deleted. When using the auto-generated directory, it’s cleaned up when the browser closes.Headless mode
Run the browser without a visible window. Uses the new
--headless=new flag.- Server environments without displays
- Automated testing pipelines
- Background scraping tasks
- When you don’t need visual feedback
Browser executable
Path to the Chrome/Chromium executable. Auto-detected if not provided.
- Google Chrome
- Chromium
- Chrome Beta
- Chrome Canary
/usr/bin/google-chrome/usr/bin/chromium/Applications/Google Chrome.app/Contents/MacOS/Google Chrome(macOS)
C:\Program Files\Google\Chrome\Application\chrome.exeC:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Browser arguments
Additional command-line arguments passed to Chrome.
Sandbox mode
Enable Chrome’s sandbox for security. Automatically disabled when running as root on Linux.
On Linux systems, if you’re running as root, sandbox is automatically disabled even if you set
sandbox=True.Language
Browser language setting.
Connection settings
Host for the DevTools Protocol connection. Defaults to “127.0.0.1” when starting a new browser.
Port for the DevTools Protocol connection. Auto-assigned to a free port when starting a new browser.
When both
host and port are specified, nodriver connects to an existing browser instead of launching a new one.Expert mode
Enable expert mode with additional debugging capabilities.
--disable-site-isolation-trialsflag- Ensures shadow roots are always in “open” mode
- Additional debugging scripts
Expert mode is useful for development and debugging but may affect page behavior.
Target discovery
Automatically discover and track new browser targets (tabs, windows, iframes).
- New tabs are opened
- Windows are created
- Tabs are closed
- Target information changes
Default browser arguments
nodriver includes sensible defaults that are always applied:Extensions
Load browser extensions:Path to extension folder (containing manifest.json) or .crx file.
Inspecting configuration
Get the final list of arguments:Utility functions
Find Chrome executable
Manually find Chrome installation:Create temporary profile
Generate a temp directory path:Check if root
Platform detection
Common configurations
Development setup
Production scraping
Docker environment
With persistent profile
Connect to remote browser
Best practices
Use persistent profiles for login sessions
Use persistent profiles for login sessions
When you need to maintain login state across runs:The first run will be clean, but subsequent runs will have cookies, cache, and local storage preserved.
Disable sandbox only when necessary
Disable sandbox only when necessary
The sandbox provides security isolation. Only disable it when:
- Running in Docker containers
- Running as root (automatically disabled)
- Encountering sandbox-related crashes
Start with minimal arguments
Start with minimal arguments
Begin with default configuration and add arguments only when needed. Too many arguments can cause conflicts or unexpected behavior.
Test headless mode separately
Test headless mode separately
Some websites behave differently in headless mode. Test both modes to ensure compatibility.
Keep extensions minimal
Keep extensions minimal
Each extension increases resource usage and may affect page behavior. Only load necessary extensions.
Troubleshooting
Browser won’t start
Chrome not found
Connection refused
Out of memory in Docker
Related documentation
- Browser management - Using the configured browser
- Tab management - Working with browser tabs
- Quick start - Getting started guide