Patcher class is responsible for downloading, patching, and managing ChromeDriver binaries to make them undetectable by anti-bot systems.
How Patching Works
Websites detect automated browsers by looking for specific signatures in ChromeDriver. The Patcher class:- Downloads the correct ChromeDriver version matching your Chrome browser
- Scans the binary for detection code blocks (specifically
window.cdc_*properties) - Replaces detection code with harmless console.log statements
- Verifies the patch was successful
The Detection Vector
ChromeDriver injects code into the browser that creates properties like:window.cdc_adoQpoasnfa76pfcZLmcfl_Arraywindow.cdc_adoQpoasnfa76pfcZLmcfl_Promisewindow.cdc_adoQpoasnfa76pfcZLmcfl_Symbol
Automatic Usage
In most cases, you don’t need to interact with the Patcher directly:- Creates a Patcher instance
- Downloads and patches ChromeDriver if needed
- Verifies the patch
- Cleans up temporary files on exit
Manual Patching
For multiprocessing scenarios, you must patch ChromeDriver before spawning processes:Constructor Parameters
version_main
Type:intRequired: Yes The major version of Chrome (e.g., 120, 121, 122). Used to download the matching ChromeDriver version.
driver_executable_path
Type:str | NoneDefault:
None (automatic)
Path where the patched ChromeDriver should be saved. If None, creates a unique path in the data directory.
user_multi_procs
Type:boolDefault:
False
When True, prevents automatic patching in the constructor. Required for multiprocessing to avoid conflicts.
Methods
patch() (Static)
Downloads, patches, and saves a ChromeDriver binary. This is the main method for manual patching.browser_executable_path(optional): Path to Chrome browserdriver_executable_path(optional): Where to save patched driver
verify()
Verifies that a patched ChromeDriver binary exists and is valid.is_binary_patched()
Checks if a specific binary has been patched by looking for the marker string.cleanup_unused_files()
Removes old ChromeDriver binaries from the data directory.Data Directory
Patched ChromeDriver binaries are stored in a platform-specific directory:- Windows:
~/AppData/Roaming/undetected - Linux:
~/.local/share/undetected - macOS:
~/Library/Application Support/undetected - AWS Lambda:
/tmp/undetected
Chrome Version Detection
The Patcher automatically detects Chrome versions:Old ChromeDriver (≤114)
Downloads from:https://chromedriver.storage.googleapis.com
New ChromeDriver (≥115)
Downloads from:https://googlechromelabs.github.io/chrome-for-testing
Platform Support
The Patcher automatically detects your platform and downloads the correct binary:- Windows:
chromedriver.exe(win32) - Linux:
chromedriver(linux64) - macOS:
chromedriver(mac-x64 for newer versions, mac64 for older)
Multiprocessing Considerations
The Patcher uses aLock to prevent race conditions when multiple processes try to patch the same binary:
Lifecycle Management
The Patcher automatically cleans up temporary binaries when the driver quits:Temporary binaries are NOT deleted when
user_multi_procs=True or when using a custom driver path.Advanced: Direct Usage
Error Handling
The Patcher will raise exceptions in several scenarios:Related
- Chrome Driver - Learn about the Chrome class
- Multiprocessing - Using Patcher with multiple processes