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
Default Rust CDP initial navigation
Magnus Müller403fe55d838b
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 72b42f42e..182e16644 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1068,8 +1068,10 @@ def _string_env_value(value: Any) -> str | 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'}+ raw = os.getenv('BROWSER_USE_RUST_DIRECT_INITIAL_NAVIGATION')+ if raw is None:+ return True+ return raw.strip().lower() not in {'0', 'false', 'no', 'off'}def _llm_provider_name(llm: Any) -> str | None:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex f2ff3f1dc..e1118b05b 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -7397,6 +7397,69 @@ async def test_rust_agent_initial_actions_can_pre_navigate_existing_cdp_session(assert agent.history.history[0].model_output.action == agent.initial_actions+async def test_rust_agent_direct_initial_navigation_defaults_on_for_cdp(monkeypatch):+ from types import SimpleNamespace++ from browser_use.rust import Agent++ 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))++ browser_session = FakeBrowserSession()+ agent = Agent(+ task='read the page',+ browser_session=browser_session,+ initial_actions=[{'navigate': {'url': 'https://example.com', 'new_tab': False}}],+ )++ monkeypatch.delenv('BROWSER_USE_RUST_DIRECT_INITIAL_NAVIGATION', raising=False)+ await agent._execute_initial_actions(allow_terminal_run=False)++ assert browser_session.calls == [('https://example.com', False)]+ assert agent._initial_actions_executed is True+ assert agent._completed_initial_navigation_urls == ['https://example.com']+ assert agent.state.last_result[0].extracted_content == 'Navigated to https://example.com'+++async def test_rust_agent_direct_initial_navigation_can_be_disabled(monkeypatch):+ from types import SimpleNamespace++ from browser_use.rust import Agent++ 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))++ browser_session = FakeBrowserSession()+ agent = Agent(+ task='read the page',+ browser_session=browser_session,+ initial_actions=[{'navigate': {'url': 'https://example.com', 'new_tab': False}}],+ )++ monkeypatch.setenv('BROWSER_USE_RUST_DIRECT_INITIAL_NAVIGATION', '0')+ await agent._execute_initial_actions(allow_terminal_run=False)++ assert browser_session.calls == []+ assert agent._initial_actions_executed is False+ assert agent.history.history == []++async def test_rust_agent_exposes_action_replay_helper_methods(monkeypatch):from types import SimpleNamespace