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
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
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:
|
RETURNS | DESCRIPTION |
---|---|
Command[Response]
|
Command[Response]: The CDP command that returns a basic success response. |
cancel_download
staticmethod
Generates a command to cancel a download.
PARAMETER | DESCRIPTION |
---|---|
guid
|
Global unique identifier of the download.
TYPE:
|
browser_context_id
|
The browser context the download belongs to. If not specified, uses the default context.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Command[Response]
|
Command[Response]: The CDP command that returns a basic success response. |
crash
staticmethod
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
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
Generates a command to set the download behavior for the browser.
PARAMETER | DESCRIPTION |
---|---|
behavior
|
The behavior to set for downloads.
TYPE:
|
download_path
|
The path to set for downloads.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Command[Response]
|
Command[Response]: The CDP command that returns a basic success response after setting the download path. |
close
staticmethod
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
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:
|
RETURNS | DESCRIPTION |
---|---|
Command[GetWindowForTargetResponse]
|
Command[GetWindowForTargetResponse]: The CDP command that returns window information including windowId and bounds. |
set_window_bounds
staticmethod
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:
|
bounds
|
The bounds to set for the window, which should include windowState and optionally width, height, x, and y coordinates.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Command[Response]
|
Command[Response]: The CDP command that returns a basic success response after setting the window bounds. |
set_window_maximized
staticmethod
Generates a command to maximize a window.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
The ID of the window to maximize.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Command[Response]
|
Command[Response]: The CDP command that returns a basic success response after maximizing the window. |
set_window_minimized
staticmethod
Generates a command to minimize a window.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
The ID of the window to minimize.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Command[Response]
|
Command[Response]: The CDP command that returns a basic success response after minimizing the window. |
grant_permissions
staticmethod
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:
|
origin
|
The origin to grant permissions to. If not specified, grants for all origins.
TYPE:
|
browser_context_id
|
The browser context to grant permissions in. If not specified, uses the default context.
TYPE:
|
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.