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

# Using Morph with browser-use

> Use morph-computer-use-v0 with browser-use Python SDK for 10x cheaper browser automation

<Warning>
  **Beta Feature** — Browser automation is currently in beta. Please report any issues to [founders@morphllm.com](mailto:founders@morphllm.com).
</Warning>

Use Morph's optimized `morph-computer-use-v0` model with [browser-use](https://github.com/browser-use/browser-use) Python SDK to get **10x cheaper** browser automation with **faster inference**.

## Why Use This?

|                  | Morph + browser-use                      | Claude + browser-use                      |
| ---------------- | ---------------------------------------- | ----------------------------------------- |
| **Cost**         | $0.30 input / $1.50 output per 1M tokens | $3.00 input / $15.00 output per 1M tokens |
| **Speed**        | 280 tokens/sec                           | 60 tokens/sec                             |
| **Optimization** | Purpose-built for browser automation     | General-purpose reasoning                 |

**You get**: browser-use's Python interface + Morph's pricing + faster inference.

## Installation

```bash theme={null}
# Install browser-use
pip install browser-use

# Install browser dependencies
playwright install
```

## Quick Start

Morph is **OpenAI-compatible**, so you can use it directly with browser-use's `ChatOpenAI`:

```python theme={null}
from browser_use import Agent, ChatOpenAI
import asyncio
import os

# Point to Morph API (OpenAI-compatible endpoint)
llm = ChatOpenAI(
    model="morph-computer-use-v0",
    api_key="YOUR_API_KEY",
    base_url="https://api.morphllm.com/v1"
)

agent = Agent(
    task="Go to amazon.com, search for 'laptop', and give me the title of the first result",
    llm=llm
)

async def main():
    result = await agent.run(max_steps=10)
    print(result)

asyncio.run(main())
```

