Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
more docs updating
Nick Sweeting4f39806a19d9
diff --git a/docs/customize/agent-settings.mdx b/docs/customize/agent-settings.mdxindex b17ca6613..cbfc4e4f7 100644--- a/docs/customize/agent-settings.mdx+++ b/docs/customize/agent-settings.mdx@@ -88,6 +88,12 @@ await browser.close()### Reuse Existing Browser Context+You can pass any of the following Playwright objects to the Agent: `page`, `browser_context`, `browser`, `browser_session`, or `browser_profile`. These all get passed down to create a `BrowserSession`:++```python+browser_session = browser_session or BrowserSession(page, browser_context, browser_profile)+```+`browser_context`: A Playwright browser context. Useful for maintaining persistent sessions. See <a href="/customize/persistent-browser">Persistent Browser</a> for more details.```pythondiff --git a/docs/customize/real-browser.mdx b/docs/customize/real-browser.mdxindex 1f7dc2de0..3234003e2 100644--- a/docs/customize/real-browser.mdx+++ b/docs/customize/real-browser.mdx@@ -10,16 +10,55 @@ You can connect the agent to your real Chrome browser instance, allowing it to a## Connection Methods-There are several ways to connect to your existing browser:+Browser-use attempts connections in the following order:-### Method 1: Connect to Running Browser by PID+### Method A: Accept Playwright/Patchright Client-If you have Chrome running with remote debugging enabled, you can connect directly using its process ID:+Pass a Playwright or Patchright client object:++```python+from browser_use import Agent, BrowserSession+from playwright.async_api import async_playwright+# or from patchright.async_api import async_patchright++async with async_playwright() as playwright:+ session = BrowserSession(playwright=playwright)+ await session.start()++ agent = Agent(+ task="Your task here",+ llm=llm,+ browser=session,+ )+```++### Method B: Accept Playwright Objects++Pass existing page, browser_context, and/or browser Playwright objects:++```python+from browser_use import Agent+from playwright.async_api import async_playwright++async with async_playwright() as p:+ browser = await p.chromium.launch()+ context = await browser.new_context()+ page = await context.new_page()++ # Can pass any of: page, browser_context, browser+ agent = Agent(+ task="Your task here",+ llm=llm,+ page=page, # or browser_context=context, or browser=browser+ )+```++### Method C: Connect by Browser PID++Connect to a browser with open `--remote-debugging-port`:```pythonfrom browser_use import Agent, BrowserSession-from langchain_openai import ChatOpenAI-import asyncio# First, start Chrome with remote debugging:# /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --remote-debugging-port=9242@@ -30,70 +69,35 @@ await session.start()agent = Agent(task="Your task here",- llm=ChatOpenAI(model='gpt-4o'),+ llm=llm,browser=session,)--async def main():- await agent.run()- # Browser stays open since we connected to existing instance--if __name__ == '__main__':- asyncio.run(main())```-### Method 2: Launch with Custom Chrome Executable+### Method D: Connect via WebSocket URL-To launch a new Chrome instance using your default profile:+Connect to Playwright Node.js server providers:```python-from browser_use import Agent, BrowserSession, BrowserProfile-from langchain_openai import ChatOpenAI-import asyncio--# Configure to use your Chrome installation-profile = BrowserProfile(- # Path to your Chrome executable- executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', # macOS- # For Windows: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'- # For Linux: '/usr/bin/google-chrome'-- # Use your default Chrome profile- user_data_dir='~/Library/Application Support/Google/Chrome', # macOS- # For Windows: '~/AppData/Local/Google/Chrome/User Data'- # For Linux: '~/.config/google-chrome'-- profile_directory='Default', # or 'Profile 1', 'Profile 2', etc.- headless=False-)+from browser_use import Agent, BrowserSession-session = BrowserSession(browser_profile=profile)+# Connect to a playwright server+session = BrowserSession(wss_url="wss://your-playwright-server.com/ws")await session.start()agent = Agent(task="Your task here",- llm=ChatOpenAI(model='gpt-4o'),+ llm=llm,browser=session,)--async def main():- await agent.run()-- input('Press Enter to close the browser...')- await session.stop()--if __name__ == '__main__':- asyncio.run(main())```-### Method 3: Connect via Chrome DevTools Protocol+### Method E: Connect via CDP URL-If Chrome is already running with remote debugging enabled:+Connect to any remote Chromium-based browser:```pythonfrom browser_use import Agent, BrowserSession-from langchain_openai import ChatOpenAI-import asyncio# Connect to Chrome via CDPsession = BrowserSession(cdp_url="http://localhost:9222")@@ -101,29 +105,46 @@ await session.start()agent = Agent(task="Your task here",- llm=ChatOpenAI(model='gpt-4o'),+ llm=llm,browser=session,)```-## Finding Chrome Profile Paths+### Method F: Launch Local Browser-### Default Profile Locations+Launch a local browser using provided executable_path or builtin default:-- **macOS**: `~/Library/Application Support/Google/Chrome`-- **Windows**: `%LOCALAPPDATA%\Google\Chrome\User Data`-- **Linux**: `~/.config/google-chrome`+```python+from browser_use import Agent, BrowserSession, BrowserProfile-### Finding Your Profile Directory+# Configure to use your Chrome installation+profile = BrowserProfile(+ # Path to your Chrome executable (optional)+ executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', # macOS+ # For Windows: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'+ # For Linux: '/usr/bin/google-chrome'++ # Use a custom profile directory+ user_data_dir='~/.config/browseruse/profiles/default',+ profile_directory='Default',+ headless=False+)++# If no executable_path provided, uses Playwright/Patchright's built-in Chromium+session = BrowserSession(browser_profile=profile)+await session.start()-1. Open Chrome and navigate to `chrome://version`-2. Look for "Profile Path" - this shows your current profile location-3. The profile directory name is usually "Default" or "Profile 1", "Profile 2", etc.+agent = Agent(+ task="Your task here",+ llm=llm,+ browser=session,+)+```## Security Considerations<Warning>- When using your real browser profile, the agent will have access to:+ When using any browser profile, the agent will have access to:- All your logged-in sessions and cookies- Saved passwords (if autofill is enabled)- Browser history and bookmarks@@ -137,7 +158,7 @@ agent = Agent(1. **Use a dedicated profile**: Consider creating a separate Chrome profile specifically for agent use:```pythonprofile = BrowserProfile(- user_data_dir='~/.browseruse/profiles/agent-profile',+ user_data_dir='~/.config/browseruse/profiles/default',profile_directory='Default')```