Skip to content

Browser Commands

Browser commands provide low-level control over browser instances and their configuration.

Overview

The browser commands module handles browser-level operations such as version information, target management, and browser-wide settings.

pydoll.commands.browser_commands

BrowserCommands

BrowserCommands class provides a set of commands to interact with the browser's main functionality based on CDP. These commands allow for managing browser windows, such as closing windows, retrieving window IDs, and adjusting window bounds (size and state).

The commands defined in this class provide functionality for: - Managing browser windows and targets. - Setting permissions and download behavior. - Controlling browser windows (size, state). - Retrieving browser information and versioning.

get_version staticmethod

get_version()

Generates a command to get browser version information.

RETURNS DESCRIPTION
Command[GetVersionResponse]

Command[GetVersionResponse]: The CDP command that returns browser version details including protocol version, product name, revision, and user agent.

reset_permissions staticmethod

reset_permissions(browser_context_id=None)

Generates a command to reset all permissions.

PARAMETER DESCRIPTION
browser_context_id

The browser context to reset permissions for. If not specified, resets permissions for the default context.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response.

cancel_download staticmethod

cancel_download(guid, browser_context_id=None)

Generates a command to cancel a download.

PARAMETER DESCRIPTION
guid

Global unique identifier of the download.

TYPE: str

browser_context_id

The browser context the download belongs to. If not specified, uses the default context.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response.

crash staticmethod

crash()

Generates a command to crash the browser main process.

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response before crashing the browser.

crash_gpu_process staticmethod

crash_gpu_process()

Generates a command to crash the browser GPU process.

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response before crashing the GPU process.

set_download_behavior staticmethod

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

Generates a command to set the download behavior for the browser.

PARAMETER DESCRIPTION
behavior

The behavior to set for downloads.

TYPE: DownloadBehavior

download_path

The path to set for downloads.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response after setting the download path.

close staticmethod

close()

Generates a command to close the browser.

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response before closing the browser.

get_window_for_target staticmethod

get_window_for_target(target_id)

Generates a command to get the window for a given target ID.

PARAMETER DESCRIPTION
target_id

The target_id to get the window for.

TYPE: str

RETURNS DESCRIPTION
Command[GetWindowForTargetResponse]

Command[GetWindowForTargetResponse]: The CDP command that returns window information including windowId and bounds.

set_window_bounds staticmethod

set_window_bounds(window_id, bounds)

Generates a command to set the bounds of a window.

PARAMETER DESCRIPTION
window_id

The ID of the window to set the bounds for.

TYPE: int

bounds

The bounds to set for the window, which should include windowState and optionally width, height, x, and y coordinates.

TYPE: WindowBoundsDict

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response after setting the window bounds.

set_window_maximized staticmethod

set_window_maximized(window_id)

Generates a command to maximize a window.

PARAMETER DESCRIPTION
window_id

The ID of the window to maximize.

TYPE: int

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response after maximizing the window.

set_window_minimized staticmethod

set_window_minimized(window_id)

Generates a command to minimize a window.

PARAMETER DESCRIPTION
window_id

The ID of the window to minimize.

TYPE: int

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response after minimizing the window.

grant_permissions staticmethod

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

Generates a command to grant specific permissions to the given origin.

PARAMETER DESCRIPTION
permissions

list of permissions to grant. See PermissionType enum for available permissions.

TYPE: list[PermissionType]

origin

The origin to grant permissions to. If not specified, grants for all origins.

TYPE: Optional[str] DEFAULT: None

browser_context_id

The browser context to grant permissions in. If not specified, uses the default context.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
Command[Response]

Command[Response]: The CDP command that returns a basic success response after granting the specified permissions.

Usage

Browser commands are typically used internally by browser classes to manage browser instances:

from pydoll.commands.browser_commands import get_version
from pydoll.connection.connection_handler import ConnectionHandler

# Get browser version information
connection = ConnectionHandler()
version_info = await get_version(connection)

Available Commands

The browser commands module provides functions for:

  • Getting browser version and user agent information
  • Managing browser targets (tabs, windows)
  • Controlling browser-wide settings and permissions
  • Handling browser lifecycle events

Internal Usage

These commands are primarily used internally by the Chrome and Edge browser classes. Direct usage is recommended only for advanced scenarios.