Skip to content

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

Msg if failed

Magnus Müllerc13075d42891
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 1f1bad082..558f05d1b 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1296,6 +1296,32 @@ class Agent(Generic[Context, AgentStructuredOutput]):
f'📍 Step {self.state.n_steps}: Ran {action_count} action{"" if action_count == 1 else "s"} in {step_duration:.2f}s: {status_str}'
)
+ def _log_final_outcome_messages(self) -> None:
+ """Log helpful messages to user based on agent run outcome"""
+ # Check if agent failed
+ is_successful = self.history.is_successful()
+
+ if is_successful is False:
+ # Get final result to check for specific failure reasons
+ final_result = self.history.final_result()
+ final_result_str = str(final_result).lower() if final_result else ''
+
+ # Check for captcha/cloudflare related failures
+ captcha_keywords = ['captcha', 'cloudflare', 'recaptcha', 'challenge', 'bot detection', 'access denied']
+ has_captcha_issue = any(keyword in final_result_str for keyword in captcha_keywords)
+
+ if has_captcha_issue:
+ # Suggest use_cloud=True for captcha/cloudflare issues
+ task_preview = self.task[:10] if len(self.task) > 10 else self.task
+ self.logger.info('')
+ self.logger.info(f'💡 Detected captcha/bot protection. For better browser fingerprinting, try:')
+ self.logger.info(f' agent = Agent(task="{task_preview}...", use_cloud=True)')
+
+ # General failure message
+ self.logger.info('')
+ self.logger.info('❌ Did the Agent fail your expectation? Let us fix this!')
+ self.logger.info(' Please open a short issue here: https://github.com/browser-use/browser-use/issues')
+
def _log_agent_event(self, max_steps: int, agent_run_error: str | None = None) -> None:
"""Sent the agent event for this run to telemetry"""
@@ -1746,6 +1772,9 @@ class Agent(Generic[Context, AgentStructuredOutput]):
output_event = await CreateAgentOutputFileEvent.from_agent_and_file(self, output_path)
self.eventbus.dispatch(output_event)
+ # Log final messages to user based on outcome
+ self._log_final_outcome_messages()
+
# Stop the event bus gracefully, waiting for all events to be processed
# Use longer timeout to avoid deadlocks in tests with multiple agents
await self.eventbus.stop(timeout=3.0)