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 |
---|---|
GetVersionCommand
|
The CDP command that returns browser version details including protocol version, product name, revision, and user agent.
TYPE:
|
get_browser_command_line
staticmethod
Returns the command line switches for the browser process.
RETURNS | DESCRIPTION |
---|---|
GetBrowserCommandLineCommand
|
The CDP command that returns command line arguments. |
Note: Only works if --enable-automation is on the command line.
get_histograms
staticmethod
Get Chrome histograms.
PARAMETER | DESCRIPTION |
---|---|
query
|
Requested substring in name. Only histograms which have query as a substring in their name are extracted. An empty or absent query returns all histograms.
TYPE:
|
delta
|
If true, retrieve delta since last delta call.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GetHistogramsCommand
|
The CDP command that returns histogram data.
TYPE:
|
get_histogram
staticmethod
Get a Chrome histogram by name.
PARAMETER | DESCRIPTION |
---|---|
name
|
Requested histogram name.
TYPE:
|
delta
|
If true, retrieve delta since last delta call.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GetHistogramCommand
|
The CDP command that returns histogram data.
TYPE:
|
get_window_bounds
staticmethod
Get position and size of the browser window.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GetWindowBoundsCommand
|
The CDP command that returns window bounds information.
TYPE:
|
get_window_for_target
staticmethod
Get the browser window that contains the devtools target.
PARAMETER | DESCRIPTION |
---|---|
target_id
|
Devtools agent host id. If called as a part of the session, associated targetId is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GetWindowForTargetCommand
|
The CDP command that returns window information including windowId and bounds. |
set_window_bounds
staticmethod
Set position and/or size of the browser window.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
bounds
|
New window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetWindowBoundsCommand
|
The CDP command that sets window bounds.
TYPE:
|
set_contents_size
staticmethod
Set size of the browser contents resizing browser window as necessary.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
width
|
The window contents width in DIP. Assumes current width if omitted. Must be specified if 'height' is omitted.
TYPE:
|
height
|
The window contents height in DIP. Assumes current height if omitted. Must be specified if 'width' is omitted.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetContentsSizeCommand
|
The CDP command that sets window contents size.
TYPE:
|
set_dock_tile
staticmethod
Set dock tile details, platform-specific.
PARAMETER | DESCRIPTION |
---|---|
badge_label
|
Optional badge label.
TYPE:
|
image
|
Png encoded image (base64 string when passed over JSON).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetDockTileCommand
|
The CDP command that sets dock tile details.
TYPE:
|
execute_browser_command
staticmethod
Invoke custom browser commands used by telemetry.
PARAMETER | DESCRIPTION |
---|---|
command_id
|
Browser command identifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ExecuteBrowserCommandCommand
|
The CDP command that executes browser command. |
add_privacy_sandbox_enrollment_override
staticmethod
Allows a site to use privacy sandbox features that require enrollment without the site actually being enrolled. Only supported on page targets.
PARAMETER | DESCRIPTION |
---|---|
url
|
Site URL.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AddPrivacySandboxEnrollmentOverrideCommand
|
The CDP command that adds enrollment |
AddPrivacySandboxEnrollmentOverrideCommand
|
override. |
add_privacy_sandbox_coordinator_key_config
staticmethod
add_privacy_sandbox_coordinator_key_config(api, coordinator_origin, key_config, browser_context_id=None)
Configures encryption keys used with a given privacy sandbox API to talk to a trusted coordinator. Since this is intended for test automation only, coordinatorOrigin must be a .test domain. No existing coordinator configuration for the origin may exist.
PARAMETER | DESCRIPTION |
---|---|
api
|
Privacy Sandbox API type.
TYPE:
|
coordinator_origin
|
Coordinator origin (must be .test domain).
TYPE:
|
key_config
|
Key configuration string.
TYPE:
|
browser_context_id
|
BrowserContext to perform the action in. When omitted, default browser context is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AddPrivacySandboxCoordinatorKeyConfigCommand
|
The CDP command that adds key config. |
set_permission
staticmethod
Set permission settings for given origin.
PARAMETER | DESCRIPTION |
---|---|
permission
|
Descriptor of permission to override.
TYPE:
|
setting
|
Setting of the permission.
TYPE:
|
origin
|
Origin the permission applies to, all origins if not specified.
TYPE:
|
browser_context_id
|
Context to override. When omitted, default browser context is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetPermissionCommand
|
The CDP command that sets permission.
TYPE:
|
grant_permissions
staticmethod
Grant specific permissions to the given origin and reject all others.
PARAMETER | DESCRIPTION |
---|---|
permissions
|
List of permissions to grant.
TYPE:
|
origin
|
Origin the permission applies to, all origins if not specified.
TYPE:
|
browser_context_id
|
BrowserContext to override permissions. When omitted, default browser context is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GrantPermissionsCommand
|
The CDP command that grants permissions.
TYPE:
|
reset_permissions
staticmethod
Reset all permission management for all origins.
PARAMETER | DESCRIPTION |
---|---|
browser_context_id
|
BrowserContext to reset permissions. When omitted, default browser context is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ResetPermissionsCommand
|
The CDP command that resets permissions.
TYPE:
|
set_download_behavior
staticmethod
Set the behavior when downloading a file.
PARAMETER | DESCRIPTION |
---|---|
behavior
|
Whether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny). allowAndName allows download and names files according to their download guids.
TYPE:
|
browser_context_id
|
BrowserContext to set download behavior. When omitted, default browser context is used.
TYPE:
|
download_path
|
The default path to save downloaded files to. This is required if behavior is set to 'allow' or 'allowAndName'.
TYPE:
|
events_enabled
|
Whether to emit download events (defaults to false).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetDownloadBehaviorCommand
|
The CDP command that sets download behavior. |
cancel_download
staticmethod
Cancel a download if in progress.
PARAMETER | DESCRIPTION |
---|---|
guid
|
Global unique identifier of the download.
TYPE:
|
browser_context_id
|
BrowserContext to perform the action in. When omitted, default browser context is used.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
CancelDownloadCommand
|
The CDP command that cancels download.
TYPE:
|
close
staticmethod
Close browser gracefully.
RETURNS | DESCRIPTION |
---|---|
CloseCommand
|
The CDP command that closes the browser.
TYPE:
|
crash
staticmethod
Crashes browser on the main thread.
RETURNS | DESCRIPTION |
---|---|
CrashCommand
|
The CDP command that crashes the browser.
TYPE:
|
crash_gpu_process
staticmethod
Crashes GPU process.
RETURNS | DESCRIPTION |
---|---|
CrashGpuProcessCommand
|
The CDP command that crashes the GPU process.
TYPE:
|
set_window_maximized
staticmethod
Maximize a browser window.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetWindowBoundsCommand
|
The CDP command that maximizes the window.
TYPE:
|
set_window_minimized
staticmethod
Minimize a browser window.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetWindowBoundsCommand
|
The CDP command that minimizes the window.
TYPE:
|
set_window_fullscreen
staticmethod
Set a browser window to fullscreen.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetWindowBoundsCommand
|
The CDP command that sets window to fullscreen.
TYPE:
|
set_window_normal
staticmethod
Set a browser window to normal state.
PARAMETER | DESCRIPTION |
---|---|
window_id
|
Browser window id.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SetWindowBoundsCommand
|
The CDP command that sets window to normal state.
TYPE:
|
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.