Chrome class is the core component of Undetected. It extends Selenium’s WebDriver to provide an undetectable Chrome browser instance that automatically downloads, patches, and manages ChromeDriver.
Basic Usage
How It Works
The Chrome class automatically:- Detects your Chrome version - Finds your installed Chrome browser and determines its version
- Downloads the matching ChromeDriver - Fetches the correct ChromeDriver binary for your Chrome version
- Patches the driver - Removes detection vectors from the ChromeDriver binary
- Configures optimal settings - Sets up arguments and options to avoid detection
- Manages the browser lifecycle - Handles startup, cleanup, and temporary profiles
Key Parameters
options
Type:ChromeOptions | NoneDefault:
None (automatic useful defaults)
Takes an instance of ChromeOptions to customize browser behavior. Anything other than the default (e.g., extensions or custom startup options) may lower undetectability.
user_data_dir
Type:str | NoneDefault:
None (creates temporary profile)
Path to a Chrome profile directory. If specified, uses that profile and disables automatic cleanup on exit. If None, creates a temporary profile that is deleted when the driver quits.
driver_executable_path
Type:str | NoneDefault:
None (downloads and patches new binary)
Path to the ChromeDriver executable. If not specified, the driver is automatically downloaded and patched.
browser_executable_path
Type:str | NoneDefault:
None (uses automatic detection)
Path to the Chrome browser executable. If not specified, the library searches for Chrome in standard locations.
port
Type:intDefault:
0 (automatic)
Port used by the ChromeDriver executable (not the debugger port). The default value of 0 automatically picks an available port.
enable_cdp_events
Type:boolDefault:
False
Enables Chrome DevTools Protocol (CDP) event handling. When enabled, you can subscribe to CDP events:
advanced_elements
Type:boolDefault:
False
Makes WebElements display more readable representations, especially useful in interactive environments.
Standard representation:
headless
Type:boolDefault:
False
Runs the browser in headless mode. Warning: This lowers undetectability and is not fully supported.
use_subprocess
Type:boolDefault:
True
False(recommended): Chrome runs in its own process, fixing issues with multithreading and cleanupTrue: Chrome starts as a subprocess, useful for simple scripts that exit immediately
no_sandbox
Type:boolDefault:
True
Uses the --no-sandbox option and suppresses the “unsecure option” status bar. Default is True because Chrome won’t start as root without this flag.
user_multi_procs
Type:boolDefault:
False
Set to True when using multithreading or multiprocessing. Prevents multiple processes from trying to modify a binary that’s in use by another process.
See Multiprocessing for details.
Special Methods
reconnect()
Reconnects to the browser by stopping and restarting the ChromeDriver service. Useful for evading heavy detection methods.find_elements_recursive()
Finds elements across all frames in the page. Returns a generator that yields elements while maintaining the correct frame context.add_cdp_listener()
Subscribes to Chrome DevTools Protocol events (requiresenable_cdp_events=True).
clear_cdp_listeners()
Removes all registered CDP event listeners.Context Manager Support
The Chrome class supports Python’s context manager protocol:Important Notes
Chrome has everything included to work out of the box. It does not need customizations. Any customizations MAY trigger bot mitigation systems.
Related
- ChromeOptions - Customize browser configuration
- Patcher - Understand how ChromeDriver is patched
- Multiprocessing - Use Undetected with multiple processes