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 window position
Magnus Müllerfcba279fea44
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 4db460fb1..453e43cc3 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -145,10 +145,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at latest pulled mai- The flags are passed through `BU_MANAGED_BROWSER_ARGS` and deduped with caller-provided `BrowserProfile.args`.- Proof: `test_rust_agent_translates_browser_profile_chromium_sandbox`.+28. BrowserProfile window position bridge+ - `BrowserProfile.window_position` is serialized into `--window-position=x,y` for terminal managed Chromium runs.+ - Dict-style and tuple-style position values are accepted by the Rust-backed wrapper.+ - Proof: `test_rust_agent_translates_browser_profile_window_position`.+## 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` (37 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (38 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`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 9b9083b41..3574d7765 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -136,6 +136,19 @@ def _window_size_arg(window_size: Any) -> str | None:return f'--window-size={width},{height}'+def _window_position_arg(window_position: Any) -> str | None:+ if window_position is None:+ return None+ if isinstance(window_position, (list, tuple)) and len(window_position) >= 2:+ x, y = window_position[0], window_position[1]+ else:+ x = _value_from_object(window_position, 'width')+ y = _value_from_object(window_position, 'height')+ if not isinstance(x, int) or not isinstance(y, int):+ return None+ return f'--window-position={x},{y}'++def _managed_browser_launch_args(browser_session: BrowserSession | None, browser_profile: BrowserProfile | None) -> list[str]:args: list[str] = []seen: set[str] = set()@@ -157,6 +170,7 @@ def _managed_browser_launch_args(browser_session: BrowserSession | None, browserfor arg in CHROME_DOCKER_ARGS:_append_unique(args, seen, arg)_append_unique(args, seen, _window_size_arg(getattr(profile, 'window_size', None)))+ _append_unique(args, seen, _window_position_arg(getattr(profile, 'window_position', None)))proxy = getattr(profile, 'proxy', None)proxy_server = _value_from_object(proxy, 'server')if isinstance(proxy_server, str) and proxy_server:diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex a8d8fbf74..ff762ec7f 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -288,6 +288,28 @@ def test_rust_agent_translates_browser_profile_chromium_sandbox(monkeypatch):assert '--disable-dev-shm-usage' in launch_args+def test_rust_agent_translates_browser_profile_window_position(monkeypatch):+ from browser_use.rust import Agent++ class BrowserProfile:+ headless = False+ window_position = {'width': 32, 'height': 64}++ class TuplePositionProfile:+ headless = False+ window_position = (12, 24)++ 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())+ tuple_agent = Agent(task='report title', browser_profile=TuplePositionProfile())++ assert '--window-position=32,64' in json.loads(agent._run_env()['BU_MANAGED_BROWSER_ARGS'])+ assert '--window-position=12,24' in json.loads(tuple_agent._run_env()['BU_MANAGED_BROWSER_ARGS'])++def test_rust_agent_translates_browser_profile_user_data_dir(monkeypatch, tmp_path):from browser_use.rust import Agent