Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Bridge BrowserProfile managed launch args

Magnus Müller0ecbe3c1f302
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index bb70af530..3a851aa66 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -120,12 +120,18 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai
- Candidates are accepted only if they validate against the requested Pydantic schema.
- Proof: `test_rust_history_extracts_fenced_structured_output`.
+23. BrowserProfile managed launch args bridge
+ - `BrowserProfile.args`, `proxy`, `window_size`, `user_agent`, `disable_security`, and `deterministic_rendering` are serialized into `BU_MANAGED_BROWSER_ARGS` for terminal managed Chromium runs.
+ - The terminal core converts those JSON args into repeated `browser connect managed --arg ...` flags for both selected-mode connect and auto-ensure before browser actions.
+ - Proof: `test_rust_agent_translates_browser_profile_managed_launch_args` and `bare_browser_connect_resolves_to_selected_managed_mode_with_launch_args`.
+
## 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` (32 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (33 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`
- 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.py
index 7727e28ff..4e62d4827 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -18,6 +18,7 @@ from uuid_extensions import uuid7str
from browser_use.agent.views import ActionResult, AgentHistory, AgentHistoryList, AgentSettings, AgentState, StepMetadata
from browser_use.browser import BrowserProfile, BrowserSession
+from browser_use.browser.profile import CHROME_DETERMINISTIC_RENDERING_ARGS, CHROME_DISABLE_SECURITY_ARGS
from browser_use.browser.views import BrowserStateHistory, TabInfo
from browser_use.tokens.views import ModelUsageStats, UsageSummary
@@ -105,6 +106,72 @@ def _extract_cloud_preference(browser_session: BrowserSession | None, browser_pr
return False
+def _value_from_object(value: Any, key: str) -> Any:
+ if value is None:
+ return None
+ if isinstance(value, dict):
+ return value.get(key)
+ return getattr(value, key, None)
+
+
+def _append_unique(items: list[str], seen: set[str], value: Any) -> None:
+ if not isinstance(value, str) or not value:
+ return
+ if value in seen:
+ return
+ items.append(value)
+ seen.add(value)
+
+
+def _window_size_arg(window_size: Any) -> str | None:
+ if window_size is None:
+ return None
+ if isinstance(window_size, (list, tuple)) and len(window_size) >= 2:
+ width, height = window_size[0], window_size[1]
+ else:
+ width = _value_from_object(window_size, 'width')
+ height = _value_from_object(window_size, 'height')
+ if not isinstance(width, int) or not isinstance(height, int) or width <= 0 or height <= 0:
+ return None
+ return f'--window-size={width},{height}'
+
+
+def _managed_browser_launch_args(browser_session: BrowserSession | None, browser_profile: BrowserProfile | None) -> list[str]:
+ args: list[str] = []
+ seen: set[str] = set()
+ session_profile = getattr(browser_session, 'browser_profile', None)
+ for profile in (session_profile, browser_profile):
+ raw_args = getattr(profile, 'args', None)
+ if isinstance(raw_args, set):
+ raw_args = sorted(raw_args)
+ if isinstance(raw_args, (list, tuple)):
+ for arg in raw_args:
+ _append_unique(args, seen, arg)
+ if getattr(profile, 'disable_security', False) is True:
+ for arg in CHROME_DISABLE_SECURITY_ARGS:
+ _append_unique(args, seen, arg)
+ if getattr(profile, 'deterministic_rendering', False) is True:
+ for arg in CHROME_DETERMINISTIC_RENDERING_ARGS:
+ _append_unique(args, seen, arg)
+ _append_unique(args, seen, _window_size_arg(getattr(profile, 'window_size', None)))
+ proxy = getattr(profile, 'proxy', None)
+ proxy_server = _value_from_object(proxy, 'server')
+ if isinstance(proxy_server, str) and proxy_server:
+ _append_unique(args, seen, f'--proxy-server={proxy_server}')
+ proxy_bypass = _value_from_object(proxy, 'bypass')
+ if isinstance(proxy_bypass, str) and proxy_bypass:
+ _append_unique(args, seen, f'--proxy-bypass-list={proxy_bypass}')
+ user_agent = getattr(profile, 'user_agent', None)
+ if isinstance(user_agent, str) and user_agent:
+ _append_unique(args, seen, f'--user-agent={user_agent}')
+ return args
+
+
+def _is_managed_browser_mode(mode: str) -> bool:
+ normalized = mode.strip().lower().replace('_', '-').replace(' ', '-')
+ return normalized in {'managed-headless', 'headless', 'headless-chromium', 'managed-headed', 'managed', 'headed'}
+
+
def _domain_list(value: Any) -> list[str]:
if value is None or isinstance(value, str):
return []
@@ -626,6 +693,7 @@ class Agent(Generic[AgentStructuredOutput]):
self.available_file_paths = available_file_paths or []
self.allowed_domains = _extract_profile_domains(self.browser_session, self.browser_profile, 'allowed_domains')
self.prohibited_domains = _extract_profile_domains(self.browser_session, self.browser_profile, 'prohibited_domains')
+ self.managed_browser_args = _managed_browser_launch_args(self.browser_session, self.browser_profile)
self.sensitive_data_context = _sensitive_data_context(sensitive_data)
self.display_files_in_done_text = display_files_in_done_text
self.file_system_path = file_system_path
@@ -1066,10 +1134,13 @@ class Agent(Generic[AgentStructuredOutput]):
def _run_env(self) -> dict[str, str]:
env = os.environ.copy()
- env['LLM_BROWSER_BROWSER_MODE'] = self._browser_mode()
+ browser_mode = self._browser_mode()
+ env['LLM_BROWSER_BROWSER_MODE'] = browser_mode
cdp_url = _extract_cdp_url(self.browser_session) or _extract_profile_cdp_url(self.browser_profile)
if cdp_url:
env['BU_CDP_URL'] = cdp_url
+ if self.managed_browser_args and _is_managed_browser_mode(browser_mode):
+ env['BU_MANAGED_BROWSER_ARGS'] = json.dumps(self.managed_browser_args)
return env
def _session_id_from_stdout(self, stdout: str) -> str | None:
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 8fbc64190..725ea75d5 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -234,6 +234,39 @@ def test_rust_agent_translates_browser_profile_cloud(monkeypatch):
assert agent._run_env()['LLM_BROWSER_BROWSER_MODE'] == 'cloud'
+def test_rust_agent_translates_browser_profile_managed_launch_args(monkeypatch):
+ from browser_use.rust import Agent
+
+ class Proxy:
+ server = 'http://proxy.example:8080'
+ bypass = 'localhost,127.0.0.1'
+
+ class BrowserProfile:
+ headless = True
+ args = ['--lang=en-US']
+ disable_security = True
+ proxy = Proxy()
+ window_size = {'width': 1440, 'height': 900}
+ user_agent = 'BrowserUseTest/1.0'
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+ monkeypatch.delenv('BROWSER_USE_RUST_BROWSER_MODE', raising=False)
+ monkeypatch.delenv('BROWSER_USE_BROWSER_MODE', raising=False)
+
+ agent = Agent(task='report title', browser_profile=BrowserProfile())
+ env = agent._run_env()
+ launch_args = json.loads(env['BU_MANAGED_BROWSER_ARGS'])
+
+ assert env['LLM_BROWSER_BROWSER_MODE'] == 'managed-headless'
+ assert agent.managed_browser_args == launch_args
+ assert '--lang=en-US' in launch_args
+ assert '--window-size=1440,900' in launch_args
+ assert '--proxy-server=http://proxy.example:8080' in launch_args
+ assert '--proxy-bypass-list=localhost,127.0.0.1' in launch_args
+ assert '--disable-web-security' in launch_args
+ assert '--user-agent=BrowserUseTest/1.0' in launch_args
+
+
def test_rust_agent_adds_browser_profile_domain_constraints():
from browser_use.rust import Agent