How to install Browser Use
Quick answer
Install the
browser-use Python package using pip install browser-use. This package enables AI-driven browser automation and requires Python 3.8+ and Playwright with Chromium installed.PREREQUISITES
Python 3.8+pip install openai>=1.0OpenAI API key (free tier works)Playwright with Chromium installed (run 'playwright install chromium')
Setup
Install the browser-use package via pip and install Playwright's Chromium browser for automation.
pip install browser-use
python -m playwright install chromium output
Collecting browser-use Downloading browser_use-1.0.0-py3-none-any.whl (XX kB) Installing collected packages: browser-use Successfully installed browser-use-1.0.0 [Playwright] Chromium browser installed successfully.
Step by step
Use the browser_use.Agent class with an OpenAI-based LLM to automate browser tasks.
from browser_use import Agent
from langchain_openai import ChatOpenAI
import os
# Ensure OPENAI_API_KEY is set in environment
async def main():
agent = Agent(
task="Go to google.com and search for 'AI news'",
llm=ChatOpenAI(model="gpt-4o-mini")
)
result = await agent.run()
print(result)
import asyncio
asyncio.run(main()) output
AI news search results or summary printed here
Common variations
- Use different LLM models by changing
modelinChatOpenAI. - Run synchronously by wrapping async calls with
asyncio.run(). - Use other Playwright browsers by installing them with
playwright install firefoxorplaywright install webkit.
Troubleshooting
- If you see
playwright not installederrors, runpython -m playwright install chromium. - Ensure your
OPENAI_API_KEYenvironment variable is set correctly. - For permission errors on Linux/macOS, run with appropriate user permissions or use a virtual environment.
Key Takeaways
- Install
browser-usewith pip and Playwright Chromium for browser automation. - Use
AgentwithChatOpenAIto run AI-driven browser tasks asynchronously. - Set
OPENAI_API_KEYin your environment to authenticate API calls. - Run
playwright install chromiumto avoid missing browser errors. - Customize browser and model choices for different automation needs.