This guide is dedicated to running your own browser-use agent while connecting to an Anchor browser. To use the embedded browser use capability, refer to AI task completion
1

Step one - Create an Anchor browser session

import requests
import os

ANCHOR_API_KEY = "YOUR_ANCHOR_API_KEY"

browser_configuration = {
    "adblock_config": {"active": True},
    "captcha_config": {"active": False},
    "proxy_config": {
        "active": True,
        "type": "anchor_mobile",
        "country_code": "uk"
    },
    "headless": False
}

response = requests.post(
    "https://api.anchorbrowser.io/api/sessions",
    headers={
        "anchor-api-key": ANCHOR_API_KEY,
        "Content-Type": "application/json",
    },
    json=browser_configuration
)

session_data = response.json()
session_id = session_data["data"]["id"]
Returns:
{
  "data": {
    "id": "<string>",
    "cdp_url": "<string>",
    "live_view_url": "https://live.anchorbrowser.io?sessionId=<session_id>"
    // Use the live view URL to view the browser session in real-time
  }
}
2

Initialize browser-use with Anchor browser

from browser_use import Agent, Controller
from browser_use.browser import BrowserProfile, BrowserSession
from browser_use.llm import ChatOpenAI

# Configure your LLM (example with OpenAI)
llm = ChatOpenAI(
    model='gpt-4o',
    api_key=os.getenv('OPENAI_API_KEY'),
)

# Create CDP connection URL
cdp_url = f'wss://connect.anchorbrowser.io?sessionId={session_id}'

# Initialize browser session with Anchor
profile = BrowserProfile(keep_alive=True)
browser_session = BrowserSession(
    headless=False, 
    cdp_url=cdp_url, 
    browser_profile=profile
)

# Create controller and agent
controller = Controller()
agent = Agent(
    task="Your task description here",
    llm=llm,
    enable_memory=False,
    use_vision=False,
    controller=controller,
    browser_session=browser_session,
)

# Run the agent
result = await agent.run(max_steps=40)
3

Optional - Live view the browser

Use the live_view_url returned on the first step to view the browser session in real-time, or to embed it as a UI component
<iframe src="https://live.anchorbrowser.io?sessionId=<session_id>" sandbox="allow-same-origin allow-scripts" allow="clipboard-read; clipboard-write" style="border: 0px; display: block; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px;"></iframe>