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
Let Rust own initial CDP navigation
Magnus Müller36cccf120169
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 42ef74986..1819e713b 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -43,15 +43,11 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly importempty browser tool results while a script is still active and keeps thenext model turn on the intended observe/cancel path instead of repeatedlynavigating or reconnecting.- - Simple initial navigation actions on existing CDP-backed browser sessions- now execute once before the Rust SDK run starts. Evals that provision a- Browser Use Cloud browser therefore hand Rust a browser already focused on- the task's start URL instead of relying only on a prompt hint from- `about:blank`.- - Completed initial CDP navigations are passed to the Rust SDK as current-page- context and the stale `First navigate to ...` prefix is removed from the- SDK task. This keeps Rust from repeating a navigation that Python already- confirmed against the Browser Use Cloud browser.+ - Simple initial navigation actions on CDP-backed Rust runs are now left for+ the Rust SDK by default, so the first navigation is a model-visible+ `browser_script` action with terminal page-state output instead of a hidden+ Python-side BrowserSession preload. The old direct CDP preload remains+ available behind `BROWSER_USE_RUST_DIRECT_INITIAL_NAVIGATION=1`.- Structured `browser_script` lifecycle events now preserve outputs, summaries,images, and browser state through terminal event persistence and Pythonhistory reconstruction. This prevents the first post-navigation page probe@@ -95,6 +91,7 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- browser-use `uv run pytest tests/ci/test_rust_agent.py -k 'sdk_client_reads_large_json_rpc_lines or sdk_and_reuses_session or translates_browser_use_args_to_terminal'`- browser-use `uv run pytest tests/ci/test_rust_agent.py -k 'sdk_client_queues_agent_notifications_before_response or sdk_client_reads_large_json_rpc_lines or sdk_and_reuses_session or translates_browser_use_args_to_terminal'`- browser-use `uv run pytest tests/ci/test_rust_agent.py -k 'rust_sdk_client_reads_large_json_rpc_lines or rust_sdk_client_queues_agent_notifications_before_response' -q`+- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_sdk_client_reads_large_json_rpc_lines tests/ci/test_rust_agent.py::test_rust_agent_run_leaves_initial_navigation_for_sdk_by_default tests/ci/test_rust_agent.py::test_rust_agent_initial_actions_can_pre_navigate_existing_cdp_session tests/ci/test_rust_agent.py::test_rust_agent_translates_browser_use_args_to_terminal -q`- evaluations-internal `uv run python -m py_compile eval/service.py`- evaluations-internal `PYTHONPATH="$PWD" uv run pytest tests/test_service_cli.py::test_progress_updates_tolerate_transient_failures_by_default tests/test_service_cli.py::test_run_stage_with_progress_heartbeat_refreshes_active_stage -q`- browser-use process-backed smoke withdiff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 4de9993fc..72b42f42e 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1067,6 +1067,11 @@ def _string_env_value(value: Any) -> str | None:return text or None+def _direct_initial_navigation_enabled() -> bool:+ raw = os.getenv('BROWSER_USE_RUST_DIRECT_INITIAL_NAVIGATION', '')+ return raw.strip().lower() in {'1', 'true', 'yes', 'on'}++def _llm_provider_name(llm: Any) -> str | None:provider = getattr(llm, 'provider', None)if callable(provider):@@ -5677,6 +5682,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):async def _execute_direct_initial_navigation_actions(self) -> list[ActionResult] | None:"""Pre-navigate existing CDP-backed browser sessions before the Rust agent starts."""self._completed_initial_navigation_urls = []+ if not _direct_initial_navigation_enabled():+ return Noneif self.browser_session is None:return Noneif not (_extract_cdp_url(self.browser_session) or _extract_profile_cdp_url(self.browser_profile)):diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 90b7e3bc3..f2ff3f1dc 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -7054,7 +7054,7 @@ async def test_rust_agent_run_executes_initial_actions_before_sdk():assert history.final_result() == 'done'-async def test_rust_agent_run_hands_off_completed_initial_navigation_as_context():+async def test_rust_agent_run_leaves_initial_navigation_for_sdk_by_default():from types import SimpleNamespacefrom browser_use.rust import Agent@@ -7096,10 +7096,10 @@ async def test_rust_agent_run_hands_off_completed_initial_navigation_as_context(history = await agent.run(max_steps=3)assert history.final_result() == 'done'- assert browser_session.calls == [('https://example.com', False)]- assert agent._completed_initial_navigation_urls == ['https://example.com']- assert "already open at 'https://example.com'" in seen[0]- assert not seen[0].startswith("First navigate to 'https://example.com'")+ assert browser_session.calls == []+ assert agent._completed_initial_navigation_urls == []+ assert seen[0].startswith("First navigate to 'https://example.com'")+ assert "already open at 'https://example.com'" not in seen[0]def test_rust_history_uses_browser_script_lifecycle_outputs_as_result():@@ -7363,7 +7363,7 @@ async def test_rust_agent_multi_act_ignores_later_done_actions():assert results[0].extracted_content == 'clicked only'-async def test_rust_agent_initial_actions_pre_navigate_existing_cdp_session():+async def test_rust_agent_initial_actions_can_pre_navigate_existing_cdp_session(monkeypatch):from types import SimpleNamespacefrom browser_use.rust import Agent@@ -7386,6 +7386,7 @@ async def test_rust_agent_initial_actions_pre_navigate_existing_cdp_session():initial_actions=[{'navigate': {'url': 'https://example.com', 'new_tab': False}}],)+ monkeypatch.setenv('BROWSER_USE_RUST_DIRECT_INITIAL_NAVIGATION', '1')await agent._execute_initial_actions(allow_terminal_run=False)assert browser_session.calls == [('https://example.com', False)]