Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
switch to using subheadings for args
Nick Sweeting29ce2c98f348
diff --git a/docs/customize/browser-settings.mdx b/docs/customize/browser-settings.mdxindex d101b39a3..77aa1482d 100644--- a/docs/customize/browser-settings.mdx+++ b/docs/customize/browser-settings.mdx@@ -10,6 +10,7 @@ Browser Use uses [playwright](https://playwright.dev/python/docs/api/class-browsfrom browser_use import BrowserProfile, BrowserSession````+- `BrowserSession(**params)` is Browser Use's object that tracks a connection to a running browser. It holds:- the `playwright`, `browser`, `browser_context`, and `page` objects and tracks which tabs the agent/human are focused on- the helper methods to launch and connect to remote and local browsers@@ -53,6 +54,7 @@ agent = Agent()```+`BrowserProfile` is a static, flat collection of all the config parameters used by a `BrowserSession`.You can optionally use it to pass around and store a collection of config for a `BrowserSession`.@@ -70,6 +72,8 @@ browser_session = BrowserSession(browser_profile=browser_profile,headless=False, # <- extra kwargs passed to session will override values from profile)+```+## `BrowserSession` Parameters@@ -81,14 +85,29 @@ e.g. `allowed_domains`, `keep_alive`, `highlight_elements`, and more.### Remote Browser Connection Parameters-- **wss_url** (str | None, default: `None`)- WSS URL of the node.js playwright browser server to connect to+#### `wss_url`-- **cdp_url** (str | None, default: `None`)- CDP URL of the browser to connect to (e.g., http://localhost:9222)+```python+wss_url: str | None = None+```++WSS URL of the node.js playwright browser server to connect to++#### `cdp_url`++```python+cdp_url: str | None = None+```-- **browser_pid** (int | None, default: `None`)- PID of a running chromium-based browser process to connect to on localhost+CDP URL of the browser to connect to (e.g., http://localhost:9222)++#### `browser_pid`++```python+browser_pid: int | None = None+```++PID of a running chromium-based browser process to connect to on localhost<Note>For web scraping tasks on sites that restrict automated access, we recommend@@ -98,91 +117,206 @@ e.g. `allowed_domains`, `keep_alive`, `highlight_elements`, and more.### Runtime State / Parameters-- **browser_profile** (BrowserProfile, default: `BrowserProfile()`)- BrowserProfile instance containing config to use for the BrowserSession+#### `browser_profile`++```python+browser_profile: BrowserProfile = BrowserProfile()+```++BrowserProfile instance containing config to use for the BrowserSession++#### `playwright`-- **playwright** (Playwright | None, default: `None`)- Optional playwright or patchright API client object to use- result of (await async_playwright().start()) or (await async_patchright().start())+```python+playwright: Playwright | None = None+```++Optional playwright or patchright API client object to use+result of (await async_playwright().start()) or (await async_patchright().start())-- **browser** (Browser | None, default: `None`)- Playwright Browser object to use (optional)+#### `browser`++```python+browser: Browser | None = None+```++Playwright Browser object to use (optional)++#### `browser_context`++```python+browser_context: BrowserContext | None = None+```++Playwright BrowserContext object to use (optional)++#### `initialized`++```python+initialized: bool = False+```++Mark BrowserSession as already initialized, skips launch/connection (not recommended)++#### `page` *aka* `agent_current_page`++```python+page: Page | None = None+```-- **browser_context** (BrowserContext | None, default: `None`)- Playwright BrowserContext object to use (optional)+Foreground Page that the agent is focused on, can also be passed as `page=...` as a shortcut.-- **initialized** (bool, default: `False`)- Mark BrowserSession as already initialized, skips launch/connection (not recommended)+#### `human_current_page`-- **page** *aka* **agent_current_page** (Page | None, default: `None`)- Foreground Page that the agent is focused on, can also be passed as `page=...` as a shortcut.+```python+human_current_page: Page | None = None+```-- **human_current_page** (Page | None, default: `None`)- Foreground Page that the human is focused on+Foreground Page that the human is focused on## Browser-Use ParametersThese parameters control browser-use specific features, and are outside the standard playwright parameter set.-- **keep_alive** (bool | None, default: `None`)- Keeps the browser alive after the agent has finished running. Useful for running multiple tasks with the same browser instance.+#### `keep_alive`++```python+keep_alive: bool | None = None+```++Keeps the browser alive after the agent has finished running. Useful for running multiple tasks with the same browser instance.-- **allowed_domains** (list[str] | None, default: `None`)- List of allowed domains for navigation. If None, all domains are allowed.- Example: `['google.com', '*.wikipedia.org']` - Here the agent will only be able to access `google.com` exactly and `wikipedia.org` + `*.wikipedia.org`.+#### `allowed_domains`++```python+allowed_domains: list[str] | None = None+```++List of allowed domains for navigation. If None, all domains are allowed.+Example: `['google.com', '*.wikipedia.org']` - Here the agent will only be able to access `google.com` exactly and `wikipedia.org` + `*.wikipedia.org`.- Glob patterns are supported:- - `['example.com']` ✅ will match only `https://example.com/*` exactly, subdomains will not be allowed.- It's always the most secure to list all the domains you want to give the access to explicitly w/ schemes e.g.- `['*://google.com', 'http*://www.google.com', 'https://myaccount.google.com', 'https://mail.google.com', 'https://docs.google.com']`- - `['*.example.com']` ⚠️ **CAUTION** this will match `https://example.com` and *all* its subdomains.- Make sure *all* the subdomains are safe for the agent! `abc.example.com`, `def.example.com`, ..., `useruploads.example.com`, `admin.example.com`+Glob patterns are supported:+- `['example.com']` ✅ will match only `https://example.com/*` exactly, subdomains will not be allowed.+ It's always the most secure to list all the domains you want to give the access to explicitly w/ schemes e.g.+ `['*://google.com', 'http*://www.google.com', 'https://myaccount.google.com', 'https://mail.google.com', 'https://docs.google.com']`+- `['*.example.com']` ⚠️ **CAUTION** this will match `https://example.com` and *all* its subdomains.+ Make sure *all* the subdomains are safe for the agent! `abc.example.com`, `def.example.com`, ..., `useruploads.example.com`, `admin.example.com`++#### `disable_security`++```python+disable_security: bool = False+```++Completely disables all basic browser security features. Allows interacting across cross-site iFrames boundaries, but very INSECURE, don't visit untrusted URLs or use cookies.++#### `deterministic_rendering`++```python+deterministic_rendering: bool = False+```++Enable deterministic rendering flags for consistent screenshots.++#### `highlight_elements`-- **disable_security** (bool, default: `False`)- Completely disables all basic browser security features. Allows interacting across cross-site iFrames boundaries, but very INSECURE, don't visit untrusted URLs or use cookies.+```python+highlight_elements: bool = True+```-- **deterministic_rendering** (bool, default: `False`)- Enable deterministic rendering flags for consistent screenshots.+Highlight interactive elements on the screen with colorful bounding boxes.-- **highlight_elements** (bool, default: `True`)- Highlight interactive elements on the screen with colorful bounding boxes.+#### `viewport_expansion`-- **viewport_expansion** (int, default: `500`)- Viewport expansion in pixels. With this you can control how much of the page is included in the context of the LLM:- - `-1`: All elements from the entire page will be included, regardless of visibility (highest token usage but most complete).- - `0`: Only elements which are currently visible in the viewport will be included.- - `500` (default): Elements in the viewport plus an additional 500 pixels in each direction will be included, providing a balance between context and token usage.+```python+viewport_expansion: int = 500+```-- **include_dynamic_attributes** (bool, default: `True`)- Include dynamic attributes in selectors for better element targeting.+Viewport expansion in pixels. With this you can control how much of the page is included in the context of the LLM:+- `-1`: All elements from the entire page will be included, regardless of visibility (highest token usage but most complete).+- `0`: Only elements which are currently visible in the viewport will be included.+- `500` (default): Elements in the viewport plus an additional 500 pixels in each direction will be included, providing a balance between context and token usage.-- **minimum_wait_page_load_time** (float, default: `0.25`)- Minimum time to wait before capturing page state for LLM input.+#### `include_dynamic_attributes`-- **wait_for_network_idle_page_load_time** (float, default: `0.5`)- Time to wait for network activity to cease. Increase to 3-5s for slower websites. This tracks essential content loading, not dynamic elements like videos.+```python+include_dynamic_attributes: bool = True+```-- **maximum_wait_page_load_time** (float, default: `5.0`)- Maximum time to wait for page load before proceeding.+Include dynamic attributes in selectors for better element targeting.-- **wait_between_actions** (float, default: `0.5`)- Time to wait between agent actions.+#### `minimum_wait_page_load_time`-- **cookies_file** (str | None, default: `None`)- File to save cookies to.+```python+minimum_wait_page_load_time: float = 0.25+```++Minimum time to wait before capturing page state for LLM input.-- **downloads_dir** (Path | str, default: `'~/.config/browseruse/downloads'`)- Directory for downloads.+#### `wait_for_network_idle_page_load_time`-- **save_downloads_path** (str | None, default: `None`)- Directory for saving downloads (alternative to downloads_dir).+```python+wait_for_network_idle_page_load_time: float = 0.5+```++Time to wait for network activity to cease. Increase to 3-5s for slower websites. This tracks essential content loading, not dynamic elements like videos.++#### `maximum_wait_page_load_time`++```python+maximum_wait_page_load_time: float = 5.0+```++Maximum time to wait for page load before proceeding.++#### `wait_between_actions`++```python+wait_between_actions: float = 0.5+```-- **profile_directory** (str, default: `'Default'`)- Chrome profile directory name (e.g., 'Profile 1', 'Profile 2').+Time to wait between agent actions.-- **window_position** (dict | None, default: `{"width": 0, "height": 0}`)- Window position from top-left corner.+#### `cookies_file`++```python+cookies_file: str | None = None+```++File to save cookies to.++#### `downloads_dir`++```python+downloads_dir: Path | str = '~/.config/browseruse/downloads'+```++Directory for downloads.++#### `save_downloads_path`++```python+save_downloads_path: str | None = None+```++Directory for saving downloads (alternative to downloads_dir).++#### `profile_directory`++```python+profile_directory: str = 'Default'+```++Chrome profile directory name (e.g., 'Profile 1', 'Profile 2').++#### `window_position`++```python+window_position: dict | None = {"width": 0, "height": 0}+```++Window position from top-left corner.---@@ -195,50 +329,126 @@ They are defined in `browser_use/browser/profile.py`.### Launch Settings-- **headless** (bool | None, default: `None`)- Runs the browser without a visible UI. If None, auto-detects based on display availability.+#### `headless`-- **channel** (BrowserChannel, default: `'chromium'`)- Browser channel: `'chromium'`, `'chrome'`, `'chrome-beta'`, `'chrome-dev'`, `'chrome-canary'`, `'msedge'`, `'msedge-beta'`, `'msedge-dev'`, `'msedge-canary'`+```python+headless: bool | None = None+```-- **executable_path** (str | Path | None, default: `None`)- Path to browser executable for custom installations.+Runs the browser without a visible UI. If None, auto-detects based on display availability.-- **user_data_dir** (str | Path | None, default: `'~/.config/browseruse/profiles/default'`)- Directory for browser profile data. Set to None to use an ephemeral profile aka incognito mode.+#### `channel`-- **args** (list[str], default: `[]`)- Additional command-line arguments to pass to the browser.+```python+channel: BrowserChannel = 'chromium'+```-- **ignore_default_args** (list[str] | bool, default: `['--enable-automation', '--disable-extensions']`)- List of default CLI args to stop playwright from applying.+Browser channel: `'chromium'`, `'chrome'`, `'chrome-beta'`, `'chrome-dev'`, `'chrome-canary'`, `'msedge'`, `'msedge-beta'`, `'msedge-dev'`, `'msedge-canary'`-- **env** (dict[str, str], default: `{}`)- Environment variables to set when launching browser.+#### `executable_path`-- **chromium_sandbox** (bool, default: `not IN_DOCKER`)- Whether to enable Chromium sandboxing (recommended unless inside Docker).+```python+executable_path: str | Path | None = None+```-- **devtools** (bool, default: `False`)- Whether to open DevTools panel automatically (only works when headless=False).+Path to browser executable for custom installations.-- **slow_mo** (float, default: `0`)- Slow down actions by this many milliseconds.+#### `user_data_dir`-- **timeout** (float, default: `30000`)- Default timeout in milliseconds for connecting to a remote browser.+```python+user_data_dir: str | Path | None = '~/.config/browseruse/profiles/default'+```++Directory for browser profile data. Set to None to use an ephemeral profile aka incognito mode.++#### `args`++```python+args: list[str] = []+```++Additional command-line arguments to pass to the browser.++#### `ignore_default_args`++```python+ignore_default_args: list[str] | bool = ['--enable-automation', '--disable-extensions']+```++List of default CLI args to stop playwright from applying.++#### `env`++```python+env: dict[str, str] = {}+```++Environment variables to set when launching browser.++#### `chromium_sandbox`++```python+chromium_sandbox: bool = not IN_DOCKER+```++Whether to enable Chromium sandboxing (recommended unless inside Docker).++#### `devtools`++```python+devtools: bool = False+```+++Whether to open DevTools panel automatically (only works when headless=False).++#### `slow_mo`++```python+slow_mo: float = 0+```++Slow down actions by this many milliseconds.++#### `timeout`++```python+timeout: float = 30000+```++Default timeout in milliseconds for connecting to a remote browser.++#### `accept_downloads`++```python+accept_downloads: bool = True+```++Whether to automatically accept all downloads.++#### `proxy`++```python+proxy: dict | None = None+```++Proxy settings. Example: `{"server": "http://proxy.com:8080", "username": "user", "password": "pass"}`++#### `permissions`++```python+permissions: list[str] = ['clipboard-read', 'clipboard-write', 'notifications']+```-- **accept_downloads** (bool, default: `True`)- Whether to automatically accept all downloads.+Browser permissions to grant.-- **proxy** (dict | None, default: `None`)- Proxy settings. Example: `{"server": "http://proxy.com:8080", "username": "user", "password": "pass"}`+#### `storage_state`-- **permissions** (list[str], default: `['clipboard-read', 'clipboard-write', 'notifications']`)- Browser permissions to grant.+```python+storage_state: str | Path | dict | None = None+```-- **storage_state** (str | Path | dict | None, default: `None`)- Browser storage state (cookies, localStorage). Can be file path or dict.+Browser storage state (cookies, localStorage). Can be file path or dict.@@ -246,141 +456,346 @@ They are defined in `browser_use/browser/profile.py`.These control how the browser waits for CDP API calls to complete and pages to load.-- **default_timeout** (float | None, default: `None`)- Default timeout for Playwright operations in milliseconds.+#### `default_timeout`++```python+default_timeout: float | None = None+```-- **default_navigation_timeout** (float | None, default: `None`)- Default timeout for page navigation in milliseconds.+Default timeout for Playwright operations in milliseconds.++#### `default_navigation_timeout`++```python+default_navigation_timeout: float | None = None+```++Default timeout for page navigation in milliseconds.### Display and Viewport SettingsConfigure browser window size, viewport, and display properties:-- **user_agent** (str | None, default: `None`)- Specific user agent to use in this context.+#### `user_agent`++```python+user_agent: str | None = None+```++Specific user agent to use in this context.++#### `is_mobile`++```python+is_mobile: bool = False+```++Whether the meta viewport tag is taken into account and touch events are enabled.++#### `has_touch`++```python+has_touch: bool = False+```++Specifies if viewport supports touch events.++#### `geolocation`++```python+geolocation: dict | None = None+```++Geolocation coordinates. Example: `{"latitude": 59.95, "longitude": 30.31667}`++#### `locale`++```python+locale: str | None = None+```++Specify user locale, for example en-GB, de-DE, etc. Locale will affect the navigator.language value, Accept-Language request header value as well as number and date formatting rules.++#### `timezone_id`++```python+timezone_id: str | None = None+```++Timezone identifier (e.g., 'America/New_York').++#### `window_size`++```python+window_size: dict | None = None+```++Browser window size for headful mode. Example: `{"width": 1920, "height": 1080}`++#### `viewport`-- **is_mobile** (bool, default: `False`)- Whether the meta viewport tag is taken into account and touch events are enabled.+```python+viewport: dict | None = None+```-- **has_touch** (bool, default: `False`)- Specifies if viewport supports touch events.+Viewport size with `width` and `height`. Example: `{"width": 1280, "height": 720}`-- **geolocation** (dict | None, default: `None`)- Geolocation coordinates. Example: `{"latitude": 59.95, "longitude": 30.31667}`+#### `no_viewport`-- **locale** (str | None, default: `None`)- Specify user locale, for example en-GB, de-DE, etc. Locale will affect the navigator.language value, Accept-Language request header value as well as number and date formatting rules.+```python+no_viewport: bool | None = None+```++Disable fixed viewport. Content will resize with window.++#### `device_scale_factor`++```python+device_scale_factor: float | None = None+```++Device scale factor (DPI). Useful for high-resolution screenshots.++#### `screen`++```python+screen: dict | None = None+```++Screen size available to browser. Auto-detected if not specified.++#### `color_scheme`++```python+color_scheme: ColorScheme = 'light'+```-- **timezone_id** (str | None, default: `None`)- Timezone identifier (e.g., 'America/New_York').+Preferred color scheme: `'light'`, `'dark'`, `'no-preference'`-- **window_size** (dict | None, default: `None`)- Browser window size for headful mode. Example: `{"width": 1920, "height": 1080}`+#### `contrast`-- **viewport** (dict | None, default: `None`)- Viewport size with `width` and `height`. Example: `{"width": 1280, "height": 720}`+```python+contrast: Contrast = 'no-preference'+```-- **no_viewport** (bool | None, default: `None`)- Disable fixed viewport. Content will resize with window.+Contrast preference: `'no-preference'`, `'more'`, `'null'`-- **device_scale_factor** (float | None, default: `None`)- Device scale factor (DPI). Useful for high-resolution screenshots.+#### `reduced_motion`-- **screen** (dict | None, default: `None`)- Screen size available to browser. Auto-detected if not specified.+```python+reduced_motion: ReducedMotion = 'no-preference'+```-- **color_scheme** (ColorScheme, default: `'light'`)- Preferred color scheme: `'light'`, `'dark'`, `'no-preference'`+Reduced motion preference: `'reduce'`, `'no-preference'`, `'null'`-- **contrast** (Contrast, default: `'no-preference'`)- Contrast preference: `'no-preference'`, `'more'`, `'null'`+#### `forced_colors`-- **reduced_motion** (ReducedMotion, default: `'no-preference'`)- Reduced motion preference: `'reduce'`, `'no-preference'`, `'null'`+```python+forced_colors: ForcedColors = 'none'+```-- **forced_colors** (ForcedColors, default: `'none'`)- Forced colors mode: `'active'`, `'none'`, `'null'`+Forced colors mode: `'active'`, `'none'`, `'null'`### Security and Network Settings> See `allowed_domains` above too!-- **offline** (bool, default: `False`)- Emulate network being offline.+#### `offline`-- **http_credentials** (dict | None, default: `None`)- Credentials for HTTP authentication.+```python+offline: bool = False+```-- **extra_http_headers** (dict[str, str], default: `{}`)- Additional HTTP headers to be sent with every request.+Emulate network being offline.-- **ignore_https_errors** (bool, default: `False`)- Whether to ignore HTTPS errors when sending network requests.+#### `http_credentials`-- **bypass_csp** (bool, default: `False`)- Toggles bypassing Content-Security-Policy.+```python+http_credentials: dict | None = None+```-- **java_script_enabled** (bool, default: `True`)- Whether or not to enable JavaScript in the context.+Credentials for HTTP authentication.-- **service_workers** (ServiceWorkers, default: `'allow'`)- Whether to allow sites to register Service workers: `'allow'`, `'block'`+#### `extra_http_headers`-- **base_url** (str | None, default: `None`)- Base URL to be used in `page.goto()` and similar operations.+```python+extra_http_headers: dict[str, str] = {}+```++Additional HTTP headers to be sent with every request.++#### `ignore_https_errors`++```python+ignore_https_errors: bool = False+```++Whether to ignore HTTPS errors when sending network requests.-- **strict_selectors** (bool, default: `False`)- If true, selector passed to Playwright methods will throw if more than one element matches.+#### `bypass_csp`-- **client_certificates** (list[ClientCertificate], default: `[]`)- Client certificates to be used with requests.+```python+bypass_csp: bool = False+```++Toggles bypassing Content-Security-Policy.++#### `java_script_enabled`++```python+java_script_enabled: bool = True+```++Whether or not to enable JavaScript in the context.++#### `service_workers`++```python+service_workers: ServiceWorkers = 'allow'+```++Whether to allow sites to register Service workers: `'allow'`, `'block'`++#### `base_url`++```python+base_url: str | None = None+```++Base URL to be used in `page.goto()` and similar operations.++#### `strict_selectors`++```python+strict_selectors: bool = False+```++If true, selector passed to Playwright methods will throw if more than one element matches.++#### `client_certificates`++```python+client_certificates: list[ClientCertificate] = []+```++Client certificates to be used with requests.### Recording and Debugging-- **save_recording_path** (str | None, default: `None`)- Directory path for saving video recordings.+#### `save_recording_path`-- **trace_path** (str | None, default: `None`)- Directory path for saving trace files. Files are automatically named as `{trace_path}/{context_id}.zip`.+```python+save_recording_path: str | None = None+```-- **record_video_dir** (str | Path | None, default: `None`)- Directory to save video recordings.+Directory path for saving video recordings.-- **record_video_size** (dict | None, default: `None`)- Video size. Example: `{"width": 1280, "height": 720}`+#### `trace_path`-- **record_har_path** (str | Path | None, default: `None`)- Path to save HAR file with network activity.+```python+trace_path: str | None = None+```-- **record_har_content** (RecordHarContent, default: `'embed'`)- How to persist HAR content: `'omit'`, `'embed'`, `'attach'`+Directory path for saving trace files. Files are automatically named as `{trace_path}/{context_id}.zip`.-- **record_har_mode** (RecordHarMode, default: `'full'`)- HAR recording mode: `'full'`, `'minimal'`+#### `record_video_dir`-- **record_har_omit_content** (bool, default: `False`)- Whether to omit request content from the HAR.+```python+record_video_dir: str | Path | None = None+```-- **record_har_url_filter** (str | Pattern | None, default: `None`)- URL filter for HAR recording.+Directory to save video recordings.-- **downloads_path** (str | Path | None, default: `None`)- Directory to save downloads to (used by launch args).+#### `record_video_size`-- **traces_dir** (str | Path | None, default: `None`)- Directory to save HAR trace files to.+```python+record_video_size: dict | None = None+```++Video size. Example: `{"width": 1280, "height": 720}`++#### `record_har_path`++```python+record_har_path: str | Path | None = None+```++Path to save HAR file with network activity.-- **handle_sighup** (bool, default: `True`)- Whether playwright should swallow SIGHUP signals and kill the browser.+#### `record_har_content`-- **handle_sigint** (bool, default: `False`)- Whether playwright should swallow SIGINT signals and kill the browser.+```python+record_har_content: RecordHarContent = 'embed'+```-- **handle_sigterm** (bool, default: `False`)- Whether playwright should swallow SIGTERM signals and kill the browser.+How to persist HAR content: `'omit'`, `'embed'`, `'attach'`++#### `record_har_mode`++```python+record_har_mode: RecordHarMode = 'full'+```++HAR recording mode: `'full'`, `'minimal'`++#### `record_har_omit_content`++```python+record_har_omit_content: bool = False+```++Whether to omit request content from the HAR.++#### `record_har_url_filter`++```python+record_har_url_filter: str | Pattern | None = None+```++URL filter for HAR recording.++#### `downloads_path`++```python+downloads_path: str | Path | None = None+```++Directory to save downloads to (used by launch args).++#### `traces_dir`++```python+traces_dir: str | Path | None = None+```++Directory to save HAR trace files to.++#### `handle_sighup`++```python+handle_sighup: bool = True+```++Whether playwright should swallow SIGHUP signals and kill the browser.++#### `handle_sigint`++```python+handle_sigint: bool = False+```++Whether playwright should swallow SIGINT signals and kill the browser.++#### `handle_sigterm`++```python+handle_sigterm: bool = False+```++Whether playwright should swallow SIGTERM signals and kill the browser.---@@ -421,6 +836,7 @@ async def run_search():)```+## Summary- **BrowserSession** parameters (defined in `browser_use/browser/session.py`) handle connection and runtime state