All articles
AI Automation

I Gave an AI Agent a Browser and It Did My Work For Me — Browser Use Tutorial

Browser Use is a Python library that lets an AI agent control a real web browser. It clicks buttons, fills forms, extracts data — anything you'd do manually. Here's a hands-on tutorial with real automation examples that'll make your jaw drop.

·10 min
I Gave an AI Agent a Browser and It Did My Work For Me — Browser Use Tutorial

The Hook: 'I Gave an AI a Browser'

I've used web scraping tools before. BeautifulSoup, Puppeteer, Playwright — they all require you to write specific selectors, handle pagination manually, and pray that the website doesn't change its layout next week.

Browser Use is something entirely different. You don't write selectors. You don't write page-specific code. You write a sentence. "Go to LinkedIn, find the top 10 AI engineers in Berlin, and save their profile URLs to a CSV." And the AI agent opens Chrome, navigates LinkedIn, figures out how to interact with the interface, and does exactly that.

I tested this on a Monday morning instead of doing the task manually. It completed in 4 minutes while I made coffee. Let me show you exactly how to set this up.

What is Browser Use?

Browser Use is an open-source Python library that connects large language models (LLMs) to Playwright — a browser automation framework. While Playwright handles the low-level browser control (clicking, typing, navigating), the LLM provides the intelligence to understand web pages visually, decide what to click, and execute multi-step tasks.

The library extracts an "interactive elements map" from each page (buttons, inputs, links with their labels) and passes it to the LLM. The LLM then decides which element to interact with, what to type, where to navigate, and when the task is complete. It's a tight loop of observation → decision → action.

You can plug in any LLM: GPT-4o, Claude 3.5 Sonnet, Gemini, or local models. Better models = smarter decisions = more reliable automation. I've had the best results with Claude 3.5 Sonnet for complex, multi-step tasks.

Installation: Getting Ready in 5 Minutes

Installation: Getting Ready in 5 Minutes

First, make sure you have Python 3.11+ installed. Then create a virtual environment and install the dependencies:

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install browser-use
pip install browser-use

# Install Playwright browsers (only needed once)
playwright install chromium

Next, create a .env file for your API key:

ANTHROPIC_API_KEY=your-api-key-here
# OR for OpenAI:
# OPENAI_API_KEY=your-api-key-here

That's it. You're ready to write your first autonomous browser agent.

Your First Script: A Working Browser Agent

Create a file called agent.py and paste this:

import asyncio
from dotenv import load_dotenv
from langchain_anthropic import ChatAnthropic
from browser_use import Agent

load_dotenv()

async def main():
    agent = Agent(
        task="Go to Hacker News (news.ycombinator.com), find the top 5 stories about AI today, and return their titles and URLs.",
        llm=ChatAnthropic(model="claude-3-5-sonnet-20241022"),
    )
    result = await agent.run()
    print(result.final_result())

asyncio.run(main())

Run it with python agent.py. A browser window will open, you'll watch it navigate to Hacker News, scan the front page, identify AI-related stories, and print a structured list back to your terminal. You can grab popcorn — it's genuinely fascinating to watch.

Real Use Case: Automating a Multi-Step Form

Real Use Case: Automating a Multi-Step Form

The real power shows up with complex tasks. Here's a script that fills out a job application form with extracted data:

agent = Agent(
    task="""
    Go to https://example-jobs.com/apply.
    Fill in the application form with these details:
    - Name: Alex Johnson
    - Email: alex@example.com
    - Position: Senior Backend Engineer
    - Years of experience: 5
    - Cover letter: "I am excited about this opportunity..."
    Click Submit when done. Confirm the success message.
    """,
    llm=ChatAnthropic(model="claude-3-5-sonnet-20241022"),
)

The agent navigates to the page, identifies each form field by its label (not by CSS selector), types the correct values, and submits. It even handles dropdowns, checkboxes, and file uploads. I've used this pattern to automate repetitive data entry tasks that used to take 30 minutes daily.

Advanced: Persistent Sessions and Custom Actions

Browser Use supports persistent browser sessions, which means the agent can stay logged into websites between runs. This is critical for automating behind-login workflows:

from browser_use import Agent, Browser, BrowserConfig

browser = Browser(
    config=BrowserConfig(
        chrome_instance_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        # Uses your existing Chrome profile with saved cookies
    )
)

agent = Agent(
    task="Check my Gmail for unread emails from @company.com and summarize them.",
    llm=llm,
    browser=browser,
)

You can also define custom actions — Python functions that the agent can call as "tools." For example, a custom action that saves extracted data to your database. The agent decides when to call it based on the task context. This makes Browser Use extensible to almost any workflow you can imagine.

Limitations to Know Before You Deploy

Browser Use is powerful but not perfect. Here are the gotchas I've hit in production:

  • CAPTCHAs — Sites with aggressive bot detection will block or slow the agent. Using your own Chrome profile helps since you carry real cookies and browser fingerprints.
  • Flaky on highly dynamic UIs — Single-page apps that load content asynchronously can confuse the agent if elements take too long to appear.
  • Cost adds up on long tasks — Each page view consumes tokens. A 20-step task with a frontier model can cost $0.10–$0.50. Use cheaper models or local models for bulk work.
  • Non-deterministic — The same task can take different paths on different runs. Always build error handling and verification steps into your prompts.

For tasks that run once a day or on demand, these are manageable. For high-volume, production-grade automation, pair Browser Use with a retry mechanism and monitoring.

FAQ

Do I need a visible browser window?

By default, the browser is visible so you can watch it work. You can run it headless by setting headless=True in the BrowserConfig. Headless mode is faster but harder to debug when something goes wrong.

Can I use a free LLM with Browser Use?

Yes. You can connect Browser Use to a local Ollama model. Results vary by model capability — smaller models may struggle with complex multi-step tasks but work fine for simple navigation.

Is this legal? Can I scrape any website?

Browser Use is a tool; legality depends on what you do with it. Always check a website's Terms of Service and robots.txt before automating actions. Automating your own accounts and internal tools is generally fine.

What's the difference between Browser Use and Selenium?

Selenium requires you to write explicit code for every action (click this selector, type this text). Browser Use uses AI to understand the page and decide actions dynamically. It's far more flexible and requires much less code, but it's less deterministic.

Explore RuView on GitHub

Browse the Rust engine, ESP32 firmware and examples.

RuView GitHub