Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Bridge BrowserProfile downloads

Magnus Müllercfed0e5a9385
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index e38c4d15f..13f1ff23d 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -165,15 +165,22 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- The terminal core parses that JSON permission list and calls CDP `Browser.grantPermissions` after connecting to managed, local, remote-CDP, or cloud browsers.
- Proof: `test_rust_agent_translates_browser_profile_permissions` and `browser_permissions_env_parses_json_array`.
+32. BrowserProfile downloads bridge
+ - `BrowserProfile.accept_downloads` is serialized into `BU_BROWSER_ACCEPT_DOWNLOADS`.
+ - `BrowserProfile.downloads_path` is serialized into `BU_BROWSER_DOWNLOADS_PATH`.
+ - The terminal core applies those settings with CDP `Browser.setDownloadBehavior` after connecting to managed, local, remote-CDP, or cloud browsers.
+ - Proof: `test_rust_agent_translates_browser_profile_downloads`, `browser_download_behavior_env_allows_downloads_path`, and `browser_download_behavior_env_denies_disabled_downloads`.
+
## Current Verification
- `python3 -m py_compile browser_use/rust/service.py browser_use/rust/__init__.py browser_use/__init__.py tests/ci/test_rust_agent.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`
-- `uv run pytest -q tests/ci/test_rust_agent.py` (41 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (42 tests)
- `cargo build -q -p browser-use-cli`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent bare_browser_connect_resolves_to_selected_managed_mode_with_launch_args -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent bare_browser_connect_resolves_to_selected_managed_mode_with_profile_dir -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_permissions_env_parses_json_array -- --nocapture`
+- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_download_behavior_env_ -- --nocapture`
- Managed-headless end-to-end:
- `BROWSER_USE_TERMINAL_BINARY=/home/exedev/Developer/terminal/target/debug/browser-use-terminal BROWSER_USE_RUST_BROWSER_MODE=managed-headless BU_TASK='Open https://example.com and report the page title only.' BU_MAX_STEPS=12 timeout 300 uv run python examples/rust_agent/basic.py`
- Output: `Example Domain`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 919f90849..645bcc0a0 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -247,6 +247,24 @@ def _extract_profile_permissions(browser_session: BrowserSession | None, browser
return values
+def _extract_browser_downloads(
+ browser_session: BrowserSession | None, browser_profile: BrowserProfile | None
+) -> tuple[bool | None, str | None]:
+ accept_downloads: bool | None = None
+ downloads_path: str | None = None
+ session_profile = getattr(browser_session, 'browser_profile', None)
+ for profile in (session_profile, browser_profile, browser_session):
+ if accept_downloads is None:
+ value = getattr(profile, 'accept_downloads', None)
+ if isinstance(value, bool):
+ accept_downloads = value
+ if downloads_path is None:
+ value = getattr(profile, 'downloads_path', None)
+ if isinstance(value, (str, os.PathLike)) and str(value):
+ downloads_path = str(Path(value).expanduser())
+ return accept_downloads, downloads_path
+
+
def _is_managed_browser_mode(mode: str) -> bool:
normalized = mode.strip().lower().replace('_', '-').replace(' ', '-')
return normalized in {'managed-headless', 'headless', 'headless-chromium', 'managed-headed', 'managed', 'headed'}
@@ -778,6 +796,9 @@ class Agent(Generic[AgentStructuredOutput]):
self.managed_browser_executable_path = _managed_browser_executable_path(self.browser_session, self.browser_profile)
self.managed_browser_env = _managed_browser_env(self.browser_session, self.browser_profile)
self.browser_permissions = _extract_profile_permissions(self.browser_session, self.browser_profile)
+ self.browser_accept_downloads, self.browser_downloads_path = _extract_browser_downloads(
+ self.browser_session, self.browser_profile
+ )
self.sensitive_data_context = _sensitive_data_context(sensitive_data)
self.display_files_in_done_text = display_files_in_done_text
self.file_system_path = file_system_path
@@ -1225,6 +1246,10 @@ class Agent(Generic[AgentStructuredOutput]):
env['BU_CDP_URL'] = cdp_url
if self.browser_permissions:
env['BU_BROWSER_PERMISSIONS'] = json.dumps(self.browser_permissions)
+ if self.browser_accept_downloads is not None:
+ env['BU_BROWSER_ACCEPT_DOWNLOADS'] = 'true' if self.browser_accept_downloads else 'false'
+ if self.browser_downloads_path:
+ env['BU_BROWSER_DOWNLOADS_PATH'] = self.browser_downloads_path
if self.managed_browser_env and _is_managed_browser_mode(browser_mode):
env.update(self.managed_browser_env)
if self.managed_browser_args and _is_managed_browser_mode(browser_mode):
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 0e5e38308..61fa84058 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -363,6 +363,28 @@ def test_rust_agent_translates_browser_profile_permissions(monkeypatch):
assert json.loads(env['BU_BROWSER_PERMISSIONS']) == ['clipboardReadWrite', 'notifications']
+def test_rust_agent_translates_browser_profile_downloads(monkeypatch, tmp_path):
+ from browser_use.rust import Agent
+
+ profile_downloads_path = tmp_path / 'downloads'
+
+ class BrowserProfile:
+ accept_downloads = True
+ downloads_path = profile_downloads_path
+ cdp_url = 'http://127.0.0.1:9222'
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+
+ agent = Agent(task='report title', browser_profile=BrowserProfile())
+ env = agent._run_env()
+
+ assert env['LLM_BROWSER_BROWSER_MODE'] == 'remote-cdp'
+ assert agent.browser_accept_downloads is True
+ assert agent.browser_downloads_path == str(profile_downloads_path)
+ assert env['BU_BROWSER_ACCEPT_DOWNLOADS'] == 'true'
+ assert env['BU_BROWSER_DOWNLOADS_PATH'] == str(profile_downloads_path)
+
+
def test_rust_agent_translates_browser_profile_user_data_dir(monkeypatch, tmp_path):
from browser_use.rust import Agent