Skip to content

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

Improve logging

Magnus Müller2045ad747c21
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 073347665..1d87a5eaa 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -840,8 +840,9 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self.state.consecutive_failures = 0
- except InterruptedError:
+ except InterruptedError as e:
# self.logger.debug('Agent paused')
+ self.logger.debug(f'InterruptedError: {type(e).__name__}: {e}')
self.state.last_result = [
ActionResult(
error='The agent was paused mid-step - the last action might need to be repeated',
@@ -849,9 +850,10 @@ class Agent(Generic[Context, AgentStructuredOutput]):
)
]
return
- except asyncio.CancelledError:
+ except asyncio.CancelledError as e:
# Directly handle the case where the step is cancelled at a higher level
# self.logger.debug('Task cancelled - agent was paused with Ctrl+C')
+ self.logger.debug(f'asyncio.CancelledError: {type(e).__name__}: {e}')
self.state.last_result = [ActionResult(error='The agent was paused with Ctrl+C', include_in_memory=True)]
raise InterruptedError('Step cancelled by user')
except Exception as e:
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index 802fdc340..75404fd81 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -364,10 +364,11 @@ Set extract_links=True ONLY if your query requires extracting links/URLs from th
markdownify_func = partial(markdownify.markdownify, strip=strip)
- content = await asyncio.wait_for(
- loop.run_in_executor(None, markdownify_func, page_html),
- timeout=10.0, # 10 second timeout for main page markdownify
- )
+ try:
+ content = await asyncio.wait_for(loop.run_in_executor(None, markdownify_func, page_html), timeout=10.0)
+ except Exception as e:
+ logger.warning(f'Main page markdownify failed: {type(e).__name__}: {e}')
+ return ActionResult(error=f'Could not convert html to markdown: {type(e).__name__}: {e}')
# manually append iframe text into the content so it's readable by the LLM (includes cross-origin iframes)
for iframe in page.frames: