Skip to main content

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:

BROWSERCLOUD_API_TOKEN=your-token-here
OPENAI_API_KEY=your-openai-key-here

2. Environment Setup

Initialize a Python virtual environment for project isolation:

uv venv --python 3.11
source .venv/bin/activate # On Windows: .venv\Scripts\activate

3. Dependency Installation

uv 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,
)
)