Browser#
The Browser domain defines methods and events for browser managing.
Types#
Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.
- class WindowState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
The state of the browser window.
- NORMAL = 'normal'#
- MINIMIZED = 'minimized'#
- MAXIMIZED = 'maximized'#
- FULLSCREEN = 'fullscreen'#
- class Bounds(left=None, top=None, width=None, height=None, window_state=None)[source]#
Browser window bounds information
-
window_state:
Optional[WindowState] = None# The window state. Default to normal.
-
window_state:
- class PermissionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
- AR = 'ar'#
- AUDIO_CAPTURE = 'audioCapture'#
- AUTOMATIC_FULLSCREEN = 'automaticFullscreen'#
- BACKGROUND_FETCH = 'backgroundFetch'#
- BACKGROUND_SYNC = 'backgroundSync'#
- CAMERA_PAN_TILT_ZOOM = 'cameraPanTiltZoom'#
- CAPTURED_SURFACE_CONTROL = 'capturedSurfaceControl'#
- CLIPBOARD_READ_WRITE = 'clipboardReadWrite'#
- CLIPBOARD_SANITIZED_WRITE = 'clipboardSanitizedWrite'#
- DISPLAY_CAPTURE = 'displayCapture'#
- DURABLE_STORAGE = 'durableStorage'#
- GEOLOCATION = 'geolocation'#
- HAND_TRACKING = 'handTracking'#
- IDLE_DETECTION = 'idleDetection'#
- KEYBOARD_LOCK = 'keyboardLock'#
- LOCAL_FONTS = 'localFonts'#
- LOCAL_NETWORK_ACCESS = 'localNetworkAccess'#
- MIDI = 'midi'#
- MIDI_SYSEX = 'midiSysex'#
- NFC = 'nfc'#
- NOTIFICATIONS = 'notifications'#
- PAYMENT_HANDLER = 'paymentHandler'#
- PERIODIC_BACKGROUND_SYNC = 'periodicBackgroundSync'#
- POINTER_LOCK = 'pointerLock'#
- PROTECTED_MEDIA_IDENTIFIER = 'protectedMediaIdentifier'#
- SENSORS = 'sensors'#
- SMART_CARD = 'smartCard'#
- SPEAKER_SELECTION = 'speakerSelection'#
- STORAGE_ACCESS = 'storageAccess'#
- TOP_LEVEL_STORAGE_ACCESS = 'topLevelStorageAccess'#
- VIDEO_CAPTURE = 'videoCapture'#
- VR = 'vr'#
- WAKE_LOCK_SCREEN = 'wakeLockScreen'#
- WAKE_LOCK_SYSTEM = 'wakeLockSystem'#
- WEB_APP_INSTALLATION = 'webAppInstallation'#
- WEB_PRINTING = 'webPrinting'#
- WINDOW_MANAGEMENT = 'windowManagement'#
- class PermissionSetting(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
- GRANTED = 'granted'#
- DENIED = 'denied'#
- PROMPT = 'prompt'#
- class PermissionDescriptor(name, sysex=None, user_visible_only=None, allow_without_sanitization=None, allow_without_gesture=None, pan_tilt_zoom=None)[source]#
Definition of PermissionDescriptor defined in the Permissions API: https://w3c.github.io/permissions/#dom-permissiondescriptor.
-
name:
str# Name of permission. See https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl for valid permission names.
-
user_visible_only:
Optional[bool] = None# For “push” permission, may specify userVisibleOnly. Note that userVisibleOnly = true is the only currently supported type.
-
allow_without_sanitization:
Optional[bool] = None# For “clipboard” permission, may specify allowWithoutSanitization.
-
name:
- class BrowserCommandId(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Browser command ids used by executeBrowserCommand.
- OPEN_TAB_SEARCH = 'openTabSearch'#
- CLOSE_TAB_SEARCH = 'closeTabSearch'#
- OPEN_GLIC = 'openGlic'#
Commands#
Each command is a generator function. The return
type Generator[x, y, z] indicates that the generator
yields arguments of type x, it must be resumed with
an argument of type y, and it returns type z. In
this library, types x and y are the same for all
commands, and z is the return type you should pay attention
to. For more information, see
Getting Started: Commands.
- add_privacy_sandbox_coordinator_key_config(api, coordinator_origin, key_config, browser_context_id=None)[source]#
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.
- add_privacy_sandbox_enrollment_override(url)[source]#
Allows a site to use privacy sandbox features that require enrollment without the site actually being enrolled. Only supported on page targets.
- cancel_download(guid, browser_context_id=None)[source]#
Cancel a download if in progress
EXPERIMENTAL
- execute_browser_command(command_id)[source]#
Invoke custom browser commands used by telemetry.
EXPERIMENTAL
- get_browser_command_line()[source]#
Returns the command line switches for the browser process if, and only if –enable-automation is on the commandline.
EXPERIMENTAL
- get_histograms(query=None, delta=None)[source]#
Get Chrome histograms.
EXPERIMENTAL
- Parameters:
- Return type:
- Returns:
Histograms.
- get_window_for_target(target_id=None)[source]#
Get the browser window that contains the devtools target.
EXPERIMENTAL
- Parameters:
target_id (
Optional[TargetID]) – (Optional) Devtools agent host id. If called as a part of the session, associated targetId is used.- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[WindowID,Bounds]]- Returns:
A tuple with the following items:
windowId - Browser window id.
bounds - Bounds information of the window. When window state is ‘minimized’, the restored window position and size are returned.
- grant_permissions(permissions, origin=None, browser_context_id=None)[source]#
Grant specific permissions to the given origin and reject all others.
EXPERIMENTAL
- Parameters:
permissions (
List[PermissionType]) –origin (
Optional[str]) – (Optional) Origin the permission applies to, all origins if not specified.browser_context_id (
Optional[BrowserContextID]) – (Optional) BrowserContext to override permissions. When omitted, default browser context is used.
- Return type:
- reset_permissions(browser_context_id=None)[source]#
Reset all permission management for all origins.
- set_contents_size(window_id, width=None, height=None)[source]#
Set size of the browser contents resizing browser window as necessary.
EXPERIMENTAL
- Parameters:
window_id (
WindowID) – Browser window id.width (
Optional[int]) – (Optional) The window contents width in DIP. Assumes current width if omitted. Must be specified if ‘height’ is omitted.height (
Optional[int]) – (Optional) The window contents height in DIP. Assumes current height if omitted. Must be specified if ‘width’ is omitted.
- Return type:
- set_dock_tile(badge_label=None, image=None)[source]#
Set dock tile details, platform-specific.
EXPERIMENTAL
- set_download_behavior(behavior, browser_context_id=None, download_path=None, events_enabled=None)[source]#
Set the behavior when downloading a file.
EXPERIMENTAL
- Parameters:
behavior (
str) – Whether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny).allowAndNameallows download and names files according to their download guids.browser_context_id (
Optional[BrowserContextID]) – (Optional) BrowserContext to set download behavior. When omitted, default browser context is used.download_path (
Optional[str]) – (Optional) The default path to save downloaded files to. This is required if behavior is set to ‘allow’ or ‘allowAndName’.events_enabled (
Optional[bool]) – (Optional) Whether to emit download events (defaults to false).
- Return type:
- set_permission(permission, setting, origin=None, embedding_origin=None, browser_context_id=None)[source]#
Set permission settings for given requesting and embedding origins.
EXPERIMENTAL
- Parameters:
permission (
PermissionDescriptor) – Descriptor of permission to override.setting (
PermissionSetting) – Setting of the permission.origin (
Optional[str]) – (Optional) Requesting origin the permission applies to, all origins if not specified.embedding_origin (
Optional[str]) – (Optional) Embedding origin the permission applies to. It is ignored unless the requesting origin is present and valid. If the requesting origin is provided but the embedding origin isn’t, the requesting origin is used as the embedding origin.browser_context_id (
Optional[BrowserContextID]) – (Optional) Context to override. When omitted, default browser context is used.
- Return type:
Events#
Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.
- class DownloadWillBegin(frame_id, guid, url, suggested_filename)[source]#
EXPERIMENTAL
Fired when page is about to start a download.