Skip to content

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

Add Rust agent browser profile property parity

Magnus Müller75b7be41a32a
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 0daf99289..d5213b25b 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -461,10 +461,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee
- Page updates rebuild `ActionModel`, `AgentOutput`, `DoneActionModel`, and `DoneAgentOutput` through the configured tools registry with the current page URL.
- Proof: `test_rust_agent_updates_action_models_for_page`.
+91. Rust Agent browser profile property parity
+ - The Rust-backed `Agent` now exposes `browser_profile` as a Browser Use-style property derived from the current `browser_session.browser_profile`.
+ - The wrapper keeps a fallback initial profile for lightweight custom sessions while reflecting later browser-session profile changes through the public property.
+ - Proof: `test_rust_agent_browser_profile_property_tracks_session_profile`.
+
## 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` (64 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (65 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.py
index 4c13c6aef..aebbcd6a1 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -1097,7 +1097,7 @@ class Agent(Generic[AgentStructuredOutput]):
self.id = task_id or uuid7str()
self.task_id = self.id
self.llm = llm
- self.browser_session, self.browser_profile = _default_browser_session(
+ self.browser_session, self._browser_profile = _default_browser_session(
self.id,
browser_profile,
browser_session,
@@ -1355,6 +1355,11 @@ class Agent(Generic[AgentStructuredOutput]):
f'browser_use.rust.Agent {self.task_id[-4:]} -> BrowserSession {str(browser_session_id)[-4:]} Target {target_id}'
)
+ @property
+ def browser_profile(self) -> Any:
+ session_profile = getattr(self.browser_session, 'browser_profile', None)
+ return session_profile if session_profile is not None else self._browser_profile
+
@property
def message_manager(self) -> MessageManager:
return self._message_manager
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index c5fab4cf2..c1ff08834 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -912,6 +912,29 @@ def test_rust_agent_initializes_browser_use_session_and_file_system(tmp_path):
assert agent.state.file_system_state is not None
+def test_rust_agent_browser_profile_property_tracks_session_profile():
+ from browser_use.rust import Agent
+
+ class FirstProfile:
+ downloads_path = None
+
+ class SecondProfile:
+ downloads_path = '/tmp/changed-downloads'
+
+ class BrowserSession:
+ browser_profile = FirstProfile()
+
+ session = BrowserSession()
+ agent = Agent(task='Use the current browser profile.', browser_session=session)
+
+ assert agent.browser_profile is session.browser_profile
+
+ session.browser_profile = SecondProfile()
+
+ assert agent.browser_profile is session.browser_profile
+ assert agent.browser_profile.downloads_path == '/tmp/changed-downloads'
+
+
async def test_rust_agent_tracks_downloaded_files_and_saves_file_system_state(tmp_path):
from browser_use.rust import Agent