Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Adding before_step_func.
Carlos Andrés Planchón Prestes6b76eb6ffe48
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex ca356a829..2de032285 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -501,6 +501,7 @@ class Agent(Generic[Context]):async def run(self,max_steps: int = 100,+ before_step_func: Callable | None = None,after_step_func: Callable | None = None) -> AgentHistoryList:"""Execute the task with maximum number of steps"""@@ -528,6 +529,9 @@ class Agent(Generic[Context]):if self.state.stopped: # Allow stopping while pausedbreak+ if before_step_func is not None:+ await before_step_func(self)+await self.step()if after_step_func is not None: