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
Forward SDK browser payload settings
Magnus Müller96b6b696137e
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex a727b9ecb..0322144a1 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -181,6 +181,12 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly importRust SDK server path, so the legacy terminal CLI adapter cannot silentlyreplace the new server protocol while the normal Python `browser_use.Agent`remains unchanged.+ - Terminal SDK browser requests now preserve and forward additional+ Browser Use-style browser settings: proxy country, local profile label,+ allowed/blocked domains, window size, and state directory. For cloud+ browser runs, proxy country is passed to `browser remote start`, so Rust+ SDK sessions can use Browser Use Cloud browser proxies through the same+ Python-facing `browser_profile`/`browser_session` options.## Current Proof@@ -237,6 +243,11 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_prefers_notification_final_when_response_history_lacks_result tests/ci/test_rust_agent.py::test_rust_agent_uses_sdk_history_usage_when_events_do_not_include_usage tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_final_result_from_sdk_notifications_after_transport_error tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_recovers_projected_sdk_final_events tests/ci/test_rust_agent.py::test_rust_agent_prefers_notification_final_when_response_history_lacks_result tests/ci/test_rust_agent.py::test_rust_agent_uses_sdk_history_usage_when_events_do_not_include_usage tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_runs_through_sdk_and_reuses_session_for_followup tests/ci/test_rust_agent.py::test_rust_agent_ignores_legacy_run_process_monkeypatch_for_sdk_server -q`+- terminal `cargo fmt --check`+- terminal `cargo test -p browser-use-cli sdk_json_rpc_browser_create_preserves_browser_use_settings -- --nocapture`+- terminal `cargo test -p browser-use-cli sdk_provider_run_config_maps_browser_use_options_to_rust_core -- --nocapture`+- terminal `cargo test -p browser-use-agent stored_cloud_profile_uses_sdk_proxy_country_env_when_connecting -- --nocapture`+- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_sdk_browser_payload_includes_profile_domains_window_and_proxy -q`- 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'`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 8548cb260..00bf9bdac 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -914,6 +914,18 @@ def _extract_browser_viewport(return no_viewport, viewport+def _extract_browser_window_size(+ browser_session: BrowserSession | None, browser_profile: BrowserProfile | None+) -> dict[str, int] | None:+ session_profile = getattr(browser_session, 'browser_profile', None)+ for profile in (session_profile, browser_profile, browser_session):+ window_size = _viewport_size(getattr(profile, 'window_size', None))+ if window_size is not None:+ width, height = window_size+ return {'width': width, 'height': height}+ return None++def _storage_state_value(value: Any) -> dict[str, Any] | None:if isinstance(value, dict):return value@@ -4239,6 +4251,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.browser_session, self.browser_profile)self.browser_no_viewport, self.browser_viewport = _extract_browser_viewport(self.browser_session, self.browser_profile)+ self.browser_window_size = _extract_browser_window_size(self.browser_session, self.browser_profile)self.browser_storage_state = _extract_browser_storage_state(self.browser_session, self.browser_profile)self.sensitive_data_context = _sensitive_data_context(sensitive_data)_warn_sensitive_data_domain_constraints(self.logger, sensitive_data, self.allowed_domains)@@ -6293,8 +6306,12 @@ class Agent(Generic[Context, AgentStructuredOutput]):put('cdp_headers', self.cdp_headers or None)put('user_agent', self.browser_user_agent)put('viewport', self.browser_viewport)+ put('window_size', self.browser_window_size)put('storage_state', self.browser_storage_state)put('downloads_path', self.browser_downloads_path)+ put('allowed_domains', self.allowed_domains or None)+ put('blocked_domains', self.prohibited_domains or None)+ put('state_dir', self._sdk_browser_state_dir())put('no_viewport', self.browser_no_viewport)put('accept_downloads', self.browser_accept_downloads)put('headless', _extract_headless_preference(self.browser_session, self.browser_profile))@@ -6323,6 +6340,12 @@ class Agent(Generic[Context, AgentStructuredOutput]):return valuereturn None+ def _sdk_browser_state_dir(self) -> str | None:+ value = getattr(self.browser_profile, 'state_dir', None)+ if isinstance(value, (str, os.PathLike)) and str(value):+ return str(Path(value).expanduser())+ return None+def _sdk_run_params(self, *, max_steps: int, task: str, followups: list[str] | None = None) -> dict[str, Any]:params: dict[str, Any] = {'task': task,diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex ee9a942f8..cfc5f9c08 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -2539,6 +2539,31 @@ def test_rust_agent_translates_browser_use_args_to_terminal(monkeypatch):assert "First navigate to 'https://example.com'" in params['task']+def test_rust_agent_sdk_browser_payload_includes_profile_domains_window_and_proxy(monkeypatch, tmp_path):+ from browser_use.rust import Agent++ class BrowserProfile:+ cdp_url = 'http://127.0.0.1:9222'+ allowed_domains = ['example.com']+ prohibited_domains = ['*.tracking.example']+ window_size = {'width': 1440, 'height': 900}+ proxy_country_code = 'DE'+ state_dir = tmp_path++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')++ agent = Agent(task='report title', browser_profile=BrowserProfile())+ params = agent._sdk_run_params(max_steps=4, task=agent.task)++ assert params['browser_mode'] == 'remote-cdp'+ assert params['browser']['cdp_url'] == 'http://127.0.0.1:9222'+ assert params['browser']['allowed_domains'] == ['example.com']+ assert params['browser']['blocked_domains'] == ['*.tracking.example']+ assert params['browser']['window_size'] == {'width': 1440, 'height': 900}+ assert params['browser']['proxy_country_code'] == 'DE'+ assert params['browser']['state_dir'] == str(tmp_path)++async def test_rust_agent_runs_through_sdk_and_reuses_session_for_followup(monkeypatch):from browser_use.rust import Agent