Chrome Browser
pydoll.browser.chromium.Chrome
Bases: Browser
Chrome browser implementation for CDP automation.
Initialize Chrome browser instance.
PARAMETER | DESCRIPTION |
---|---|
options
|
Chrome configuration options (default if None).
TYPE:
|
connection_port
|
CDP WebSocket port (random if None).
TYPE:
|
start
async
Start browser process and establish CDP connection.
PARAMETER | DESCRIPTION |
---|---|
headless
|
Run without UI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tab
|
Initial tab for interaction. |
RAISES | DESCRIPTION |
---|---|
FailedToStartBrowser
|
If the browser fails to start or connect. |
stop
async
Stop browser process and cleanup resources.
Sends Browser.close command, terminates process, removes temp directories, and closes WebSocket connections.
RAISES | DESCRIPTION |
---|---|
BrowserNotRunning
|
If the browser is not currently running. |
create_browser_context
async
Create isolated browser context (like incognito).
Browser contexts provide isolated storage and don't share session data. Multiple contexts can exist simultaneously.
PARAMETER | DESCRIPTION |
---|---|
proxy_server
|
Optional proxy for this context only (scheme://host:port).
TYPE:
|
proxy_bypass_list
|
Comma-separated hosts that bypass proxy.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
Browser context ID for use with other methods. |
delete_browser_context
async
Delete browser context and all associated tabs/resources.
Removes all storage (cookies, localStorage, etc.) and closes all tabs. The default browser context cannot be deleted.
Note
Closes all associated tabs immediately.
get_browser_contexts
async
Get all browser context IDs including the default context.
new_tab
async
Create new tab for page interaction.
PARAMETER | DESCRIPTION |
---|---|
url
|
Initial URL (about:blank if empty).
TYPE:
|
browser_context_id
|
Context to create tab in (default if None).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tab
|
Tab instance for page navigation and element interaction. |
get_targets
async
Get all active targets/pages in browser.
Targets include pages, service workers, shared workers, and browser process. Useful for debugging and managing multiple tabs.
RETURNS | DESCRIPTION |
---|---|
list[TargetInfo]
|
List of TargetInfo objects. |
get_opened_tabs
async
Get all opened tabs that are not extensions and have the type 'page'
RETURNS | DESCRIPTION |
---|---|
list[Tab]
|
List of Tab instances. The last tab is the most recent one. |
set_download_path
async
Set download directory path (convenience method for set_download_behavior).
set_download_behavior
async
Configure download handling.
PARAMETER | DESCRIPTION |
---|---|
behavior
|
ALLOW (save to path), DENY (cancel), or DEFAULT.
TYPE:
|
download_path
|
Required if behavior is ALLOW.
TYPE:
|
browser_context_id
|
Context to apply to (default if None).
TYPE:
|
events_enabled
|
Generate download events for progress tracking.
TYPE:
|
delete_all_cookies
async
Delete all cookies (session, persistent, third-party) from browser or context.
set_cookies
async
Set multiple cookies in browser or context.
get_window_id_for_target
async
Get window ID for target (used for window manipulation via CDP).
get_window_id
async
Get window ID for any valid tab.
RAISES | DESCRIPTION |
---|---|
NoValidTabFound
|
If no valid attached tab can be found. |
set_window_maximized
async
Maximize browser window (affects all tabs in window).
set_window_bounds
async
Set window position and/or size.
PARAMETER | DESCRIPTION |
---|---|
bounds
|
Properties to modify (left, top, width, height, windowState). Only specified properties are changed.
TYPE:
|
grant_permissions
async
Grant browser permissions (geolocation, notifications, camera, etc.).
Bypasses normal permission prompts for automated testing.
PARAMETER | DESCRIPTION |
---|---|
permissions
|
Permissions to grant.
TYPE:
|
origin
|
Origin to grant to (all origins if None).
TYPE:
|
browser_context_id
|
Context to apply to (default if None).
TYPE:
|
reset_permissions
async
Reset all permissions to defaults and restore prompting behavior.
on
async
Register CDP event listener at browser level.
Callback runs in background task to prevent blocking. Affects all pages/targets.
PARAMETER | DESCRIPTION |
---|---|
event_name
|
CDP event name (e.g., "Network.responseReceived").
TYPE:
|
callback
|
Function called on event (sync or async).
TYPE:
|
temporary
|
Remove after first invocation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Callback ID for removal. |
Note
For page-specific events, use Tab.on() instead.
enable_fetch_events
async
Enable network request interception via Fetch domain.
Allows monitoring, modifying, or blocking requests before they're sent. All matching requests are paused until explicitly continued.
PARAMETER | DESCRIPTION |
---|---|
handle_auth_requests
|
Intercept authentication challenges.
TYPE:
|
resource_type
|
Filter by type (XHR, Fetch, Document, etc.). Empty = all.
TYPE:
|
Note
Paused requests must be continued or they will timeout.
disable_fetch_events
async
Disable request interception and release any paused requests.