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

# Browser Examples

> Examples for browser automation with Playwright CDP.

## Basic Browser Agent

Navigate and extract information from web pages.

```python theme={null}
import asyncio
from definable.agent import Agent
from definable.browser import BrowserToolkit, BrowserConfig

async def main():
    config = BrowserConfig(headless=False)
    async with BrowserToolkit(config=config) as toolkit:
        agent = Agent(
            model="gpt-4o",
            toolkits=[toolkit],
            instructions="Use browser_snapshot before interacting with any page.",
        )
        result = await agent.arun("Go to news.ycombinator.com and list the top 3 stories")
        print(result.content)

asyncio.run(main())
```

```bash theme={null}
pip install 'definable[browser]'
playwright install chromium
```

## Connect to Existing Browser

Attach to an already-running Chrome instance:

```bash theme={null}
# Launch Chrome with remote debugging
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --remote-debugging-port=9222 --no-first-run
```

```python theme={null}
config = BrowserConfig(cdp_url="http://127.0.0.1:9222")
async with BrowserToolkit(config=config) as toolkit:
    agent = Agent(model="gpt-4o", toolkits=[toolkit])
    result = await agent.arun("What page am I on?")
```

## Persistent Profile

Keep cookies and login state across runs:

```python theme={null}
config = BrowserConfig(user_data_dir="/tmp/my-browser-profile")
```

## Form Filling

```python theme={null}
result = await agent.arun("""
    Go to https://example.com/signup
    Fill in the email field with "test@example.com"
    Fill in the password field with "secure123"
    Click the submit button
""")
```

## Combined with MCP

```python theme={null}
from definable.mcp import MCPToolkit, MCPConfig

async with BrowserToolkit(config=config) as browser:
    async with MCPToolkit(config=MCPConfig(...)) as mcp:
        agent = Agent(
            model="gpt-4o",
            toolkits=[browser, mcp],
        )
```
