Selenium and Playwright scripts break when a site changes its layout, and they take hours to write. browser-use/browser-use takes another route: you give an agent a task in plain words and an LLM, and it drives a real browser until it has an answer.
This post covers the Python library path from the README, the one you can run locally with your own model key.
Install
With uv installed, start a project if you need one, then add the library (Python 3.11 or newer; the README uses 3.12):
uv init --python 3.12 uv add browser-use Add your key
Put your OpenAI key in .env. The README also lists an optional Browser Use key for its own BU2 model or the cloud browser.
# .env OPENAI_API_KEY=your-key # BROWSER_USE_API_KEY=your-key # Optional: BU2 model or cloud browser Write agent.py
Create an Agent with a task and an LLM, run it, and print the final result. The README imports Agent, Browser, ChatBrowserUse and ChatOpenAI from browser_use. A minimal version:
import asyncio from browser_use import Agent, ChatOpenAI from dotenv import load_dotenv load_dotenv() async def main(): agent = Agent( task="Find the current price of the first result for 'mechanical keyboard' on example-shop.com", llm=ChatOpenAI(model="gpt-4.1"), ) history = await agent.run() print(history.final_result()) asyncio.run(main()) Check the README for the current model names and constructor arguments, since they move quickly. Run it with:
uv run agent.py If you have a Browser Use key, the README suggests swapping in ChatBrowserUse with the bu-2-0 model, which is tuned for browser automation.
Letting Claude Code or Codex do it
There is also a CLI path. The README says to paste a prompt into Claude Code, Codex or another agent asking it to install or upgrade browser-use with uv on Python 3.12, run browser-use skill install, and connect to your browser. If setup fails it points to the browser-harness install guide.
Tips
- Name the exact site and the exact output you want. Vague tasks wander.
- Save the result to a file, for example
result.json, so a run is reusable. - Start with one low-stakes task and watch the step count before you scale up.
- Respect each site's terms and never automate logins you do not own.
Caveats
- You pay your model provider for each step the agent takes.
- Agents click real pages, so keep them away from anything destructive.
- This walkthrough follows the README and we have not run it end to end.
The step-by-step version is on our use-case page: automate a web task with a Python browser agent. For alternatives, see the best AI repos for browser automation.
Want the setup commands for 50 AI repos people actually ship with? Get the free AI Repos That Actually Ship pack: https://dedupedai.com/ship-pack/?utm_source=devto&utm_medium=article&utm_campaign=shippack
Get one email every Monday with the week's hottest AI repos and exactly how to use them: subscribe free at dedupedai.com