Skip to content

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

fix(BrowserError): drop trailing 'during: None' when no event is attached

Larsen Cundric49fb16b69305
diff --git a/browser_use/browser/views.py b/browser_use/browser/views.py
index 43ff2a74b..74830c29c 100644
--- a/browser_use/browser/views.py
+++ b/browser_use/browser/views.py
@@ -188,12 +188,12 @@ class BrowserError(Exception):
super().__init__(message)
def __str__(self) -> str:
+ parts = [self.message]
if self.details:
- return f'{self.message} ({self.details}) during: {self.while_handling_event}'
- elif self.while_handling_event:
- return f'{self.message} (while handling: {self.while_handling_event})'
- else:
- return self.message
+ parts.append(f'({self.details})')
+ if self.while_handling_event:
+ parts.append(f'during: {self.while_handling_event}')
+ return ' '.join(parts)
class URLNotAllowedError(BrowserError):