Skip to main content

What is Browser Use?

Browser Use is an open-source framework for building and managing autonomous agents that can interact with the web. By integrating Browser Cash’s stealth browsers with Browser Use, you can create powerful agents that can perform complex web tasks while avoiding detection.

Setting up the integration

1. Create environment with uv (Python>=3.11):
uv init
2. Install the Browser-Use package and requests:
uv add browser-use requests
uv sync
3. Get an API key from Browser Use Cloud and add it to your .env file, along with your Browser Cash API key:
# .env
BROWSER_USE_API_KEY=your-key
BROWSER_CASH_API_KEY=your-key
5. Run your Browser Use agent, powered by Browser Cash:
# main.py
import os
import asyncio
import requests
from browser_use import Agent, Browser, ChatBrowserUse


async def example():
    # 1) Create a Browser Cash session and get its CDP URL
    resp = requests.post(
        "https://api.browser.cash/v1/browser/session",
        headers={
            "Authorization": f"Bearer {os.getenv('BROWSER_CASH_API_KEY')}",
            "content-type": "application/json",
        },
        json={},
    )
    resp.raise_for_status()
    cdp_url = resp.json()["cdpUrl"]

    # 2) Create a Browser Use Browser object with the Browser Cash browser URL
    browser = Browser(cdp_url=cdp_url)
    llm = ChatBrowserUse()

    # 3) Create and run an agent with the browser
    agent = Agent(
        task="Find the number of stars of the browser-use repo",
        llm=llm,
        browser=browser,
    )

    history = await agent.run()

    # 4) Stop the Browser Cash session
    requests.delete(
        "https://api.browser.cash/v1/browser/session",
        headers={
            "Authorization": f"Bearer {os.getenv('BROWSER_CASH_API_KEY')}",
        },
        params={"sessionId": resp.json()["sessionId"]},
    )

    # 5) Return the agent's history
    return history


if __name__ == "__main__":
    history = asyncio.run(example())
uv run main.py
Congratulations! You have successfully integrated Browser Cash with Browser Use. You can combine the power of Browser Cash’s stealth browsers with Browser Use’s agent framework to build powerful web automations, even on the most challenging websites.