Skip to content

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

Error trace only in debug mode

magmuellere994da11c1e8
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 738498f05..d1bdf124e 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -161,7 +161,8 @@ class Agent:
def _handle_step_error(self, error: Exception) -> list[ActionResult]:
"""Handle all types of errors that can occur during a step"""
- error_msg = AgentError.format_error(error, include_trace=True)
+ include_trace = logger.isEnabledFor(logging.DEBUG)
+ error_msg = AgentError.format_error(error, include_trace=include_trace)
prefix = f'❌ Result failed {self.consecutive_failures + 1}/{self.max_failures} times:\n '
if isinstance(error, (ValidationError, ValueError)):
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index 1d29f42f0..dd64c13a9 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -250,4 +250,6 @@ class AgentError:
return f'{AgentError.VALIDATION_ERROR}\nDetails: {str(error)}'
if isinstance(error, RateLimitError):
return AgentError.RATE_LIMIT_ERROR
- return f'Unexpected error: {str(error)}\nStacktrace:\n{traceback.format_exc()}'
+ if include_trace:
+ return f'{str(error)}\nStacktrace:\n{traceback.format_exc()}'
+ return f'{str(error)}'