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
Trust only confirmed Rust pre-navigation
Magnus Müller4c04bdce44f7
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex e209ef024..ecaf978c0 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -106,6 +106,16 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly importURL/title into the Rust task context. Start-URL tasks should begin byinspecting or extracting from the already-loaded page instead of spendingearly turns on repeated navigation/status recovery.+ - Browser-use Rust direct CDP pre-navigation now only records an initial+ navigation as completed when the observed browser state matches the+ requested URL. If the Cloud Browser remains on `about:blank` or another+ mismatched target, the original navigation stays in the Rust task context+ instead of giving the model a false "already loaded" state.+ - Eval GitHub runners now preserve visible output for interrupted Rust runs:+ if an agent is cancelled or errors after collecting history, formatting+ synthesizes a partial final answer from the latest memory/tool evidence;+ if no history exists, the saved dashboard payload still includes a+ non-empty failure response with the stage error.## Current Proof@@ -143,10 +153,12 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- 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`- browser-use `PYTHONPATH=. uv run pytest tests/ci/test_rust_agent.py -q -k 'pre_navigates_cdp_session_before_sdk_by_default or initial_actions_can_pre_navigate_existing_cdp_session or direct_initial_navigation_defaults_on_for_cdp or direct_initial_navigation_can_be_disabled'`+- browser-use `uv run pytest -q tests/ci/test_rust_agent.py -k "pre_navigates_cdp_session_before_sdk_by_default or keeps_initial_navigation_when_direct_state_mismatches or initial_actions_can_pre_navigate_existing_cdp_session or direct_initial_navigation_defaults_on_for_cdp"`- browser-use `python -m py_compile browser_use/rust/service.py`- evaluations-internal `uv run python -m py_compile eval/service.py`- evaluations-internal `python -m py_compile eval/task_types.py`- evaluations-internal `PYTHONPATH=. uv run pytest tests/test_service_cli.py -q -k 'usage_aliases or trims_oversized_history_fields or rust_eval_uses_adapter_initial_navigation_default or rust_eval_preserves_explicit_direct_initial_navigation_override'`+- evaluations-internal `PYTHONPATH=. uv run pytest -q tests/test_service_cli.py -k "synthesizes_partial_result_on_timeout or synthesizes_partial_result_without_timeout_marker or server_payload_includes_failure_final_response_without_history"`- 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 with`BROWSER_USE_TERMINAL_BINARY=/home/exedev/Developer/terminal/target/debug/browser-use-terminal`,diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex f751595f0..f68b95aac 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -5756,6 +5756,17 @@ class Agent(Generic[Context, AgentStructuredOutput]):results.append(ActionResult(error=message))continuestate = await self._capture_direct_initial_navigation_state(url)+ if not self._direct_initial_navigation_state_matches(url, getattr(state, 'url', '') if state else None):+ observed_url = getattr(state, 'url', None) if state else None+ self.logger.warning(+ 'Initial navigation to %s was not confirmed by browser state; observed %s. '+ 'Leaving navigation in the Rust task context.',+ url,+ observed_url or '<unknown>',+ )+ self._completed_initial_navigation_urls = []+ self._completed_initial_navigation_states = []+ return Nonestate_context = self._direct_initial_navigation_state_context(url, state)text = f'Navigated to {url}'current_url = state_context.get('url')@@ -5799,12 +5810,20 @@ class Agent(Generic[Context, AgentStructuredOutput]):requested = str(requested_url or '')if not current:return False- if current == requested or current.startswith(requested):+ if current == requested:return Truetry:current_parts = urlparse(current)requested_parts = urlparse(requested)- return bool(requested_parts.netloc and current_parts.netloc == requested_parts.netloc)+ if not requested_parts.netloc or current_parts.netloc != requested_parts.netloc:+ return False+ requested_path = (requested_parts.path or '/').rstrip('/') or '/'+ current_path = (current_parts.path or '/').rstrip('/') or '/'+ if requested_path != '/' and current_path != requested_path:+ return False+ if requested_parts.query and current_parts.query != requested_parts.query:+ return False+ return Trueexcept Exception:return Falsediff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex fc12db184..582817c9c 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -7110,6 +7110,58 @@ async def test_rust_agent_run_pre_navigates_cdp_session_before_sdk_by_default():assert "First navigate to 'https://example.com'" not in seen[0]+async def test_rust_agent_run_keeps_initial_navigation_when_direct_state_mismatches():+ from types import SimpleNamespace++ from browser_use.rust import Agent+ from browser_use.rust.service import _history_from_events++ class FakeBrowserSession:+ id = 'browser-cdp'+ cdp_url = 'wss://cloud-browser.example/devtools/browser/session'+ browser_profile = SimpleNamespace(cdp_url=cdp_url)++ def __init__(self):+ self.calls = []++ async def navigate_to(self, url, new_tab=False):+ self.calls.append((url, new_tab))++ async def get_browser_state_summary(self, include_screenshot=False):+ assert include_screenshot is False+ return SimpleNamespace(url='about:blank', title='', tabs=[])++ browser_session = FakeBrowserSession()+ agent = Agent(+ task='read the page',+ browser_session=browser_session,+ initial_actions=[{'navigate': {'url': 'https://example.com/start', 'new_tab': False}}],+ )+ seen = []++ async def fake_run_sdk_agent(**kwargs):+ seen.append(kwargs['task'])+ return _history_from_events(+ [{'event_type': 'session.done', 'payload': {'result': 'done'}}],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ agent._run_sdk_agent = fake_run_sdk_agent+ agent._initialize_run_lifecycle_state = lambda: None++ history = await agent.run(max_steps=3)++ assert history.final_result() == 'done'+ assert browser_session.calls == [('https://example.com/start', False)]+ assert agent._completed_initial_navigation_urls == []+ assert seen[0].startswith("First navigate to 'https://example.com/start'")+ assert 'The browser session is already open at' not in seen[0]++def test_rust_history_uses_browser_script_lifecycle_outputs_as_result():from browser_use.rust.service import _history_from_events@@ -7387,6 +7439,10 @@ async def test_rust_agent_initial_actions_can_pre_navigate_existing_cdp_session(async def navigate_to(self, url, new_tab=False):self.calls.append((url, new_tab))+ async def get_browser_state_summary(self, include_screenshot=False):+ assert include_screenshot is False+ return SimpleNamespace(url='https://example.com', title='Example Domain', tabs=[])+browser_session = FakeBrowserSession()agent = Agent(task='read the page',@@ -7400,7 +7456,10 @@ async def test_rust_agent_initial_actions_can_pre_navigate_existing_cdp_session(assert browser_session.calls == [('https://example.com', False)]assert agent._initial_actions_executed is Trueassert agent._completed_initial_navigation_urls == ['https://example.com']- assert agent.state.last_result[0].extracted_content == 'Navigated to https://example.com'+ assert (+ agent.state.last_result[0].extracted_content+ == 'Navigated to https://example.com. Current page: https://example.com (Example Domain)'+ )assert agent.history.history[0].metadata.step_number == 0assert agent.history.history[0].model_output.action == agent.initial_actions@@ -7421,6 +7480,10 @@ async def test_rust_agent_direct_initial_navigation_defaults_on_for_cdp(monkeypaasync def navigate_to(self, url, new_tab=False):self.calls.append((url, new_tab))+ async def get_browser_state_summary(self, include_screenshot=False):+ assert include_screenshot is False+ return SimpleNamespace(url='https://example.com', title='Example Domain', tabs=[])+browser_session = FakeBrowserSession()agent = Agent(task='read the page',@@ -7434,7 +7497,10 @@ async def test_rust_agent_direct_initial_navigation_defaults_on_for_cdp(monkeypaassert browser_session.calls == [('https://example.com', False)]assert agent._initial_actions_executed is Trueassert agent._completed_initial_navigation_urls == ['https://example.com']- assert agent.state.last_result[0].extracted_content == 'Navigated to https://example.com'+ assert (+ agent.state.last_result[0].extracted_content+ == 'Navigated to https://example.com. Current page: https://example.com (Example Domain)'+ )async def test_rust_agent_direct_initial_navigation_can_be_disabled(monkeypatch):