Skip to content

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

Fix empty page

magmuelleraea1d79b5847
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.py
index 2b6d9688d..c8293d81e 100644
--- a/browser_use/agent/prompts.py
+++ b/browser_use/agent/prompts.py
@@ -171,16 +171,22 @@ class AgentMessagePrompt:
else:
step_info_description = ''
+ elements_text = self.state.element_tree.clickable_elements_to_string(
+ include_attributes=self.include_attributes
+ )
+ if elements_text != '':
+ extra = '... Cut off - use extract content or scroll to get more ...'
+ elements_text = f'{extra}\n{elements_text}\n{extra}'
+ else:
+ elements_text = 'empty page'
+
state_description = f"""
{step_info_description}
Current url: {self.state.url}
Available tabs:
{self.state.tabs}
Interactive elements from current page view:
-
-... Cut off - use extract content or scroll to get more ...
-{self.state.element_tree.clickable_elements_to_string(include_attributes=self.include_attributes)}
-... Cut off - use extract content or scroll to get more ...
+{elements_text}
"""
if self.result: