Browser Managers
The managers module provides specialized classes for managing different aspects of browser lifecycle and configuration.
Overview
Browser managers handle specific responsibilities in browser automation:
pydoll.browser.managers
ChromiumOptionsManager
Bases: BrowserOptionsManager
Manages browser options configuration for Chromium-based browsers.
Handles options creation, validation, and applies default CDP arguments for Chrome and Edge browsers.
initialize_options
Initialize and validate browser options.
Creates ChromiumOptions if none provided, validates existing options, and applies default CDP arguments.
RETURNS | DESCRIPTION |
---|---|
ChromiumOptions
|
Properly configured ChromiumOptions instance. |
RAISES | DESCRIPTION |
---|---|
InvalidOptionsObject
|
If provided options is not ChromiumOptions. |
BrowserProcessManager
Manages browser process lifecycle for CDP automation.
Handles process creation, monitoring, and termination with proper resource cleanup and graceful shutdown.
Initialize browser process manager.
PARAMETER | DESCRIPTION |
---|---|
process_creator
|
Custom function to create browser processes. Must accept command list and return subprocess.Popen object. Uses default subprocess implementation if None.
TYPE:
|
start_browser_process
Launch browser process with CDP debugging enabled.
PARAMETER | DESCRIPTION |
---|---|
binary_location
|
Path to browser executable.
TYPE:
|
port
|
TCP port for CDP WebSocket connections.
TYPE:
|
arguments
|
Additional command-line arguments.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Popen
|
Started browser process instance. |
Note
Automatically adds --remote-debugging-port argument.
ProxyManager
Manages proxy configuration and credentials for CDP automation.
Extracts embedded credentials from proxy URLs, secures authentication information, and sanitizes command-line arguments.
Initialize proxy manager with browser options.
PARAMETER | DESCRIPTION |
---|---|
options
|
Browser options potentially containing proxy configuration. Will be modified if credentials are found.
TYPE:
|
get_proxy_credentials
Extract and secure proxy authentication credentials.
Searches for proxy settings, extracts embedded credentials, and sanitizes options to remove credential exposure.
RETURNS | DESCRIPTION |
---|---|
tuple[bool, tuple[Optional[str], Optional[str]]]
|
Tuple of (has_private_proxy, (username, password)). |
TempDirectoryManager
Manages temporary directory lifecycle for CDP browser automation.
Creates isolated temporary directories for browser profiles and handles secure cleanup with retry mechanisms for locked files.
Initialize temporary directory manager.
PARAMETER | DESCRIPTION |
---|---|
temp_dir_factory
|
Function to create temporary directories. Must return TemporaryDirectory-compatible object.
TYPE:
|
create_temp_dir
Create and track new temporary directory for browser use.
RETURNS | DESCRIPTION |
---|---|
TemporaryDirectory
|
TemporaryDirectory object for browser --user-data-dir argument. |
retry_process_file
staticmethod
Execute file operation with retry logic for locked files.
PARAMETER | DESCRIPTION |
---|---|
func
|
Function to execute on path.
TYPE:
|
path
|
File or directory path to operate on.
TYPE:
|
retry_times
|
Maximum retry attempts (negative = unlimited).
TYPE:
|
RAISES | DESCRIPTION |
---|---|
PermissionError
|
If operation fails after all retries. |
handle_cleanup_error
Handle errors during directory cleanup with browser-specific workarounds.
PARAMETER | DESCRIPTION |
---|---|
func
|
Original function that failed.
TYPE:
|
path
|
Path that could not be processed.
TYPE:
|
exc_info
|
Exception information tuple.
TYPE:
|
Note
Handles Chromium-specific locked files like CrashpadMetrics.
Manager Classes
Browser Process Manager
Manages the browser process lifecycle, including starting, stopping, and monitoring browser processes.
pydoll.browser.managers.browser_process_manager
BrowserProcessManager
Manages browser process lifecycle for CDP automation.
Handles process creation, monitoring, and termination with proper resource cleanup and graceful shutdown.
Initialize browser process manager.
PARAMETER | DESCRIPTION |
---|---|
process_creator
|
Custom function to create browser processes. Must accept command list and return subprocess.Popen object. Uses default subprocess implementation if None.
TYPE:
|
start_browser_process
Launch browser process with CDP debugging enabled.
PARAMETER | DESCRIPTION |
---|---|
binary_location
|
Path to browser executable.
TYPE:
|
port
|
TCP port for CDP WebSocket connections.
TYPE:
|
arguments
|
Additional command-line arguments.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Popen
|
Started browser process instance. |
Note
Automatically adds --remote-debugging-port argument.
Browser Options Manager
Handles browser configuration options and command-line arguments.
pydoll.browser.managers.browser_options_manager
ChromiumOptionsManager
Bases: BrowserOptionsManager
Manages browser options configuration for Chromium-based browsers.
Handles options creation, validation, and applies default CDP arguments for Chrome and Edge browsers.
initialize_options
Initialize and validate browser options.
Creates ChromiumOptions if none provided, validates existing options, and applies default CDP arguments.
RETURNS | DESCRIPTION |
---|---|
ChromiumOptions
|
Properly configured ChromiumOptions instance. |
RAISES | DESCRIPTION |
---|---|
InvalidOptionsObject
|
If provided options is not ChromiumOptions. |
Proxy Manager
Manages proxy configuration and authentication for browser instances.
pydoll.browser.managers.proxy_manager
ProxyManager
Manages proxy configuration and credentials for CDP automation.
Extracts embedded credentials from proxy URLs, secures authentication information, and sanitizes command-line arguments.
Initialize proxy manager with browser options.
PARAMETER | DESCRIPTION |
---|---|
options
|
Browser options potentially containing proxy configuration. Will be modified if credentials are found.
TYPE:
|
get_proxy_credentials
Extract and secure proxy authentication credentials.
Searches for proxy settings, extracts embedded credentials, and sanitizes options to remove credential exposure.
RETURNS | DESCRIPTION |
---|---|
tuple[bool, tuple[Optional[str], Optional[str]]]
|
Tuple of (has_private_proxy, (username, password)). |
Temporary Directory Manager
Handles creation and cleanup of temporary directories used by browser instances.
pydoll.browser.managers.temp_dir_manager
TempDirectoryManager
Manages temporary directory lifecycle for CDP browser automation.
Creates isolated temporary directories for browser profiles and handles secure cleanup with retry mechanisms for locked files.
Initialize temporary directory manager.
PARAMETER | DESCRIPTION |
---|---|
temp_dir_factory
|
Function to create temporary directories. Must return TemporaryDirectory-compatible object.
TYPE:
|
create_temp_dir
Create and track new temporary directory for browser use.
RETURNS | DESCRIPTION |
---|---|
TemporaryDirectory
|
TemporaryDirectory object for browser --user-data-dir argument. |
retry_process_file
staticmethod
Execute file operation with retry logic for locked files.
PARAMETER | DESCRIPTION |
---|---|
func
|
Function to execute on path.
TYPE:
|
path
|
File or directory path to operate on.
TYPE:
|
retry_times
|
Maximum retry attempts (negative = unlimited).
TYPE:
|
RAISES | DESCRIPTION |
---|---|
PermissionError
|
If operation fails after all retries. |
handle_cleanup_error
Handle errors during directory cleanup with browser-specific workarounds.
PARAMETER | DESCRIPTION |
---|---|
func
|
Original function that failed.
TYPE:
|
path
|
Path that could not be processed.
TYPE:
|
exc_info
|
Exception information tuple.
TYPE:
|
Note
Handles Chromium-specific locked files like CrashpadMetrics.
Usage
Managers are typically used internally by browser classes like Chrome
and Edge
. They provide modular functionality that can be composed together:
from pydoll.browser.managers.proxy_manager import ProxyManager
from pydoll.browser.managers.temp_dir_manager import TempDirManager
# Managers are used internally by browser classes
# Direct usage is for advanced scenarios only
proxy_manager = ProxyManager()
temp_manager = TempDirManager()
Internal Usage
These managers are primarily used internally by the browser classes. Direct usage is recommended only for advanced scenarios or when extending the library.