Skip to content

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

fix(agent): guard _inject_budget_warning against ZeroDivisionError

itxaiohanglovercce612838a73
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index fe325c74a..bfd8d494c 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1537,7 +1537,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
This gives the LLM advance notice to wrap up, save partial results, and call done
rather than exhausting all steps with nothing saved.
"""
- if step_info is None:
+ if step_info is None or step_info.max_steps <= 0:
return
steps_used = step_info.step_number + 1 # Convert 0-indexed to 1-indexed