SurfAI: Advanced Browser Automation Framework
A powerful Rust-based browser automation framework with human-like behavior simulation and stealth capabilities. Built on top of chromiumoxide with advanced scripting, element interaction, and MCP (Model Context Protocol) server integration.
Features
🚀 Core Capabilities
- Stealth Browser Management: Anti-detection capabilities with realistic browser fingerprinting
- Human-like Interactions: Natural mouse movements, typing patterns, and browsing behavior
- Advanced Element Detection: Intelligent element labeling and interaction systems
- CDP Script Execution: Custom Chrome DevTools Protocol script execution
- Page Scraping: Comprehensive data extraction from web pages
- MCP Server Integration: Model Context Protocol server for AI agent integration
🛡️ Stealth Features
- User agent spoofing and browser fingerprint masking
- Realistic timing patterns and random delays
- CAPTCHA detection and avoidance
- Session management with cookies and browsing history simulation
- Mouse movement with natural curves and variations
🎯 Element Interaction
- Smart element detection and labeling
- Google Search automation with human-like patterns
- Form filling and button clicking
- Screenshot capture and visual debugging
- DOM manipulation and event simulation
Installation
Add this to your Cargo.toml:
[]
= "0.1.2"
= { = "1.0", = ["full"] }
= { = "1.0", = ["derive"] }
= "1.0"
Quick Start
Basic Browser Automation
use *;
async >
Human-like Google Search
use *;
async >
MCP Server Integration
The framework includes a built-in MCP (Model Context Protocol) server for seamless AI agent integration.
Starting the MCP Server
use MCPBrowserServer;
async >
Available MCP Tools
The MCP server provides the following tools for AI agents:
1. create_browser_session
Creates a new browser session with optional stealth mode.
Parameters:
headless(boolean, default: true): Run browser in headless modestealth(boolean, default: false): Enable stealth anti-detection features
Example:
2. navigate_to_url
Navigate to a specific URL in an existing session.
Parameters:
session_id(string, required): Browser session IDurl(string, required): Target URL
Example:
3. search_google
Perform a Google search with human-like behavior patterns.
Parameters:
session_id(string, required): Browser session IDquery(string, required): Search query
Example:
4. get_page_elements
Extract all interactable elements from the current page.
Parameters:
session_id(string, required): Browser session IDelement_types(array, optional): Specific element types to filter
Example:
5. click_element
Click on an element with human-like mouse movements.
Parameters:
session_id(string, required): Browser session IDselector(string, required): CSS selector for the element
Example:
6. type_text
Type text into an element with realistic human typing patterns.
Parameters:
session_id(string, required): Browser session IDselector(string, required): CSS selector for the input elementtext(string, required): Text to type
Example:
7. scrape_page
Extract all data from the current page including title, content, links, images, and forms.
Parameters:
session_id(string, required): Browser session ID
Example:
8. take_screenshot
Capture a screenshot of the current page.
Parameters:
session_id(string, required): Browser session ID
Example:
9. close_session
Close a browser session and clean up resources.
Parameters:
session_id(string, required): Browser session ID
Example:
MCP Usage Flow
- Create Session: Use
create_browser_sessionto initialize a browser - Navigate: Use
navigate_to_urlto go to target websites - Interact: Use
click_element,type_text, orsearch_googlefor interactions - Extract Data: Use
scrape_page,get_page_elements, ortake_screenshotfor data extraction - Cleanup: Use
close_sessionto properly close the browser
MCP Integration Example
use *;
async >
API Reference
Core Components
BrowserManager
Main browser management interface.
Methods:
new(headless: bool) -> BrowserResult: Create standard browsernew_stealth_browser(headless: bool) -> BrowserResult: Create stealth browsernew_page(url: &str) -> BrowserResult: Create new pageclose(self) -> BrowserResult: Close browser
HumanInteractor
Human-like interaction simulation.
Key Methods:
apply_stealth() -> BrowserResult: Apply stealth settingstype_human(selector: &str, text: &str) -> BrowserResult: Human-like typingclick_human(selector: &str) -> BrowserResult: Human-like clickingsearch_with_realistic_pattern(query: &str) -> BrowserResult: Realistic searchextract_search_results() -> BrowserResult>>: Extract results
ElementInteractor
Element detection and interaction.
Key Methods:
get_all_elements() -> BrowserResult>: Get all elementsget_interactable_elements() -> BrowserResult>: Get interactive elementslabel_elements(tags: Option>) -> BrowserResult>: Label elementsclick_element(selector: &str) -> BrowserResult: Click elementtype_text(selector: &str, text: &str) -> BrowserResult: Type text
PageScraper
Web page data extraction.
Key Methods:
scrape_page() -> BrowserResult: Scrape all page datatake_screenshot() -> BrowserResult>: Take screenshotextract_links() -> BrowserResult>: Extract linksextract_images() -> BrowserResult>: Extract images
Configuration
Stealth Browser Settings
The stealth browser includes comprehensive anti-detection features:
let browser = new_stealth_browser.await?;
Stealth Features:
- User agent spoofing
- Plugin and extension masking
- Canvas fingerprinting protection
- WebGL fingerprinting protection
- Timezone and language spoofing
- Screen resolution normalization
Human Behavior Patterns
Customize human-like behavior:
let human = new;
// Configure timing patterns
human.random_delay.await; // Random delay between 1-2 seconds
human.simulate_reading_delay.await; // Reading-based delay
human.simulate_hesitation.await; // Simulate user hesitation
Examples
The examples/ directory contains comprehensive usage examples:
basic_usage.rs: Basic browser automationgoogle_search.rs: Google search automationhuman_google_search.rs: Human-like Google searchlabel_elements.rs: Element labeling and interaction
Run examples with:
Error Handling
The framework uses a comprehensive error system:
use BrowserResult;
match browser.new_page.await
Requirements
- Rust 1.70+
- Chrome or Chromium browser installed
- tokio runtime
- Network access for web automation
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
Support
For issues and questions:
- Create an issue on GitHub
- Check the examples directory for usage patterns
- Review the API documentation
Note: This framework is designed for legitimate automation and testing purposes. Please respect website terms of service and implement appropriate rate limiting and error handling in production use.