Skip to content

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

Merge commit '90fa344b599d55c2984bd926161acfecbb681d8c' into feature/new-dom-extraction-layer

Gregor Žunič286b5ec801eb
diff --cc browser_use/agent/prompts.py
index 1c4e8ea9c,672e97e9d..6b9b0ae77
--- a/browser_use/agent/prompts.py
+++ b/browser_use/agent/prompts.py
@@@ -108,39 -108,9 +108,9 @@@ class AgentMessagePrompt
self.vision_detail_level = vision_detail_level
assert self.browser_state
- @observe_debug(ignore_input=True, ignore_output=True, name='_deduplicate_screenshots')
- def _deduplicate_screenshots(self, screenshots: list[str]) -> list[str]:
- """
- Remove consecutive duplicate screenshots, keeping only the most recent of each.
-
- Args:
- screenshots: List of base64-encoded screenshot strings in chronological order (oldest first)
-
- Returns:
- List of screenshots with consecutive duplicates removed, maintaining chronological order
- """
- if not screenshots:
- return []
-
- if len(screenshots) == 1:
- return screenshots
-
- # Keep track of unique screenshots by comparing each with the next one
- unique_screenshots = []
-
- for i in range(len(screenshots)):
- # Always keep the last screenshot
- if i == len(screenshots) - 1:
- unique_screenshots.append(screenshots[i])
- # Only keep screenshot if it's different from the next one
- elif screenshots[i] != screenshots[i + 1]:
- unique_screenshots.append(screenshots[i])
-
- return unique_screenshots
-
@observe_debug(ignore_input=True, ignore_output=True, name='_get_browser_state_description')
def _get_browser_state_description(self) -> str:
- elements_text = self.browser_state.element_tree.clickable_elements_to_string(include_attributes=self.include_attributes)
+ elements_text = self.browser_state.dom_state.llm_representation(include_attributes=self.include_attributes)
if len(elements_text) > self.max_clickable_elements_length:
elements_text = elements_text[: self.max_clickable_elements_length]
diff --cc browser_use/agent/service.py
index cc58916cb,3633d464e..c549bbeca
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@@ -1036,12 -1039,12 +1054,12 @@@ class Agent(Generic[Context, AgentStruc
self.logger.debug(f'🤖 Browser-Use Library Version {self.version} ({self.source})')
- def _log_step_context(self, current_page, browser_state_summary) -> None:
+ def _log_step_context(self, current_page: Page, browser_state_summary: BrowserStateSummary) -> None:
"""Log step context information"""
url_short = current_page.url[:50] + '...' if len(current_page.url) > 50 else current_page.url
- interactive_count = len(browser_state_summary.selector_map) if browser_state_summary else 0
+ interactive_count = len(browser_state_summary.dom_state.selector_map) if browser_state_summary else 0
self.logger.info(
- f'📍 Step {self.state.n_steps + 1}: Evaluating page with {interactive_count} interactive elements on: {url_short}'
+ f'📍 Step {self.state.n_steps}: Evaluating page with {interactive_count} interactive elements on: {url_short}'
)
def _log_next_action_summary(self, parsed: 'AgentOutput') -> None:
diff --cc browser_use/browser/views.py
index 9af5c894f,20ef0b92b..738777dc4
--- a/browser_use/browser/views.py
+++ b/browser_use/browser/views.py
@@@ -73,8 -75,27 +73,27 @@@ class BrowserStateHistory
url: str
title: str
tabs: list[TabInfo]
- interacted_element: list[DOMHistoryElement | None] | list[None]
+ interacted_element: list[DOMInteractedElement | None] | list[None]
- screenshot: str | None = None
+ screenshot_path: str | None = None
+
+ def get_screenshot(self) -> str | None:
+ """Load screenshot from disk and return as base64 string"""
+ if not self.screenshot_path:
+ return None
+
+ import base64
+ from pathlib import Path
+
+ path_obj = Path(self.screenshot_path)
+ if not path_obj.exists():
+ return None
+
+ try:
+ with open(path_obj, 'rb') as f:
+ screenshot_data = f.read()
+ return base64.b64encode(screenshot_data).decode('utf-8')
+ except Exception:
+ return None
def to_dict(self) -> dict[str, Any]:
data = {}