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
Add Rust agent screenshot service parity
Magnus Müller8c67a3ef13d6
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex fec7809ed..517644eba 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -431,10 +431,15 @@ Terminal core branch: `magnus/browser-use-rust-integration` at terminal main `ee- Single-step Rust results now synchronize into `agent.state.last_result`, so Browser Use callers can inspect the last action result after `step(...)`, `take_step(...)`, `run(...)`, or `follow_up(...)`.- Proof: `test_rust_agent_step_runs_single_terminal_turn_and_updates_state`.+85. Rust Agent screenshot service parity+ - The Rust-backed `Agent` now initializes Browser Use's `ScreenshotService` under the agent directory during construction.+ - Callers can use `agent.screenshot_service.store_screenshot(...)` and `get_screenshot(...)` with the same storage layout as the Python Agent.+ - Proof: `test_rust_agent_initializes_screenshot_service`.+## 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` (58 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (59 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 dcd661d30..795d06079 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -35,6 +35,7 @@ from browser_use.browser import BrowserProfile, BrowserSessionfrom browser_use.browser.profile import CHROME_DETERMINISTIC_RENDERING_ARGS, CHROME_DISABLE_SECURITY_ARGS, CHROME_DOCKER_ARGSfrom browser_use.browser.views import BrowserStateHistory, TabInfofrom browser_use.filesystem.file_system import FileSystem+from browser_use.screenshots.service import ScreenshotServicefrom browser_use.telemetry.service import ProductTelemetryfrom browser_use.tokens.service import TokenCostfrom browser_use.tokens.views import ModelUsageStats, UsageSummary@@ -1122,6 +1123,7 @@ class Agent(Generic[AgentStructuredOutput]):timestamp = int(time.time())self.agent_directory = Path(tempfile.gettempdir()) / f'browser_use_agent_{self.id}_{timestamp}'self.file_system, self.file_system_path = _init_file_system(self.state, self.agent_directory, file_system_path)+ self.screenshot_service = ScreenshotService(self.agent_directory)self.settings = AgentSettings(use_vision=use_vision,vision_detail_level=vision_detail_level,diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex ad084b38d..a775d314c 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -916,6 +916,27 @@ async def test_rust_agent_tracks_downloaded_files_and_saves_file_system_state(tmassert agent.state.file_system_state.base_dir == str(tmp_path / 'agent-files')+async def test_rust_agent_initializes_screenshot_service(tmp_path):+ import base64++ from browser_use.rust import Agent+ from browser_use.screenshots.service import ScreenshotService++ agent = Agent(task='Capture a screenshot.', file_system_path=str(tmp_path / 'agent-files'))++ assert isinstance(agent.screenshot_service, ScreenshotService)+ assert agent.screenshot_service.agent_directory == agent.agent_directory+ assert agent.screenshot_service.screenshots_dir == agent.agent_directory / 'screenshots'+ assert agent.screenshot_service.screenshots_dir.exists()++ screenshot_b64 = base64.b64encode(b'png-bytes').decode('utf-8')+ screenshot_path = await agent.screenshot_service.store_screenshot(screenshot_b64, step_number=3)++ assert Path(screenshot_path).name == 'step_3.png'+ assert Path(screenshot_path).read_bytes() == b'png-bytes'+ assert await agent.screenshot_service.get_screenshot(screenshot_path) == screenshot_b64++def test_rust_agent_adds_available_files_to_task_context():from browser_use.rust import Agent