> ## Documentation Index
> Fetch the complete documentation index at: https://intunedhq.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up hooks

## Recipe

This recipe shows how to initialize a shared browser session in a hook and reuse it across automation steps using `attempt_store`.

## Project structure

```plaintext theme={null}
api/
  └── automation.py
hooks/
  └── setup_context.py
```

## Setup

### hooks/setup\_context.py

Connect to Intuned's browser via CDP and store the instance for later steps:

```python theme={null}
import os
from intuned_runtime import attempt_store


async def setup_context(*, api_name: str, api_parameters: str, cdp_url: str):
    os.environ["BROWSER_USE_CONFIG_DIR"] = "/tmp/browseruse-config"
    from browser_use import Browser

    browser = Browser(cdp_url=cdp_url)
    attempt_store.set("browser", browser)
```

## Use the browser in your automation

Retrieve the stored browser instance and pass it to a Browser Use agent:

```python theme={null}
from playwright.async_api import Page
from browser_use import Agent, ChatOpenAI, Browser
from intuned_runtime import attempt_store


async def automation(page: Page, params=None, **_kwargs):
    browser: Browser = attempt_store.get("browser")

    agent = Agent(
        browser=browser,
        task="Your automation task here",
        llm=ChatOpenAI(model="gpt-5.4-mini"),
    )
    await agent.run()
```

## Related links

> [card] [Cookbook (Python)](https://github.com/Intuned/cookbook/tree/main/python-examples/setup-hooks)
>
> Python setup hooks example in the Intuned Cookbook

> [card] [Cookbook (TypeScript)](https://github.com/Intuned/cookbook/tree/main/typescript-examples/setup-hooks)
>
> TypeScript setup hooks example in the Intuned Cookbook

> [card] [attempt\_store (Python)](https://intunedhq.com/docs/main/05-references/runtime-sdk-python/attempt-store.md)
>
> Store and retrieve data within an attempt


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.