<Tip>
  Get your API key at [app.morphllm.com/settings/api-keys](https://app.morphllm.com/settings/api-keys)
</Tip>

## Real-World Examples

<AccordionGroup>
  <Accordion title="E-commerce Testing" icon="cart-shopping">
    Test product search and checkout flows:

    ```python theme={null}
    from browser_use import Agent, ChatOpenAI
    import asyncio
    import os

    llm = ChatOpenAI(
        model="morph-computer-use-v0",
        api_key="YOUR_API_KEY",
        base_url="https://api.morphllm.com/v1"
    )

    async def test_ecommerce():
        # Test search functionality
        agent = Agent(
            task=(
                "Go to amazon.com, search for 'wireless mouse', "
                "click on the first result, and tell me the price"
            ),
            llm=llm
        )
        
        result = await agent.run(max_steps=15)
        print(f"Result: {result}")
        
        # Test checkout flow
        checkout_agent = Agent(
            task=(
                "Go to mystore.com, add the first product to cart, "
                "go to checkout, and verify the cart total is displayed"
            ),
            llm=llm
        )
        
        checkout_result = await checkout_agent.run(max_steps=20)
        print(f"Checkout test: {checkout_result}")

    asyncio.run(test_ecommerce())
    ```

    **Use case**: Automated regression testing for e-commerce platforms
  </Accordion>

  <Accordion title="Form Submission Testing" icon="file-lines">
    Test complex forms and multi-step flows:

    ```python theme={null}
    from browser_use import Agent, ChatOpenAI
    import asyncio
    import os

    llm = ChatOpenAI(
        model="morph-computer-use-v0",
        api_key="YOUR_API_KEY",
        base_url="https://api.morphllm.com/v1"
    )

    async def test_form_submission():
        agent = Agent(
            task=(
                "Go to example.com/contact, fill in the form with: "
                "name='John Doe', email='john@example.com', "
                "message='Test message', then submit and verify success message appears"
            ),
            llm=llm
        )
        
        result = await agent.run(max_steps=12)
        
        if "success" in result.lower():
            print("✅ Form submission successful")
        else:
            print("❌ Form submission failed")
            print(result)

    asyncio.run(test_form_submission())
    ```

    **Use case**: Continuous testing of lead generation forms
  </Accordion>

  <Accordion title="Authentication Testing" icon="lock">
    Test login flows and authenticated sessions:

    ```python theme={null}
    from browser_use import Agent, ChatOpenAI
    import asyncio
    import os

    llm = ChatOpenAI(
        model="morph-computer-use-v0",
        api_key="YOUR_API_KEY",
        base_url="https://api.morphllm.com/v1"
    )

    async def test_login_flow():
        agent = Agent(
            task=(
                "Go to myapp.com/login, enter email 'test@example.com' "
                "and password 'TestPass123', click login, and verify "
                "the dashboard page loads with the welcome message"
            ),
            llm=llm
        )
        
        result = await agent.run(max_steps=10)
        print(f"Login test result: {result}")

    asyncio.run(test_login_flow())
    ```

    **Security note**: Use test accounts only. Never use real credentials in automated tests.
  </Accordion>

  <Accordion title="Data Extraction" icon="database">
    Extract structured data from web pages:

    ```python theme={null}
    from browser_use import Agent, ChatOpenAI
    import asyncio
    import json
    import os

    llm = ChatOpenAI(
        model="morph-computer-use-v0",
        api_key="YOUR_API_KEY",
        base_url="https://api.morphllm.com/v1"
    )

    async def extract_product_data():
        agent = Agent(
            task=(
                "Go to amazon.com/product/B08N5WRWNW, extract the product title, "
                "price, rating, and number of reviews. Return as JSON format."
            ),
            llm=llm
        )
        
        result = await agent.run(max_steps=8)
        
        # Parse the extracted data
        try:
            data = json.loads(result)
            print(f"Product: {data.get('title')}")
            print(f"Price: {data.get('price')}")
            print(f"Rating: {data.get('rating')}")
        except json.JSONDecodeError:
            print("Raw result:", result)

    asyncio.run(extract_product_data())
    ```

    **Use case**: Competitive pricing analysis, product monitoring
  </Accordion>
</AccordionGroup>

## Configuration

### Custom Browser Options

Control browser behavior with browser-use config:

```python theme={null}
from browser_use import Agent, Browser, BrowserConfig, ChatOpenAI
import os

llm = ChatOpenAI(
    model="morph-computer-use-v0",
    api_key="YOUR_API_KEY",
    base_url="https://api.morphllm.com/v1"
)

# Configure browser
browser = Browser(
    config=BrowserConfig(
        headless=True,              # Run in background
        disable_security=False,     # Keep security enabled
        extra_chromium_args=[
            '--window-size=1920,1080'
        ]
    )
)

agent = Agent(
    task="Navigate to example.com and take a screenshot",
    llm=llm,
    browser=browser
)

result = await agent.run()
```

### Error Handling

Handle failures gracefully:

```python theme={null}
from browser_use import Agent, ChatOpenAI
import asyncio
import os

llm = ChatOpenAI(
    model="morph-computer-use-v0",
    api_key="YOUR_API_KEY",
    base_url="https://api.morphllm.com/v1"
)

async def test_with_retry():
    max_retries = 3
    
    for attempt in range(max_retries):
        try:
            agent = Agent(
                task="Test the checkout flow at myapp.com",
                llm=llm
            )
            
            result = await agent.run(max_steps=15)
            
            if "success" in result.lower():
                print(f"✅ Test passed on attempt {attempt + 1}")
                return result
            else:
                print(f"⚠️ Test inconclusive on attempt {attempt + 1}")
                
        except Exception as e:
            print(f"❌ Attempt {attempt + 1} failed: {e}")
            
            if attempt == max_retries - 1:
                raise
            
            # Wait before retry
            await asyncio.sleep(2)

asyncio.run(test_with_retry())
```

## Advanced Usage

### Parallel Testing

Run multiple tests concurrently:

```python theme={null}
from browser_use import Agent, ChatOpenAI
import asyncio
import os

llm = ChatOpenAI(
    model="morph-computer-use-v0",
    api_key="YOUR_API_KEY",
    base_url="https://api.morphllm.com/v1"
)

async def run_test(test_name: str, task: str):
    agent = Agent(task=task, llm=llm)
    result = await agent.run(max_steps=10)
    return {"test": test_name, "result": result}

async def parallel_tests():
    tests = [
        ("Homepage", "Go to myapp.com and verify the hero section loads"),
        ("Pricing", "Go to myapp.com/pricing and count the pricing tiers"),
        ("Contact", "Go to myapp.com/contact and verify the form is present")
    ]
    
    # Run all tests in parallel
    results = await asyncio.gather(*[
        run_test(name, task) for name, task in tests
    ])
    
    for result in results:
        print(f"{result['test']}: {result['result']}")

asyncio.run(parallel_tests())
```

### Integration with Pytest

Create a test suite:

```python theme={null}
# test_browser_flows.py
import pytest
from browser_use import Agent, ChatOpenAI
import os

@pytest.fixture
def llm():
    return ChatOpenAI(
        model="morph-computer-use-v0",
        api_key="YOUR_API_KEY",
        base_url="https://api.morphllm.com/v1"
    )

@pytest.mark.asyncio
async def test_homepage_loads(llm):
    agent = Agent(
        task="Go to myapp.com and verify the page loads",
        llm=llm
    )
    result = await agent.run(max_steps=5)
    assert "loaded" in result.lower() or "success" in result.lower()

@pytest.mark.asyncio
async def test_search_functionality(llm):
    agent = Agent(
        task="Go to myapp.com, search for 'test', verify results appear",
        llm=llm
    )
    result = await agent.run(max_steps=10)
    assert "result" in result.lower()

# Run with: pytest test_browser_flows.py -v
```

## Comparison: Morph SDK vs browser-use

Choose the right tool for your use case:

| Feature           | Morph SDK (TypeScript)        | browser-use + Morph            |
| ----------------- | ----------------------------- | ------------------------------ |
| **Language**      | TypeScript/JavaScript         | Python                         |
| **Setup**         | `bun add @morphllm/morphsdk`  | `pip install browser-use`      |
| **Integration**   | Built for Morph               | OpenAI-compatible              |
| **Live Sessions** | ✅ Built-in                    | ❌ Not available                |
| **Recording**     | ✅ Video + rrweb + logs        | ❌ Not available                |
| **Async Tasks**   | ✅ `createTask()` with polling | ❌ Direct execution only        |
| **Best For**      | Node.js apps, dashboards      | Python scripts, data pipelines |

**Use Morph SDK if**: You're building in TypeScript and want live sessions, recordings, or async task tracking

**Use browser-use if**: You're in Python and want the browser-use agent interface

## Troubleshooting

<AccordionGroup>
  <Accordion title="Authentication errors" icon="key">
    **Error**: `401 Unauthorized` or `Invalid API key`

    **Fix**:

    1. Get your API key at [app.morphllm.com/settings/api-keys](https://app.morphllm.com/settings/api-keys)
    2. Set environment variable: `export MORPH_API_KEY=sk-your-key`
    3. Verify it's loaded: `print(os.environ.get('MORPH_API_KEY'))`

    ```python theme={null}
    import os

    # Verify API key is set
    if not os.environ.get('MORPH_API_KEY'):
        raise ValueError("MORPH_API_KEY not set in environment")
    ```
  </Accordion>

  <Accordion title="Browser crashes or timeouts" icon="browser">
    **Error**: Browser crashes, hangs, or times out

    **Fix**: Adjust browser config and max\_steps

    ```python theme={null}
    from browser_use import Agent, Browser, BrowserConfig

    browser = Browser(
        config=BrowserConfig(
            headless=True,
            disable_security=False,
            extra_chromium_args=[
                '--no-sandbox',            # For containers
                '--disable-dev-shm-usage', # Prevent memory issues
                '--disable-gpu'            # Stability
            ]
        )
    )

    agent = Agent(
        task="Your task here",
        llm=llm,
        browser=browser
    )

    # Increase max_steps for complex tasks
    result = await agent.run(max_steps=25)
    ```
  </Accordion>

  <Accordion title="Task doesn't complete" icon="circle-exclamation">
    **Error**: Agent gives up or can't complete the task

    **Fix**: Make task more specific and increase steps

    ```python theme={null}
    # ❌ Too vague
    task = "Test the app"

    # ✅ Specific and actionable
    task = (
        "Go to myapp.com, click the 'Sign Up' button, "
        "verify the registration form appears with email and password fields"
    )

    # Use enough steps for the complexity
    agent = Agent(task=task, llm=llm)
    result = await agent.run(max_steps=15)  # Adjust based on task
    ```
  </Accordion>

  <Accordion title="Playwright installation issues" icon="download">
    **Error**: `playwright._impl._errors.Error: Executable doesn't exist`

    **Fix**: Install Playwright browsers

    ```bash theme={null}
    # Install all browsers
    playwright install

    # Or install specific browser
    playwright install chromium

    # For CI/CD, install system dependencies
    playwright install-deps
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Morph SDK" icon="code" href="/sdk/components/browser">
    Use the TypeScript SDK for live sessions and recordings
  </Card>

  <Card title="API Reference" icon="book" href="/api-reference/browser">
    Direct API access for custom integrations
  </Card>

  <Card title="browser-use Docs" icon="github" href="https://github.com/browser-use/browser-use">
    Official browser-use documentation
  </Card>

  <Card title="Get API Key" icon="key" href="https://app.morphllm.com/settings/api-keys">
    Create your Morph API key
  </Card>
</CardGroup>
