Browser class (alias for BrowserSession) manages browser lifecycle, configuration, and provides methods for direct browser control.
Browser is the recommended name. BrowserSession is the internal class name but both refer to the same class.Constructor
Core Settings
str
Unique identifier for this browser session. Auto-generated if not provided.
str | None
CDP URL for connecting to existing browser instance (e.g.,
"http://localhost:9222").BrowserProfile | None
Browser profile configuration. If not provided, direct parameters are used to create one.
bool
default:"True"
Whether this is a local browser instance. Set to
False for remote browsers. Auto-detected from executable_path or cdp_url.Display & Appearance
bool | None
Run browser without UI. Auto-detects based on display availability.
True = no UI, False = show window, None = auto-detect.dict | ViewportSize
Browser window size for headful mode. Format:
{'width': 1920, 'height': 1080}dict
default:"{'width': 0, 'height': 0}"
Window position from top-left corner in pixels.
dict | ViewportSize
Content area size. Format:
{'width': 1280, 'height': 720}bool | None
Disable viewport emulation, content fits to window size.
float
Device scale factor (DPI). Set to
2.0 or 3.0 for high-resolution screenshots.Browser Behavior
bool | None
Keep browser running after agent completes.
list[str]
Restrict navigation to specific domains. Domain patterns:
'example.com'- Matches onlyhttps://example.com/*'*.example.com'- Matchesexample.comand all subdomains'http*://example.com'- Matches both HTTP and HTTPS'chrome-extension://*'- Matches Chrome extensions
list[str]
Block navigation to specific domains. Uses same pattern format as
allowed_domains. When both are set, allowed_domains takes precedence.bool
default:"True"
Load automation extensions (uBlock Origin, cookie handlers, ClearURLs).
bool
default:"False"
Enable cross-origin iframe support (may increase complexity).
User Data & Profiles
str | Path | None
Directory for browser profile data. Use
None for incognito mode. Auto-generated temp directory by default.str
default:"'Default'"
Chrome profile subdirectory name (e.g.,
'Profile 1', 'Work Profile').str | Path | dict[str, Any] | None
Browser storage state (cookies, localStorage). Can be file path or dict object.
Network & Security
ProxySettings
Proxy configuration. Format:
ProxySettings(server='http://host:8080', bypass='localhost', username='user', password='pass')list[str]
default:"['clipboardReadWrite', 'notifications']"
Browser permissions to grant. Examples:
['camera', 'microphone', 'geolocation']dict[str, str]
Additional HTTP headers for connect requests (remote browsers only).
Browser Launch
str | Path
Path to browser executable. Platform examples:
- macOS:
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' - Windows:
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' - Linux:
'/usr/bin/google-chrome'
str
Browser channel:
'chromium', 'chrome', 'chrome-beta', 'msedge', etc.list[str]
Additional command-line arguments. Format:
['--disable-gpu', '--custom-flag=value']dict[str, str | float | bool]
Environment variables for browser process. Format:
{'DISPLAY': ':0', 'LANG': 'en_US.UTF-8'}bool
default:"True"
Enable Chromium sandboxing for security. Defaults to
False in Docker.bool
default:"False"
Open DevTools panel automatically (requires
headless=False).list[str] | Literal[True]
List of default args to disable, or
True to disable all. Format: ['--enable-automation', '--disable-extensions']Timing & Performance
float
default:"0.25"
Minimum time to wait before capturing page state (seconds).
float
default:"0.5"
Time to wait for network activity to cease (seconds).
float
default:"0.5"
Time to wait between agent actions (seconds).
AI Integration
bool
default:"True"
Highlight interactive elements for AI vision.
bool
default:"True"
Alternative name for
highlight_elements.bool
default:"True"
Optimize DOM tree by removing elements hidden behind others. Slightly experimental.
bool
Filter highlight IDs from DOM output.
Downloads & Files
bool
default:"True"
Automatically accept all downloads.
str | Path
Directory for downloaded files. Format:
'./downloads' or Path object.bool
default:"True"
Automatically download PDFs instead of viewing in browser.
Device Emulation
str
Custom user agent string. Example:
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)'dict
Screen size information. Same format as
window_size.Recording & Debugging
str | Path
Directory to save video recordings as
.mp4 files.dict | ViewportSize
Frame size (width, height) of video recording.
int
default:"30"
Framerate for video recording.
str | Path
Path to save network trace files as
.har format.str | Path
Directory to save complete trace files for debugging.
str
default:"'embed'"
HAR content mode:
'omit', 'embed', or 'attach'.str
default:"'full'"
HAR recording mode:
'full' or 'minimal'.Cloud Browser
bool
Use Browser Use cloud browser service. Requires
BROWSER_USE_API_KEY environment variable.bool
Deprecated: Use
use_cloud instead. Alias for backward compatibility.CloudBrowserParams
Cloud browser configuration parameters.
UUID | str
UUID of cloud browser profile.
ProxyCountryCode
Country code for cloud proxy:
'us', 'uk', 'fr', 'it', 'jp', 'au', 'de', 'fi', 'ca', 'in'int
Session timeout in minutes (free: max 15 min, paid: max 240 min).
DOM Configuration
int
Maximum number of iframes to process.
int
Maximum iframe nesting depth.
list[str]
Domains to whitelist for cookie handling.
Advanced Options
bool
default:"False"
⚠️ NOT RECOMMENDED - Disables all browser security features.
bool
default:"False"
⚠️ NOT RECOMMENDED - Forces consistent rendering but reduces performance.
bool
Enable demo mode with browser overlay UI.
Methods
start()
Start the browser session.stop()
Stop the browser session without killing the process.kill()
Force-stop the browser and clean up all resources.reset()
Clear all cached CDP sessions.get_browser_state_summary()
Get current browser state including DOM and screenshot.bool
default:"True"
Include screenshot in the state.
bool
default:"False"
Use cached state if available.
bool
default:"False"
Include recent browser events.
BrowserStateSummary
Complete browser state with URL, DOM, tabs, and optional screenshot.
get_current_page()
Get the current page as an Actor Page object.Page | None
Current page actor, or
None if no page is open.get_pages()
Get all open pages.list[Page]
List of all open page actors.
new_page()
Create a new page (tab).str | None
Initial URL to navigate to. Defaults to
'about:blank'.Page
New page actor.
close_page()
Close a page by Page object or target ID.Page | str
required
Page object or target ID string.
cookies()
Get all browser cookies.list[Cookie]
List of browser cookies.
clear_cookies()
Clear all browser cookies.export_storage_state()
Export browser cookies and storage to storage_state format.str | Path | None
Optional path to save storage_state.json.
dict[str, Any]
Storage state dict with cookies in Playwright format.
set_extra_headers()
Set extra HTTP headers for all requests.dict[str, str]
required
Dictionary of header name -> value pairs.
str | None
Target to set headers on. Defaults to current focus.
Properties
cdp_client
CDPClient
CDP client for direct CDP communication.
browser_profile
BrowserProfile
Browser profile configuration.
agent_focus_target_id
str | None
Target ID of the currently focused tab.
session_manager
SessionManager
Session manager that owns all targets and sessions.
downloaded_files
list[str]
List of files downloaded during this session.