Skip to content

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

Increase consecutive_failures if action error

Magnus Müller5a908851d5ae
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index becaeca4a..144cb804d 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -798,6 +798,12 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Check for new downloads after executing actions
await self._check_and_update_downloads('after executing actions')
+ # check for action errors
+ if self.state.last_result and self.state.last_result[-1].error:
+ self.state.consecutive_failures += 1
+ self.logger.debug(f'🔄 Step {self.state.n_steps}: Consecutive failures: {self.state.consecutive_failures}')
+ return
+
self.state.consecutive_failures = 0
self.logger.debug(f'🔄 Step {self.state.n_steps}: Consecutive failures reset to: {self.state.consecutive_failures}')