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 highlights
Magnus Müller060bdf9bbb2d
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex b9a23e718..e6f31fba8 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -186,10 +186,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- The terminal core applies those headers when resolving HTTP CDP endpoints through `/json/version` and when opening CDP WebSocket connections.- Proof: `test_rust_agent_translates_browser_profile_cdp_headers` and `cdp_headers_env_builds_websocket_request_headers`.+36. BrowserProfile interaction highlight bridge+ - `BrowserProfile.highlight_elements`, `dom_highlight_elements`, `interaction_highlight_color`, and `interaction_highlight_duration` are serialized into Rust terminal highlight env controls.+ - The terminal core now supports configurable highlight duration in addition to its existing highlight enable and color controls.+ - Proof: `test_rust_agent_translates_browser_profile_highlights` and `browser_highlight_env_controls_color_and_duration`.+## 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` (45 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (46 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`@@ -199,6 +204,7 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_viewport_env_ -- --nocapture`- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-browser browser_storage_state_env_parses_cookies_and_storage_scripts -- --nocapture`- `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`- 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 dcbc43504..66666bf45 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -243,6 +243,32 @@ def _extract_cdp_headers(browser_session: BrowserSession | None, browser_profilereturn headers+def _extract_highlight_settings(+ browser_session: BrowserSession | None, browser_profile: BrowserProfile | None+) -> tuple[bool | None, str | None, int | None]:+ enabled: bool | None = None+ color: str | None = None+ duration_ms: int | None = None+ session_profile = getattr(browser_session, 'browser_profile', None)+ for profile in (session_profile, browser_profile, browser_session):+ if enabled is None:+ if getattr(profile, 'dom_highlight_elements', None) is True:+ enabled = False+ else:+ value = getattr(profile, 'highlight_elements', None)+ if isinstance(value, bool):+ enabled = value+ if color is None:+ value = getattr(profile, 'interaction_highlight_color', None)+ if isinstance(value, str) and value:+ color = value+ if duration_ms is None:+ value = getattr(profile, 'interaction_highlight_duration', None)+ if isinstance(value, (int, float)) and value >= 0:+ duration_ms = int(value * 1000)+ return enabled, color, duration_ms++def _extract_profile_permissions(browser_session: BrowserSession | None, browser_profile: BrowserProfile | None) -> list[str]:values: list[str] = []seen: set[str] = set()@@ -892,6 +918,9 @@ class Agent(Generic[AgentStructuredOutput]):self.managed_browser_executable_path = _managed_browser_executable_path(self.browser_session, self.browser_profile)self.managed_browser_env = _managed_browser_env(self.browser_session, self.browser_profile)self.cdp_headers = _extract_cdp_headers(self.browser_session, self.browser_profile)+ self.highlight_enabled, self.highlight_color, self.highlight_duration_ms = _extract_highlight_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@@ -1347,6 +1376,12 @@ class Agent(Generic[AgentStructuredOutput]):env['BU_CDP_URL'] = cdp_urlif self.cdp_headers:env['BU_CDP_HEADERS'] = json.dumps(self.cdp_headers)+ if self.highlight_enabled is not None:+ env['BROWSER_USE_TERMINAL_AUTO_HIGHLIGHT'] = 'true' if self.highlight_enabled else 'false'+ if self.highlight_color:+ env['BROWSER_USE_TERMINAL_HIGHLIGHT_COLOR'] = self.highlight_color+ if self.highlight_duration_ms is not None:+ env['BROWSER_USE_TERMINAL_HIGHLIGHT_DURATION_MS'] = str(self.highlight_duration_ms)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 093dcb6d9..17f4325ed 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -201,6 +201,37 @@ def test_rust_agent_translates_browser_profile_cdp_headers(monkeypatch):assert json.loads(env['BU_CDP_HEADERS']) == agent.cdp_headers+def test_rust_agent_translates_browser_profile_highlights(monkeypatch):+ from browser_use.rust import Agent++ class BrowserProfile:+ highlight_elements = True+ dom_highlight_elements = False+ interaction_highlight_color = 'rgb(255, 127, 39)'+ interaction_highlight_duration = 1.75+ cdp_url = 'http://127.0.0.1:9222'++ class DomHighlightProfile:+ highlight_elements = True+ dom_highlight_elements = True+ 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 env['BROWSER_USE_TERMINAL_AUTO_HIGHLIGHT'] == 'true'+ assert env['BROWSER_USE_TERMINAL_HIGHLIGHT_COLOR'] == 'rgb(255, 127, 39)'+ assert env['BROWSER_USE_TERMINAL_HIGHLIGHT_DURATION_MS'] == '1750'++ dom_agent = Agent(task='report title', browser_profile=DomHighlightProfile())+ dom_env = dom_agent._run_env()++ assert dom_agent.highlight_enabled is False+ assert dom_env['BROWSER_USE_TERMINAL_AUTO_HIGHLIGHT'] == 'false'++def test_rust_agent_translates_browser_profile_headless(monkeypatch):from browser_use.rust import Agent