浏览器管理器
管理器模块提供专门的类来管理浏览器生命周期和配置。
总览
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.
管理器类
浏览器进程管理器
管理浏览器进程的生命周期,包括启动、停止和监控浏览器进程。
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.
浏览器选项管理器
处理浏览器配置选项和命令行参数。
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. |
代理管理器
管理浏览器实例的代理配置和身份验证。
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)). |
临时目录管理器
处理浏览器实例使用的临时目录的创建和清理。
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.
用法
管理器通常由 Chrome 和 Edge 等浏览器类内部使用。它们提供可组合的模块化功能:
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.