Enhance AI Applications with Browser Use Integration
Browser Use is a sophisticated Python framework that enables AI agents to interact with web browsers autonomously. By combining BrowserCloud's infrastructure with Browser Use, you can equip your AI applications with advanced web automation capabilities while eliminating the complexity of browser management.
Requirements
- Python 3.11 or newer version
- Valid BrowserCloud API Token (obtain from your account dashboard)
Step-by-Step Setup
1. Configure API Credentials
Navigate to your BrowserCloud Account Dashboard to retrieve your API token.
Configure the BROWSERCLOUD_API_TOKEN
environment variable:
- .env file
- terminal
BROWSERCLOUD_API_TOKEN=your-token-here
OPENAI_API_KEY=your-openai-key-here
export BROWSERCLOUD_API_TOKEN=your-token-here
export OPENAI_API_KEY=your-openai-key-here
2. Environment Setup
Initialize a Python virtual environment for project isolation:
- uv (recommended)
- venv
- conda
uv venv --python 3.11
source .venv/bin/activate # On Windows: .venv\Scripts\activate
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
conda create -n browser-use-env python=3.11
conda activate browser-use-env
3. Dependency Installation
- uv (recommended)
- pip
- Poetry
uv add browser-use python-dotenv
pip install browser-use python-dotenv
poetry add browser-use python-dotenv
4. Implementation
from browser_use import Agent, BrowserSession
from browser_use.llm import ChatOpenAI
from dotenv import load_dotenv
import os
import asyncio
load_dotenv()
async def main():
# Get the token from environment variables
browsercloud_token = os.getenv('BROWSERCLOUD_API_TOKEN')
if not browsercloud_token:
raise ValueError("BROWSERCLOUD_API_TOKEN environment variable is required")
browser_session = BrowserSession(cdp_url=f"wss://chrome-v2.browsercloud.io?token={browsercloud_token}")
llm = ChatOpenAI(model="gpt-4o")
agent = Agent(
task="find me the top cheapest trainer on ebay.co.uk",
llm=llm,
browser_session=browser_session
)
result = await agent.run()
print(result)
if __name__ == "__main__":
asyncio.run(main())
5. Execution
Run your application:
python main.py
Advanced Configuration Options
Proxy Integration
browser_session = BrowserSession(cdp_url=f"wss://chrome-v2.browsercloud.io?token={os.environ['BROWSERCLOUD_API_TOKEN']}&proxy=residential")
Browser Customization
Tailor browser behavior through configuration parameters:
from browser_use import BrowserSession
from browser_use.browser import BrowserProfile
browser_session = BrowserSession(
cdp_url=f"wss://chrome-v2.browsercloud.io?token={os.environ['BROWSERCLOUD_API_TOKEN']}",
browser_profile=BrowserProfile(
user_agent="Custom User Agent",
viewport_size={"width": 1920, "height": 1080},
headless=True,
)
)