Skip to content

Chrome Browser

pydoll.browser.chromium.Chrome

Chrome(options=None, connection_port=None)

Bases: Browser

Chrome browser implementation for CDP automation.

Initialize Chrome browser instance.

PARAMETER DESCRIPTION
options

Chrome configuration options (default if None).

TYPE: Optional[ChromiumOptions] DEFAULT: None

connection_port

CDP WebSocket port (random if None).

TYPE: Optional[int] DEFAULT: None

options instance-attribute

options = initialize_options()

start async

start(headless=False)

Start browser process and establish CDP connection.

PARAMETER DESCRIPTION
headless

Run without UI.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Tab

Initial tab for interaction.

RAISES DESCRIPTION
FailedToStartBrowser

If the browser fails to start or connect.

stop async

stop()

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_browser_context(proxy_server=None, proxy_bypass_list=None)

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: Optional[str] DEFAULT: None

proxy_bypass_list

Comma-separated hosts that bypass proxy.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
str

Browser context ID for use with other methods.

delete_browser_context async

delete_browser_context(browser_context_id)

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_browser_contexts()

Get all browser context IDs including the default context.

new_tab async

new_tab(url='', browser_context_id=None)

Create new tab for page interaction.

PARAMETER DESCRIPTION
url

Initial URL (about:blank if empty).

TYPE: str DEFAULT: ''

browser_context_id

Context to create tab in (default if None).

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Tab

Tab instance for page navigation and element interaction.

get_targets async

get_targets()

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_opened_tabs()

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_path(path, browser_context_id=None)

Set download directory path (convenience method for set_download_behavior).

set_download_behavior async

set_download_behavior(behavior, download_path=None, browser_context_id=None, events_enabled=False)

Configure download handling.

PARAMETER DESCRIPTION
behavior

ALLOW (save to path), DENY (cancel), or DEFAULT.

TYPE: DownloadBehavior

download_path

Required if behavior is ALLOW.

TYPE: Optional[str] DEFAULT: None

browser_context_id

Context to apply to (default if None).

TYPE: Optional[str] DEFAULT: None

events_enabled

Generate download events for progress tracking.

TYPE: bool DEFAULT: False

delete_all_cookies async

delete_all_cookies(browser_context_id=None)

Delete all cookies (session, persistent, third-party) from browser or context.

set_cookies async

set_cookies(cookies, browser_context_id=None)

Set multiple cookies in browser or context.

get_cookies async

get_cookies(browser_context_id=None)

Get all cookies from browser or context.

get_version async

get_version()

Get browser version and CDP protocol information.

get_window_id_for_target async

get_window_id_for_target(target_id)

Get window ID for target (used for window manipulation via CDP).

get_window_id_for_tab async

get_window_id_for_tab(tab)

Get window ID for tab (convenience method).

get_window_id async

get_window_id()

Get window ID for any valid tab.

RAISES DESCRIPTION
NoValidTabFound

If no valid attached tab can be found.

set_window_maximized async

set_window_maximized()

Maximize browser window (affects all tabs in window).

set_window_minimized async

set_window_minimized()

Minimize browser window to taskbar/dock.

set_window_bounds async

set_window_bounds(bounds)

Set window position and/or size.

PARAMETER DESCRIPTION
bounds

Properties to modify (left, top, width, height, windowState). Only specified properties are changed.

TYPE: WindowBoundsDict

grant_permissions async

grant_permissions(permissions, origin=None, browser_context_id=None)

Grant browser permissions (geolocation, notifications, camera, etc.).

Bypasses normal permission prompts for automated testing.

PARAMETER DESCRIPTION
permissions

Permissions to grant.

TYPE: list[PermissionType]

origin

Origin to grant to (all origins if None).

TYPE: Optional[str] DEFAULT: None

browser_context_id

Context to apply to (default if None).

TYPE: Optional[str] DEFAULT: None

reset_permissions async

reset_permissions(browser_context_id=None)

Reset all permissions to defaults and restore prompting behavior.

on async

on(event_name, callback, temporary=False)

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: str

callback

Function called on event (sync or async).

TYPE: Callable[[Any], Any]

temporary

Remove after first invocation.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
int

Callback ID for removal.

Note

For page-specific events, use Tab.on() instead.

enable_fetch_events async

enable_fetch_events(handle_auth_requests=False, resource_type=None)

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: bool DEFAULT: False

resource_type

Filter by type (XHR, Fetch, Document, etc.). Empty = all.

TYPE: Optional[ResourceType] DEFAULT: None

Note

Paused requests must be continued or they will timeout.

disable_fetch_events async

disable_fetch_events()

Disable request interception and release any paused requests.

enable_runtime_events async

enable_runtime_events()

Enable runtime events.

disable_runtime_events async

disable_runtime_events()

Disable runtime events.

continue_request async

continue_request(request_id, url=None, method=None, post_data=None, headers=None, intercept_response=None)

Continue paused request without modifications.

fail_request async

fail_request(request_id, error_reason)

Fail request with error code.

fulfill_request async

fulfill_request(request_id, response_code, response_headers=None, body=None, response_phrase=None)

Fulfill request with response data.