Skip to main content

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

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:
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:
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()

Cookbook (Python)

Python setup hooks example in the Intuned Cookbook

Cookbook (TypeScript)

TypeScript setup hooks example in the Intuned Cookbook

attempt_store (Python)

Store and retrieve data within an attempt