Browser automation is becoming essential for AI agents that need to interact with the real world - searching for information, filling forms, extracting data, and navigating web applications. This guide covers how to add browser capabilities to your agentic applications.
Overview of Browser Agent Solutions
Several frameworks provide browser automation for AI agents:
| Solution | Framework | Browser Engine | Key Features |
|---|---|---|---|
| MultimodalWebSurfer | AutoGen | Playwright/Chromium | Set-of-mark screenshots, built-in tools |
| Browser Use | LangChain compatible | Playwright | DOM extraction, action chains |
| Playwright MCP | Model Context Protocol | Playwright | Standardized tool interface |
| Puppeteer | Standalone | Chrome DevTools | Low-level control |
| Selenium | Standalone | WebDriver | Cross-browser support |
This guide focuses on AutoGen's MultimodalWebSurfer as a representative implementation, but the concepts apply broadly.
AutoGen MultimodalWebSurfer
AutoGen's MultimodalWebSurfer is a multimodal agent that can browse the web autonomously - searching, navigating pages, clicking links, filling forms, and extracting information.
Installation
pip install "autogen-ext[web-surfer]"
Quick Start
import asyncio
from autogen_agentchat.ui import Console
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.agents.web_surfer import MultimodalWebSurfer
async def main() -> None:
web_surfer_agent = MultimodalWebSurfer(
name="MultimodalWebSurfer",
model_client=OpenAIChatCompletionClient(model="gpt-4o-2024-08-06"),
)
agent_team = RoundRobinGroupChat([web_surfer_agent], max_turns=3)
stream = agent_team.run_stream(task="Navigate to the AutoGen readme on GitHub.")
await Console(stream)
# Important: Close the browser when done
await web_surfer_agent.close()
asyncio.run(main())
How It Works
- Browser Initialization: Playwright launches Chromium on first call (reused for subsequent calls)
- Screenshot & Analysis: Takes screenshot, extracts interactive elements, creates set-of-mark (SOM) image with bounding boxes
- Model Decision: Sends SOM screenshot + message history + available tools to multimodal model
- Action Execution: Executes tool calls via PlaywrightController
- Response Generation: Returns screenshot, page metadata, action description, and webpage text
Configuration
web_surfer = MultimodalWebSurfer(
name="WebSurfer",
model_client=model_client,
# Browser
headless=True, # No visible window
start_page="https://www.bing.com/", # Initial page
browser_channel=None, # e.g., "chrome"
browser_data_dir=None, # Persistent data
# Viewport (default: 1440x900)
to_resize_viewport=True,
# Features
downloads_folder=None, # Save downloads here
animate_actions=False, # Visual cursor animations
to_save_screenshots=False, # Save screenshots to disk
use_ocr=False, # OCR for text extraction
# Debug
debug_dir=None,
# Advanced: existing Playwright instance
playwright=None,
context=None,
)
PlaywrightController API
The PlaywrightController handles browser interactions:
Navigation
visit_page(page, url)- Navigate to URLback(page)- Go backpage_down(page)/page_up(page)- Scroll viewport
Interactions
click_id(page, identifier)- Click elementhover_id(page, identifier)- Hover over elementfill_id(page, identifier, value, press_enter=True)- Fill formscroll_id(page, identifier, direction)- Scroll within element
Content Extraction
get_webpage_text(page, n_lines=50)- Get page textget_visible_text(page)- Get viewport textget_page_metadata(page)- Get title, URL, etc.
Element Detection
get_interactive_rects(page)- Get interactive elements with bounding boxesget_focused_rect_id(page)- Get focused element ID
Utilities
sleep(page, duration)- Wait (for page loads)
Windows Compatibility
import sys
import asyncio
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
Model Requirements
The model must be:
- Multimodal: Process screenshots
- Function calling capable: Execute browser actions
Recommended: GPT-4o (gpt-4o-2024-08-06 or later)
Security Considerations
Browser agents interact with the real web, which introduces risks:
Risks
- Agents may accept cookie agreements or click unexpected buttons
- Susceptible to prompt injection from malicious webpages
- May inadvertently expose credentials or sensitive data
Mitigations
- Run in sandboxed/containerized environments
- Whitelist allowed domains
- Monitor agent actions in real-time
- Never expose sensitive credentials to agents
- Use read-only modes when possible
Example: Research Agent
import asyncio
from autogen_agentchat.ui import Console
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.agents.web_surfer import MultimodalWebSurfer
async def research_topic(topic: str) -> None:
web_surfer = MultimodalWebSurfer(
name="Researcher",
model_client=OpenAIChatCompletionClient(model="gpt-4o-2024-08-06"),
headless=True,
to_save_screenshots=True,
debug_dir="./research_debug",
)
team = RoundRobinGroupChat([web_surfer], max_turns=5)
task = f"""
Research: {topic}
1. Search on Bing
2. Visit 2-3 relevant pages
3. Summarize key findings
"""
stream = team.run_stream(task=task)
await Console(stream)
await web_surfer.close()
if __name__ == "__main__":
asyncio.run(research_topic("AutoGen multi-agent framework"))
References
- AutoGen MultimodalWebSurfer Documentation. (n.d.). Microsoft. Retrieved December 25, 2025, from https://microsoft.github.io/autogen/stable/reference/python/autogen_ext.agents.web_surfer.html