Available Hooks
Currently, Browser-Use provides the following hooks:| Hook | Description | When it’s called |
|---|---|---|
on_step_start | Executed at the beginning of each agent step | Before the agent processes the current state and decides on the next action |
on_step_end | Executed at the end of each agent step | After the agent has executed all the actions for the current step, before it starts the next step |
async callable function that accepts the agent instance as its only parameter.
Basic Example
Data Available in Hooks
When working with agent hooks, you have access to the entireAgent instance. Here are some useful data points you can access:
agent.tasklets you see what the main task is,agent.add_new_task(...)lets you queue up a new oneagent.toolsgive access to theTools()object andRegistry()containing the available actionsagent.tools.registry.execute_action('click', {'index': 123}, browser_session=agent.browser_session)
agent.sensitive_datacontains the sensitive data dict, which can be updated in-place to add/remove/modify itemsagent.settingscontains all the configuration options passed to theAgent(...)at init timeagent.llmgives direct access to the main LLM object (e.g.ChatOpenAI)agent.stategives access to lots of internal state, including agent thoughts, outputs, actions, etc.agent.historygives access to historical data from the agent’s execution:agent.history.model_thoughts(): Reasoning from Browser Use’s model.agent.history.model_outputs(): Raw outputs from the Browser Use’s model.agent.history.model_actions(): Actions taken by the agentagent.history.extracted_content(): Content extracted from web pagesagent.history.urls(): URLs visited by the agent
agent.browser_sessiongives direct access to theBrowserSessionand CDP interfaceagent.browser_session.agent_focus_target_id: Get the current target ID the agent is focused onagent.browser_session.get_or_create_cdp_session(): Get the current CDP session for browser interactionagent.browser_session.get_tabs(): Get all tabs currently openagent.browser_session.get_current_page_url(): Get the URL of the current active tabagent.browser_session.get_current_page_title(): Get the title of the current active tab
Tips for Using Hooks
- Avoid blocking operations: Since hooks run in the same execution thread as the agent, keep them efficient and avoid blocking operations.
- Use custom tools instead: hooks are fairly advanced, most things can be implemented with custom tools instead
- Increase step_timeout: If your hook is doing something that takes a long time, you can increase the
step_timeoutparameter in theAgent(...)constructor.