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 wait timings
Magnus Müller788253100337
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex e18ab95f7..ab8f3513d 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -196,10 +196,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- The terminal core applies it with CDP `Network.setUserAgentOverride`, covering remote-CDP and cloud browsers in addition to the existing managed Chromium `--user-agent` launch arg.- Proof: `test_rust_agent_translates_browser_profile_remote_user_agent`, `test_rust_agent_translates_browser_profile_managed_launch_args`, and `browser_user_agent_env_builds_override_params`.+38. BrowserProfile page wait timing bridge+ - `BrowserProfile.minimum_wait_page_load_time`, `wait_for_network_idle_page_load_time`, and `wait_between_actions` are serialized into Rust browser-script helper env controls.+ - The terminal helper layer uses those values for post-navigation waits, default network-idle windows, and action helper delays.+ - Proof: `test_rust_agent_translates_browser_profile_wait_timings` and `browser_script_helpers_read_wait_timing_env`.+## 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` (47 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (48 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`@@ -211,6 +216,7 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser cdp_headers_env_builds_websocket_request_headers -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_highlight_env_controls_color_and_duration -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_user_agent_env_builds_override_params -- --nocapture`+- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_script_helpers_read_wait_timing_env -- --nocapture`- Managed-headless end-to-end:- `BROWSER_USE_TERMINAL_BINARY=/home/exedev/Developer/terminal/target/debug/browser-use-terminal BROWSER_USE_RUST_BROWSER_MODE=managed-headless BU_TASK='Open https://example.com and report the page title only.' BU_MAX_STEPS=12 timeout 300 uv run python examples/rust_agent/basic.py`- Output: `Example Domain`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex f8f61de01..f29fa5e6f 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -278,6 +278,32 @@ def _extract_highlight_settings(return enabled, color, duration_ms+def _seconds_to_ms(value: Any) -> int | None:+ if isinstance(value, bool) or not isinstance(value, (int, float)) or value < 0:+ return None+ return int(value * 1000)+++def _extract_wait_timing_settings(+ browser_session: BrowserSession | None, browser_profile: BrowserProfile | None+) -> dict[str, str]:+ settings: dict[str, str] = {}+ session_profile = getattr(browser_session, 'browser_profile', None)+ mappings = (+ ('minimum_wait_page_load_time', 'BU_BROWSER_MINIMUM_WAIT_PAGE_LOAD_MS'),+ ('wait_for_network_idle_page_load_time', 'BU_BROWSER_NETWORK_IDLE_PAGE_LOAD_MS'),+ ('wait_between_actions', 'BU_BROWSER_WAIT_BETWEEN_ACTIONS_MS'),+ )+ for profile in (session_profile, browser_profile, browser_session):+ for attr, env_name in mappings:+ if env_name in settings:+ continue+ value_ms = _seconds_to_ms(getattr(profile, attr, None))+ if value_ms is not None:+ settings[env_name] = str(value_ms)+ return settings++def _extract_profile_permissions(browser_session: BrowserSession | None, browser_profile: BrowserProfile | None) -> list[str]:values: list[str] = []seen: set[str] = set()@@ -931,6 +957,7 @@ class Agent(Generic[AgentStructuredOutput]):self.highlight_enabled, self.highlight_color, self.highlight_duration_ms = _extract_highlight_settings(self.browser_session, self.browser_profile)+ self.wait_timing_env = _extract_wait_timing_settings(self.browser_session, self.browser_profile)self.browser_permissions = _extract_profile_permissions(self.browser_session, self.browser_profile)self.browser_accept_downloads, self.browser_downloads_path = _extract_browser_downloads(self.browser_session, self.browser_profile@@ -1394,6 +1421,7 @@ class Agent(Generic[AgentStructuredOutput]):env['BROWSER_USE_TERMINAL_HIGHLIGHT_COLOR'] = self.highlight_colorif self.highlight_duration_ms is not None:env['BROWSER_USE_TERMINAL_HIGHLIGHT_DURATION_MS'] = str(self.highlight_duration_ms)+ env.update(self.wait_timing_env)if self.browser_permissions:env['BU_BROWSER_PERMISSIONS'] = json.dumps(self.browser_permissions)if self.browser_accept_downloads is not None:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex f25c9666c..95b7b877d 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -249,6 +249,30 @@ def test_rust_agent_translates_browser_profile_highlights(monkeypatch):assert dom_env['BROWSER_USE_TERMINAL_AUTO_HIGHLIGHT'] == 'false'+def test_rust_agent_translates_browser_profile_wait_timings(monkeypatch):+ from browser_use.rust import Agent++ class BrowserProfile:+ minimum_wait_page_load_time = 0.25+ wait_for_network_idle_page_load_time = 0.75+ wait_between_actions = 0.125+ cdp_url = 'http://127.0.0.1:9222'++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')++ agent = Agent(task='report title', browser_profile=BrowserProfile())+ env = agent._run_env()++ assert agent.wait_timing_env == {+ 'BU_BROWSER_MINIMUM_WAIT_PAGE_LOAD_MS': '250',+ 'BU_BROWSER_NETWORK_IDLE_PAGE_LOAD_MS': '750',+ 'BU_BROWSER_WAIT_BETWEEN_ACTIONS_MS': '125',+ }+ assert env['BU_BROWSER_MINIMUM_WAIT_PAGE_LOAD_MS'] == '250'+ assert env['BU_BROWSER_NETWORK_IDLE_PAGE_LOAD_MS'] == '750'+ assert env['BU_BROWSER_WAIT_BETWEEN_ACTIONS_MS'] == '125'++def test_rust_agent_translates_browser_profile_headless(monkeypatch):from browser_use.rust import Agent