Skip to content

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

Request screenshot

Magnus Müller461bce7b2297
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index d64108e12..2d922a125 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -305,11 +305,25 @@ class MessageManager:
self.sensitive_data = effective_sensitive_data
self.sensitive_data_description = self._get_sensitive_data_description(browser_state_summary.url)
- # Use only the current screenshot
+ # Use only the current screenshot, but check if action results request screenshot inclusion
screenshots = []
- if browser_state_summary.screenshot:
+ include_screenshot_requested = False
+
+ # Check if any action results request screenshot inclusion
+ if result:
+ for action_result in result:
+ if action_result.metadata and action_result.metadata.get('include_screenshot'):
+ include_screenshot_requested = True
+ logger.debug('Screenshot inclusion requested by action result')
+ break
+
+ # Include screenshot if either use_vision is True, or if explicitly requested by an action
+ if (use_vision or include_screenshot_requested) and browser_state_summary.screenshot:
screenshots.append(browser_state_summary.screenshot)
+ # Override use_vision if screenshot was explicitly requested
+ effective_use_vision = use_vision or include_screenshot_requested
+
# Create single state message with all content
assert browser_state_summary
state_message = AgentMessagePrompt(
@@ -327,7 +341,7 @@ class MessageManager:
vision_detail_level=self.vision_detail_level,
include_recent_events=self.include_recent_events,
sample_images=self.sample_images,
- ).get_user_message(use_vision)
+ ).get_user_message(effective_use_vision)
# Set the state message with caching enabled
self._set_message_with_type(state_message, 'state')
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 868aacf5b..d41d7823b 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -844,6 +844,21 @@ Note: For multiple pages (>=1.0), scrolls are performed one page at a time to en
long_term_memory=f"Tried scrolling to text '{text}' but it was not found",
)
+ @self.registry.action(
+ 'Request to include a screenshot in your next browser state. Use this when you need visual confirmation or when the page contains complex visual information that is hard to understand from the DOM alone.'
+ )
+ async def take_screenshot():
+ """Request that a screenshot be included in the next observation"""
+ memory = 'Requested screenshot for next observation'
+ msg = f'📸 {memory}'
+ logger.info(msg)
+
+ # Return flag in metadata to signal that screenshot should be included
+ return ActionResult(
+ extracted_content=memory,
+ metadata={'include_screenshot': True},
+ )
+
# Dropdown Actions
@self.registry.action(