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
Bridge BrowserProfile headless mode
Magnus Müllerc6ad34b094ec
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex b2a18d4d6..65330f08a 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -80,10 +80,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- The export is lazy to avoid circular imports with `browser_use.agent.views`.- Proof: `test_agent_package_export_uses_rust_wrapper`.+15. BrowserProfile headless bridge+ - `BrowserProfile(headless=False)` now selects terminal `managed-headed`; `headless=True` selects `managed-headless`.+ - Remote CDP and explicit browser mode environment variables still override the profile preference.+ - Proof: `test_rust_agent_translates_browser_profile_headless` and `test_rust_agent_browser_mode_env_overrides_profile_headless`.+## 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` (22 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (24 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`- Managed-headless end-to-end:diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex ebf374380..8769bfbcd 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -83,6 +83,18 @@ def _extract_profile_cdp_url(browser_profile: BrowserProfile | None) -> str | Noreturn None+def _extract_headless_preference(browser_session: BrowserSession | None, browser_profile: BrowserProfile | None) -> bool | None:+ session_profile = getattr(browser_session, 'browser_profile', None)+ for profile in (session_profile, browser_profile):+ value = getattr(profile, 'headless', None)+ if isinstance(value, bool):+ return value+ value = getattr(browser_session, 'headless', None)+ if isinstance(value, bool):+ return value+ return None++def _initial_navigation_url(initial_actions: Any) -> str | None:if not isinstance(initial_actions, list):return None@@ -824,7 +836,15 @@ class Agent(Generic[AgentStructuredOutput]):value = os.environ.get('BROWSER_USE_RUST_BROWSER_MODE')if value:return value- return os.environ.get('BROWSER_USE_BROWSER_MODE', 'managed-headless')+ value = os.environ.get('BROWSER_USE_BROWSER_MODE')+ if value:+ return value+ headless = _extract_headless_preference(self.browser_session, self.browser_profile)+ if headless is False:+ return 'managed-headed'+ if headless is True:+ return 'managed-headless'+ return 'managed-headless'def _run_env(self) -> dict[str, str]:env = os.environ.copy()diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 4457cf760..ced302c69 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -134,6 +134,43 @@ def test_rust_agent_translates_browser_profile_cdp_url(monkeypatch):assert env['LLM_BROWSER_BROWSER_MODE'] == 'remote-cdp'+def test_rust_agent_translates_browser_profile_headless(monkeypatch):+ from browser_use.rust import Agent++ class HeadedProfile:+ headless = False++ class HeadlessProfile:+ headless = True++ 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)++ headed = Agent(task='report title', browser_profile=HeadedProfile())+ headless = Agent(task='report title', browser_profile=HeadlessProfile())++ assert 'browser_mode="managed-headed"' in headed._run_argv(max_steps=4)+ assert headed._run_env()['LLM_BROWSER_BROWSER_MODE'] == 'managed-headed'+ assert 'browser_mode="managed-headless"' in headless._run_argv(max_steps=4)+ assert headless._run_env()['LLM_BROWSER_BROWSER_MODE'] == 'managed-headless'+++def test_rust_agent_browser_mode_env_overrides_profile_headless(monkeypatch):+ from browser_use.rust import Agent++ class HeadedProfile:+ headless = False++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')+ monkeypatch.setenv('BROWSER_USE_BROWSER_MODE', 'cloud')++ agent = Agent(task='report title', browser_profile=HeadedProfile())++ assert 'browser_mode="cloud"' in agent._run_argv(max_steps=4)+ assert agent._run_env()['LLM_BROWSER_BROWSER_MODE'] == 'cloud'++def test_rust_agent_mirrors_direct_url_startup():from browser_use.rust import Agent