Browserbase
Navigate pages, take screenshots, and extract page content with BrowserbaseTools using sync and async browser sessions.
BrowserbaseTools enable an Agent to automate browser interactions using Browserbase, a headless browser service.
Prerequisites
The following example requires Browserbase API credentials after you signup here, and the Playwright library.
uv pip install agno browserbase playwright openai
export BROWSERBASE_API_KEY=xxx
export BROWSERBASE_PROJECT_ID=xxxExample
The following agent will use Browserbase to visit https://quotes.toscrape.com and extract content. Then navigate to page two of the website and get quotes from there as well.
from agno.agent import Agent
from agno.tools.browserbase import BrowserbaseTools
agent = Agent(
name="Web Automation Assistant",
tools=[BrowserbaseTools()],
instructions=[
"You are a web automation assistant that can help with:",
"1. Capturing screenshots of websites",
"2. Extracting content from web pages",
"3. Monitoring website changes",
"4. Taking visual snapshots of responsive layouts",
"5. Automated web testing and verification",
],
markdown=True,
)
agent.print_response("""
Visit https://quotes.toscrape.com and:
1. Extract the first 5 quotes and their authors
2. Navigate to page 2
3. Extract the first 5 quotes from page 2
""")Close the browser connection
Retain the toolkit instance and close it even when the agent run fails:
from agno.agent import Agent
from agno.tools.browserbase import BrowserbaseTools
browser = BrowserbaseTools()
try:
Agent(tools=[browser]).print_response(
"Read the first five quotes from https://quotes.toscrape.com."
)
finally:
browser.close_session()For an async run, use await browser.aclose_session() in an async finally block. These methods disconnect local Playwright resources. Normal provider sessions end on disconnect; an externally supplied keep-alive session needs the provider's REQUEST_RELEASE operation to end immediately.
Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | Browserbase API key. If not provided, uses BROWSERBASE_API_KEY env var. |
project_id | str | None | Browserbase project ID. If not provided, uses BROWSERBASE_PROJECT_ID env var. |
base_url | str | None | Custom Browserbase API endpoint URL. This changes the HTTP API endpoint; it does not select a browser session region. If not provided, uses BROWSERBASE_BASE_URL env var. |
enable_navigate_to | bool | True | Enable the navigate_to functionality. |
enable_screenshot | bool | True | Enable the screenshot functionality. |
enable_get_page_content | bool | True | Enable the get_page_content functionality. |
enable_close_session | bool | True | Enable the close_session functionality. |
all | bool | False | Enable all functionality. |
parse_html | bool | True | Strip script/style blocks and HTML tags with regular expressions; this does not evaluate CSS visibility. Reduces token usage. |
max_content_length | Optional[int] | 100000 | Maximum character length for page content. Longer content is truncated with a notice. Set to None for no limit. |
Toolkit Functions
| Function | Description |
|---|---|
navigate_to | Navigates to a URL. Takes a URL and an optional connect_url parameter. |
screenshot | Takes a screenshot of the current page. Takes a path to save the screenshot, a boolean for full-page capture, and an optional connect_url parameter. |
get_page_content | Gets the content of the current page. Returns text-only content when parse_html=True (default), otherwise raw HTML. Takes an optional connect_url parameter. |
close_session | Closes a browser session. |