Browser Use key features
Quick answer
The
browser-use Python package enables AI-driven browser automation with key features like task-based agents, integration with langchain_openai.ChatOpenAI, and async execution. It supports running complex browsing tasks programmatically using modern AI models such as gpt-4o.PREREQUISITES
Python 3.8+OpenAI API key (free tier works)pip install openai>=1.0pip install browser-usePlaywright with Chromium installed (playwright install chromium)
Setup
Install the browser-use package and its dependencies, including openai and playwright. Ensure you have a valid OpenAI API key set in your environment variables. Install Chromium browser for Playwright to automate.
pip install openai browser-use
playwright install chromium output
Requirement already satisfied: openai in ... Requirement already satisfied: browser-use in ... [Playwright] Chromium is installed successfully.
Step by step
Use browser-use.Agent with a task description and an LLM instance from langchain_openai.ChatOpenAI. Run the agent asynchronously to perform browser automation tasks.
import asyncio
from browser_use import Agent
from langchain_openai import ChatOpenAI
import os
async def main():
agent = Agent(
task="Go to google.com and search for 'AI news'",
llm=ChatOpenAI(model="gpt-4o", openai_api_key=os.environ["OPENAI_API_KEY"])
)
result = await agent.run()
print("Agent output:", result)
if __name__ == "__main__":
asyncio.run(main()) output
Agent output: [Agent's summarized browsing result or search snippets]
Common variations
- Use different models like
gpt-4o-minifor faster, cheaper runs. - Run multiple browsing tasks concurrently with asyncio.
- Integrate with LangChain or other LLM frameworks by passing compatible LLM instances.
import asyncio
from browser_use import Agent
from langchain_openai import ChatOpenAI
import os
async def run_multiple_tasks():
tasks = [
Agent(task="Search latest AI trends", llm=ChatOpenAI(model="gpt-4o-mini", openai_api_key=os.environ["OPENAI_API_KEY"])),
Agent(task="Check weather in NYC", llm=ChatOpenAI(model="gpt-4o-mini", openai_api_key=os.environ["OPENAI_API_KEY"]))
]
results = await asyncio.gather(*(agent.run() for agent in tasks))
for i, res in enumerate(results, 1):
print(f"Result {i}:", res)
if __name__ == "__main__":
asyncio.run(run_multiple_tasks()) output
Result 1: [Summary of AI trends search] Result 2: [Weather info for NYC]
Troubleshooting
- If you see
playwright not installederrors, runplaywright install chromium. - Ensure your
OPENAI_API_KEYenvironment variable is set correctly. - For async runtime errors, verify you are running inside an
asyncioevent loop.
Key Takeaways
- Use
browser-use.Agentwith asyncrun()for AI-driven browser automation. - Integrate with
langchain_openai.ChatOpenAIfor flexible LLM model selection. - Install Playwright and Chromium to enable browser control.
- Support for concurrent tasks via asyncio enhances automation throughput.