Skip to content

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

fix: preserve partial action results when mid-batch action fails

Tonybca433ccb28e
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 91b7fda3f..09ada94dc 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -2807,15 +2807,17 @@ class Agent(Generic[Context, AgentStructuredOutput]):
self.logger.info(f'Page changed after "{action_name}" — skipping {total_actions - i - 1} remaining action(s)')
break
- except Exception as e:
- # Handle any exceptions during action execution
- self.logger.error(f'❌ Executing action {i + 1} failed -> {type(e).__name__}: {e}')
- await self._demo_mode_log(
- f'Action "{action_name}" raised {type(e).__name__}: {e}',
- 'error',
- {'action': action_name, 'step': self.state.n_steps},
- )
- raise e
+ except Exception as e:
+ # Handle any exceptions during action execution
+ self.logger.error(f'❌ Executing action {i + 1} failed -> {type(e).__name__}: {e}')
+ await self._demo_mode_log(
+ f'Action "{action_name}" raised {type(e).__name__}: {e}',
+ 'error',
+ {'action': action_name, 'step': self.state.n_steps},
+ )
+ # Preserve partial results so the agent knows which actions succeeded before the failure
+ results.append(ActionResult(error=str(e)))
+ return results
return results