Skip to content

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

Bridge BrowserProfile profile directory

Magnus Müllerf4866668f63b
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 0af46eeaf..0ea4579a9 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -155,10 +155,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- This preserves Browser Use's headed-browser devtools launch option through the Rust managed browser path.
- Proof: `test_rust_agent_translates_browser_profile_devtools`.
+30. BrowserProfile profile directory bridge
+ - `BrowserProfile.profile_directory` is serialized into `--profile-directory=...` for terminal managed Chromium runs.
+ - This works with the managed `user_data_dir` bridge so callers can target a named Chrome profile inside the persistent profile root.
+ - Proof: `test_rust_agent_translates_browser_profile_profile_directory`.
+
## 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` (39 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (40 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`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index c3eed119e..7fe31676b 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -183,6 +183,9 @@ def _managed_browser_launch_args(browser_session: BrowserSession | None, browser
user_agent = getattr(profile, 'user_agent', None)
if isinstance(user_agent, str) and user_agent:
_append_unique(args, seen, f'--user-agent={user_agent}')
+ profile_directory = getattr(profile, 'profile_directory', None)
+ if isinstance(profile_directory, str) and profile_directory:
+ _append_unique(args, seen, f'--profile-directory={profile_directory}')
return args
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index fda453f77..cf5b98b97 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -329,6 +329,23 @@ def test_rust_agent_translates_browser_profile_devtools(monkeypatch):
assert '--auto-open-devtools-for-tabs' in launch_args
+def test_rust_agent_translates_browser_profile_profile_directory(monkeypatch):
+ from browser_use.rust import Agent
+
+ class BrowserProfile:
+ headless = False
+ profile_directory = 'Profile 7'
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+ monkeypatch.delenv('BROWSER_USE_RUST_BROWSER_MODE', raising=False)
+ monkeypatch.delenv('BROWSER_USE_BROWSER_MODE', raising=False)
+
+ agent = Agent(task='report title', browser_profile=BrowserProfile())
+ launch_args = json.loads(agent._run_env()['BU_MANAGED_BROWSER_ARGS'])
+
+ assert '--profile-directory=Profile 7' in launch_args
+
+
def test_rust_agent_translates_browser_profile_user_data_dir(monkeypatch, tmp_path):
from browser_use.rust import Agent