> ## 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-4o-mini"),
    )
    await agent.run()
```

## Related links

<CardGroup cols={2}>
  <Card title="Cookbook (Python)" icon="github" href="https://github.com/Intuned/cookbook/tree/main/python-examples/setup-hooks">
    Python setup hooks example in the Intuned Cookbook
  </Card>

  <Card title="Cookbook (TypeScript)" icon="github" href="https://github.com/Intuned/cookbook/tree/main/typescript-examples/setup-hooks">
    TypeScript setup hooks example in the Intuned Cookbook
  </Card>

  <Card title="attempt_store (Python)" icon="python" href="/main/05-references/runtime-sdk-python/attempt-store">
    Store and retrieve data within an attempt
  </Card>
</CardGroup>
