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
python
Copy
Ask AI
from anchorbrowser import Anchorbrowserimport osanchor_client = Anchorbrowser( api_key=os.getenv("ANCHOR_API_KEY"))session = anchor_client.sessions.create()cdp_url = session.cdp_urlprint("Session's CDP_URL for later use\n", cdp_url)
2
Initialize browser-use with Anchor browser
python
Copy
Ask AI
from browser_use import Agent, Controllerfrom browser_use.browser import BrowserProfile, BrowserSessionfrom browser_use.llm import ChatOpenAIimport os# Configure your LLM (example with OpenAI)llm = ChatOpenAI( model='gpt-4o', api_key=os.getenv('OPENAI_API_KEY'),)# Initialize browser session with Anchorprofile = BrowserProfile(keep_alive=True)browser_session = BrowserSession( headless=False, cdp_url=cdp_url, browser_profile=profile)# Create controller and agentcontroller = Controller()agent = Agent( task="Your task description here", llm=llm, enable_memory=False, use_vision=False, controller=controller, browser_session=browser_session,)# Run the agentresult = 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
Copy
Ask AI
<!-- Make sure to replace <session_id> with the actual session ID from the first step --><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>