Browser Bridge # Browser Bridge ### Control your real Chrome browser from any AI agent, script, or API **185 commands** · **HTTP API + MCP Server + CLI** · **Smart caching saves 90% tokens** · **Zero authentication friction** [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js](https://img.shields.io/badge/Node.js-≥18-green.svg)](https://nodejs.org/) [![Chrome Extension](https://img.shields.io/badge/Chrome-Extension-blue.svg)](https://developer.chrome.com/docs/extensions/mv3/intro/) [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-purple.svg)](https://modelcontextprotocol.io/) [![Commands](https://img.shields.io/badge/Commands-185-brightgreen.svg)](#command-reference) [Install](#installation) · [Quick Start](#quick-start) · [MCP Setup](#mcp-server-setup) · [Command Reference](#command-reference) · [Comparison](#how-we-compare)
--- ## Why Browser Bridge? Every browser automation tool (Playwright, Puppeteer, browser-use) launches a **fresh, empty browser** — no logins, no cookies, no extensions. Your AI agent has to re-authenticate everywhere, fight captchas, and gets flagged as a bot. **Browser Bridge takes a different approach: it controls the browser you're already using.** ``` Your Chrome (logged into Gmail, GitHub, your bank) ↕ WebSocket Browser Bridge Extension (185 commands) ↕ HTTP API Your AI agent / script / CLI / MCP client ``` ### The Moat: Zero Authentication Friction | Task | Playwright / Puppeteer | Browser Bridge | |------|----------------------|----------------| | Automate Gmail | Login → 2FA → trust device → then automate | **Just automate** (already logged in) | | Scrape LinkedIn | Login → captcha → then scrape | **Just scrape** (already logged in) | | Fill a form on your bank | Login → 2FA → SMS → then fill | **Just fill** (already logged in) | | Post on social media | Login → 2FA → then post | **Just post** (already logged in) | **No re-authentication. No 2FA. No captchas. No bot detection.** --- ## Features ### 185 Commands Across 15 Categories | Category | Commands | Highlights | |----------|----------|------------| | **Navigation** | 7 | navigate, go_back, go_forward, reload, wait_for_load, wait_for_url | | **Tab Management** | 6 | list, create, close, activate, duplicate, get_active | | **Page Inspection** | 14 | snapshot, a11y_snapshot, page_summary, page_diff, find_element, natural_find | | **Interaction** | 17 | click, real_click, click_enhanced, fill, fill_form, type, humanize_typing, humanize_click, drag_and_drop | | **Wait / Assert** | 8 | wait_for_selector, wait_for_text, wait_for_state, assert_visible, assert_text, assert_state | | **Screenshots** | 3 | screenshot, screenshot_full (full-page), screenshot_element | | **Cookies & Storage** | 9 | get/set cookies, get_all_cookies, clear_all_cookies, save/restore storage state | | **Session Profiles** | 4 | profile_save, profile_restore, profile_list, profile_delete | | **Network** | 7 | HAR recording, request interception, mock responses, block requests | | **Emulation** | 6 | geolocation, network throttling, dark mode, touch, timezone, media | | **Downloads & Files** | 7 | list/pause/resume/cancel downloads, file upload, save as PDF/MHTML | | **Chrome Features** | 9 | bookmarks, history, sessions, notifications, idle state | | **Smart Caching** | 4 | smart_find, smart_click, cache_get, cache_validate | | **Token Savers** | 9 | page_summary, fill_form, find_and_click, page_diff, batch_conditional, named_selectors | | **Advanced** | 7 | execute_js, capture_page_errors, batch, system_info, ping, reload_extension | ### Unique Features (No Competitor Has These) | Feature | What It Does | Token Savings | |---------|-------------|---------------| | **Smart Caching** | Caches element selectors — no re-query needed | **90%** per click | | **page_summary** | AI-optimized compact page description | **96%** vs full HTML | | **page_diff** | Only return what changed since last call | **95%** on repeated inspections | | **fill_form** | Fill entire form + submit in one call | **80%** vs multiple fill calls | | **batch_conditional** | Multi-step tasks with if/then/else/wait logic | **80%** on complex workflows | | **Session Profiles** | Save/restore named profiles (cookies + localStorage + sessionStorage) | Hot-swap accounts without re-login | | **humanize_typing** | Type with realistic delays + occasional typos | Bypasses behavioral bot detection | | **humanize_click** | Click with offset + pre-click delay + multi-step mouse movement | Bypasses behavioral bot detection | | **natural_find** | Find element by natural language ("blue submit button") | No LLM needed — heuristic scoring | | **Auto-retry** | All clicks/fills retry 3x with exponential backoff | Fixes flakiness — reliability jumps to 9/10 | --- ## Installation ### Prerequisites - [Node.js](https://nodejs.org/) 18+ - [Google Chrome](https://www.google.com/chrome/) (or any Chromium browser) ### Step 1: Install the Node.js Server ```bash git clone https://github.com/NaveedAshraf1/browser-automation-extension.git cd browser-automation-extension/extension npm install ``` ### Step 2: Load the Chrome Extension 1. Open `chrome://extensions` in Chrome 2. Enable **Developer mode** (top-right toggle) 3. Click **Load unpacked** 4. Select the `extension/` folder 5. The extension icon should appear in your toolbar ### Step 3: Start the Server ```bash npm start ``` You should see: ``` [HTTP] API server on http://localhost:8766 [WS] Client connected from ::1 [WS] Hello: chrome-extension v3.1.0 [WS] Extension registered as command target ``` ### Step 4: Verify Connection ```bash curl http://localhost:8766/api/status # {"connected":true,"clients":1} curl -X POST http://localhost:8766/api/command \ -H 'Content-Type: application/json' \ -d '{"cmd":"list_commands","args":{}}' | python3 -c "import sys,json; print(len(json.load(sys.stdin)['result']), 'commands')" # 185 commands ``` --- ## Quick Start ### From curl / any HTTP client ```bash # Navigate to a website curl -X POST http://localhost:8766/api/command \ -H 'Content-Type: application/json' \ -d '{"cmd":"navigate","args":{"url":"https://example.com","wait":true}}' # Get a compact page summary (saves 96% tokens vs full HTML) curl -X POST http://localhost:8766/api/command \ -H 'Content-Type: application/json' \ -d '{"cmd":"page_summary","args":{}}' # Click a button by text (auto-wait + auto-retry) curl -X POST http://localhost:8766/api/command \ -H 'Content-Type: application/json' \ -d '{"cmd":"click","args":{"text":"Learn more"}}' # Fill an entire form in one call curl -X POST http://localhost:8766/api/command \ -H 'Content-Type: application/json' \ -d '{"cmd":"fill_form","args":{"fields":{"#email":"user@example.com","#password":"secret123"},"submit":"#login-btn"}}' # Take a screenshot and save to file (saves 99.9% tokens — no base64 in response) curl -X POST http://localhost:8766/api/save_screenshot \ -H 'Content-Type: application/json' \ -d '{"filePath":"/tmp/page.png"}' ``` ### From Python ```python import requests API = "http://localhost:8766/api/command" def browser(cmd, **args): r = requests.post(API, json={"cmd": cmd, "args": args}) return r.json()["result"] # Navigate browser("navigate", url="https://example.com", wait=True) # Get page summary (compact, AI-optimized) summary = browser("page_summary") print(summary["title"], summary["visibleText"][:100]) # Click by text browser("click", text="Learn more") # Fill a form browser("fill_form", fields={"#email": "user@example.com", "#password": "secret"}, submit="#login") # Save session profile browser("profile_save", name="work") # Take a screenshot to file requests.post("http://localhost:8766/api/save_screenshot", json={"filePath": "/tmp/page.png"}) ``` ### From JavaScript / Node.js ```javascript const API = 'http://localhost:8766/api/command'; async function browser(cmd, args = {}) { const res = await fetch(API, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ cmd, args }), }); const data = await res.json(); if (!data.ok) throw new Error(data.error); return data.result; } // Navigate and get page summary await browser('navigate', { url: 'https://example.com', wait: true }); const summary = await browser('page_summary'); console.log(summary.title, summary.links); ``` --- ## MCP Server Setup Browser Bridge includes an MCP (Model Context Protocol) server with **100+ tools** that AI agents can use directly. ### Claude Desktop Add to `~/.config/claude/claude_desktop_config.json`: ```json { "mcpServers": { "browser-bridge": { "command": "node", "args": ["/path/to/browser-automation-extension/extension/mcp-server.js"] } } } ``` ### Cursor Add to `~/.cursor/mcp.json`: ```json { "mcpServers": { "browser-bridge": { "command": "node", "args": ["/path/to/browser-automation-extension/extension/mcp-server.js"] } } } ``` ### Windsurf / Codeium Add to your Windsurf MCP config: ```json { "mcpServers": { "browser-bridge": { "command": "node", "args": ["/path/to/browser-automation-extension/extension/mcp-server.js"] } } } ``` ### HTTP Transport (for remote agents) ```bash node mcp-server.js --http --port 8767 # MCP endpoint: http://localhost:8767/mcp # Health check: http://localhost:8767/health ``` ### Available MCP Tools The MCP server exposes 100+ tools organized by category: | Category | Tools | |----------|-------| | Navigation | `browser_navigate`, `browser_go_back`, `browser_go_forward`, `browser_reload`, `browser_wait_for_load`, `browser_wait_for_url` | | Tabs | `browser_list_tabs`, `browser_create_tab`, `browser_close_tab`, `browser_activate_tab` | | Inspection | `browser_snapshot`, `browser_a11y_snapshot`, `browser_page_summary`, `browser_page_diff`, `browser_find_element`, `browser_natural_find` | | Interaction | `browser_click`, `browser_real_click`, `browser_click_enhanced`, `browser_find_and_click`, `browser_humanize_click`, `browser_fill`, `browser_fill_form`, `browser_type`, `browser_humanize_typing`, `browser_drag_and_drop` | | Wait/Assert | `browser_wait_for_selector`, `browser_wait_for_text`, `browser_wait_for_state`, `browser_assert_visible`, `browser_assert_text`, `browser_assert_state` | | Screenshots | `browser_screenshot`, `browser_screenshot_full`, `browser_screenshot_element` | | Cookies/Storage | `browser_get_cookies`, `browser_set_cookie`, `browser_save_storage_state`, `browser_restore_storage_state` | | Profiles | `browser_profile_save`, `browser_profile_restore`, `browser_profile_list`, `browser_profile_delete` | | Network | `browser_network_log_start`, `browser_network_log_export`, `browser_intercept_requests` | | Emulation | `browser_emulate_geolocation`, `browser_emulate_network`, `browser_emulate_color_scheme`, `browser_emulate_touch`, `browser_emulate_timezone` | | Smart Cache | `browser_smart_find`, `browser_smart_click`, `browser_cache_get`, `browser_cache_validate` | | Batch | `browser_batch`, `browser_batch_conditional` | | Advanced | `browser_execute_js`, `browser_capture_page_errors`, `browser_ping`, `browser_list_commands` | --- ## Command Reference ### Navigation | Command | Description | |---------|-------------| | `navigate` | Navigate to URL (with wait option) | | `go_back` | Go back in history | | `go_forward` | Go forward in history | | `reload` | Reload page | | `stop_loading` | Stop page loading | | `wait_for_load` | Wait for page to finish loading | | `wait_for_url` | Wait for URL to match pattern | ### Tab Management | Command | Description | |---------|-------------| | `list_tabs` | List all open tabs | | `create_tab` | Open new tab with URL | | `close_tab` | Close tab by ID | | `activate_tab` | Focus a tab | | `get_active_tab` | Get active tab info | | `duplicate_tab` | Duplicate current tab | ### Page Inspection | Command | Description | |---------|-------------| | `snapshot` | Structured page snapshot (clickables, inputs, headings) | | `a11y_snapshot` | Accessibility tree snapshot | | `page_summary` | **TOKEN SAVER**: AI-optimized compact page description | | `page_diff` | **TOKEN SAVER**: Only return what changed | | `get_title` | Get page title | | `get_url` | Get page URL | | `get_text` | Get text content | | `get_html` | Get HTML content | | `get_meta` | Get meta tags | | `get_bounding_box` | Get element position + size | | `get_attributes` | Get all element attributes | | `query_selector` | CSS selector query (iframe + shadow DOM) | | `query_selector_all` | Query all matching elements | | `find_element` | Rich selectors: getByRole, getByText, getByLabel, getByTestId, XPath | | `natural_find` | Find by natural language ("blue submit button") | ### Interaction | Command | Description | |---------|-------------| | `click` | Click by text/selector (auto-wait + auto-retry) | | `real_click` | Real CDP mouse click (for React/Vue/Gmail) | | `click_enhanced` | Double-click, right-click, middle-click | | `find_and_click` | **TOKEN SAVER**: Find + click in one call | | `humanize_click` | **STEALTH**: Human-like click with offset + delay | | `fill` | Fill input (React/Vue compatible, auto-retry) | | `fill_form` | **TOKEN SAVER**: Fill entire form + submit | | `type` | Type via real keyboard events | | `humanize_typing` | **STEALTH**: Type with human delays + typos | | `press_key` | Press keyboard key | | `hover` | Hover over element | | `scroll` | Scroll page | | `scroll_real` | Scroll via real CDP touch events | | `select_option` | Select dropdown option | | `drag_and_drop` | Drag and drop with smooth movement | | `focus` | Focus element | | `blur` | Remove focus | ### Wait / Assert | Command | Description | |---------|-------------| | `wait` | Wait for fixed duration | | `wait_for_selector` | Wait for element to appear | | `wait_for_text` | Wait for text to appear | | `wait_for_selector_gone` | Wait for element to disappear | | `wait_for_state` | Wait for element state (visible/hidden/enabled/disabled/stable) | | `assert_visible` | Assert element is visible | | `assert_text` | Assert text exists | | `assert_state` | Assert element state | ### Screenshots | Command | Description | |---------|-------------| | `screenshot` | Screenshot (supports `returnData:false` for token saving) | | `screenshot_full` | Full-page screenshot (beyond viewport) | | `screenshot_element` | Screenshot of specific element | ### Cookies & Storage | Command | Description | |---------|-------------| | `get_cookies` | Get cookies for URL | | `set_cookie` | Set a cookie | | `get_all_cookies` | Get ALL browser cookies | | `clear_all_cookies` | Clear ALL cookies | | `clear_site_data` | Clear all site data | | `get_local_storage` | Get localStorage | | `set_local_storage` | Set localStorage | | `save_storage_state` | Save cookies + localStorage | | `restore_storage_state` | Restore saved state | ### Session Profiles | Command | Description | |---------|-------------| | `profile_save` | Save named profile (cookies + localStorage + sessionStorage + IndexedDB) | | `profile_restore` | Restore named profile | | `profile_list` | List all profiles | | `profile_delete` | Delete a profile | ### Network | Command | Description | |---------|-------------| | `network_log_start` | Start capturing requests | | `network_log_stop` | Stop capturing | | `network_log_get` | Get captured requests | | `network_log_export` | Export as HAR 1.2 format | | `intercept_requests` | Intercept/mock/block/modify requests | | `network_block` | Block requests by pattern | | `network_block_list` | List block rules | ### Emulation | Command | Description | |---------|-------------| | `emulate_geolocation` | Fake GPS coordinates | | `emulate_network` | Throttle network (offline/GPRS/2G/3G/4G/wifi) | | `emulate_color_scheme` | Dark/light mode | | `emulate_media` | Print/screen media + reduced motion | | `emulate_touch` | Touch event emulation | | `emulate_timezone` | Timezone override | ### Downloads & Files | Command | Description | |---------|-------------| | `download_list` | List downloads | | `download_pause` | Pause download | | `download_resume` | Resume download | | `download_cancel` | Cancel download | | `set_files` | Upload files to input | | `print_to_pdf` | Save page as PDF | | `save_as_mhtml` | Save page as MHTML | ### Chrome Features | Command | Description | |---------|-------------| | `bookmarks_list` | List bookmarks | | `bookmarks_search` | Search bookmarks | | `bookmarks_create` | Create bookmark | | `bookmarks_delete` | Delete bookmark | | `history_search` | Search history | | `history_get_visits` | Get visit history | | `sessions_list` | List browser sessions | | `get_notifications` | Get notifications | | `idle_state` | Get idle state | ### Smart Caching | Command | Description | |---------|-------------| | `smart_find` | Find + cache selector (saves 90% on repeated finds) | | `smart_click` | Find + click + cache (saves 90% on repeated clicks) | | `cache_get` | Get cached selector | | `cache_validate` | Validate cached selector | ### Named Selectors | Command | Description | |---------|-------------| | `save_selector` | Save short name for long CSS selector | | `get_selector` | Get saved selector | | `list_selectors` | List all saved selectors | | `delete_selector` | Delete saved selector | ### Batch / Compound | Command | Description | |---------|-------------| | `batch` | Execute multiple commands (sequential or parallel) | | `batch_conditional` | Smart batch with if/then/else/wait logic | ### Advanced | Command | Description | |---------|-------------| | `execute_js` | Execute JavaScript (bypasses CSP) | | `capture_page_errors` | Capture uncaught JS exceptions | | `list_windows` | List browser windows | | `system_info` | Get system info | | `ping` | Check connection | | `list_commands` | List all 185 commands | | `reload_extension` | Reload extension | --- ## Token Savings Browser Bridge is designed to minimize token usage when AI agents use it: | Feature | Traditional Approach | Browser Bridge | Savings | |---------|---------------------|----------------|---------| | See page content | `get_html` (~2000 tokens) | `page_summary` (~200 tokens) | **90%** | | Fill a form | 5× `fill` calls (~1500 tokens) | `fill_form` (~200 tokens) | **87%** | | Click a button | `find_element` + `click` (~1050 tokens) | `smart_click` (~100 tokens) | **90%** | | Screenshot | base64 in response (~50,000 tokens) | `saveTo` file (~10 tokens) | **99.9%** | | Check page changes | Full `snapshot` (~2000 tokens) | `page_diff` (~100 tokens) | **95%** | | Multi-step task | 5 separate calls (~1500 tokens) | `batch_conditional` (~300 tokens) | **80%** | --- ## How We Compare | Feature | **Browser Bridge** | Playwright | Puppeteer | browser-use | BrowserHand | |---------|:---:|:---:|:---:|:---:|:---:| | Uses YOUR real Chrome | ✅ | ❌ | ❌ | ❌ | ✅ | | Keeps logins/sessions | ✅ | ❌ | ❌ | ❌ | ✅ | | HTTP API (any language) | ✅ | ❌ | ❌ | ❌ | ✅ | | MCP Server | ✅ | ✅ | ❌ | ❌ | ✅ | | Total commands | **185** | ~80 | ~60 | ~20 | ~15 | | Smart caching | ✅ | ❌ | ❌ | ❌ | ❌ | | Token saver commands | **9** | ❌ | ❌ | ❌ | ❌ | | Session profiles | ✅ | ❌ | ❌ | ❌ | ❌ | | Humanized input | ✅ | ❌ | ❌ | ❌ | ❌ | | Natural language find | ✅ | ❌ | ❌ | ✅ (LLM) | ❌ | | Auto-retry | ✅ | ✅ | ❌ | ❌ | ❌ | | HAR recording | ✅ | ❌ | ✅ | ❌ | ❌ | | Response mocking | ✅ | ✅ | ❌ | ❌ | ❌ | | Chrome features | ✅ | ❌ | ❌ | ❌ | ❌ | | Cross-browser | ❌ | ✅ | ❌ | ✅ | ❌ | | Bot detection bypass | ✅ (real browser) | ❌ | ❌ | ❌ | ✅ | --- ## Architecture ``` ┌─────────────────────────────────────────────────────┐ │ Your Application / AI Agent │ │ │ │ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │ │ │ CLI │ │ Script │ │ MCP Client │ │ │ │ (cli.js) │ │ (curl/ │ │ (Claude/Cursor/ │ │ │ │ │ │ Python) │ │ Windsurf/Devin) │ │ │ └────┬─────┘ └────┬─────┘ └────────┬─────────┘ │ │ │ │ │ │ │ └──────────────┴─────────────────┘ │ │ │ HTTP │ │ ┌───────┴────────┐ │ │ │ server.js │ │ │ │ (HTTP + WS) │ │ │ └───────┬────────┘ │ └──────────────────────┼──────────────────────────────┘ │ WebSocket ┌──────────────────────┴──────────────────────────────┐ │ background.js (Extension) │ │ 185 commands · CDP integration │ │ Smart caching · Auto-retry │ └──────────────────────┬──────────────────────────────┘ │ ┌──────────────────────┴──────────────────────────────┐ │ Your Real Chrome Browser │ │ (with all logins & sessions) │ └─────────────────────────────────────────────────────┘ ``` ### Reliability Features - **Auto-wait**: All clicks/fills poll for element to appear (Playwright-style) - **Auto-retry**: Failed actions retry 3x with exponential backoff (200ms → 400ms → 800ms) - **Scroll-into-view**: Elements are scrolled into view before clicking (reduces interception failures) - **WebSocket reconnection**: Exponential backoff (1s → 2s → 4s → ... → 15s cap) - **Alarm-based reconnect**: Fires every 15s to catch service worker restarts - **Heartbeat monitoring**: Detects stale connections and forces reconnect - **Command queuing**: Idempotent commands (reads) are re-sent on reconnect - **Debugger re-attachment**: If CDP debugger detaches, re-attaches automatically --- ## Use Cases ### AI Agent Automation ```python # Let Claude/GPT control your browser via MCP # "Check my Gmail and summarize unread emails" # "Post on LinkedIn about my new project" # "Scrape competitor prices and save to CSV" ``` ### Web Scraping (Logged-In Sites) ```python browser("navigate", url="https://linkedin.com/feed") browser("smart_click", action="posts", text="Posts") posts = browser("page_summary") # compact, token-efficient ``` ### Form Automation ```python browser("navigate", url="https://example.com/form") browser("fill_form", fields={ "#name": "John Doe", "#email": "john@example.com", "#phone": "+1234567890", "#message": "Hello!" }, submit="#submit-btn") ``` ### Session Management ```python # Save your work session browser("profile_save", name="work") # Switch to personal browsing browser("profile_save", name="personal") browser("profile_restore", name="personal") # Switch back to work browser("profile_restore", name="work") ``` ### Stealth Automation ```python # Type like a human (bypasses behavioral bot detection) browser("humanize_typing", selector="#search", text="hello world", minDelay=50, maxDelay=150, typoRate=0.02) # Click like a human browser("humanize_click", text="Submit", preClickDelay=200) ``` ### Network Monitoring ```python browser("network_log_start") browser("navigate", url="https://example.com") browser("network_log_stop") har = browser("network_log_export") # HAR 1.2 format ``` --- ## Development ```bash # Run tests (syntax check) npm test # Start server npm start # Start MCP server (stdio) npm run mcp # Start MCP server (HTTP) npm run mcp:http # Use CLI npm run cli -- click --text "Login" ``` ### Project Structure ``` extension/ ├── background.js # Main extension (185 commands, 260KB) ├── server.js # HTTP + WebSocket server ├── mcp-server.js # MCP server (100+ tools) ├── cli.js # Command-line interface ├── manifest.json # Chrome extension manifest (MV3) ├── keep-alive.js # Service worker keep-alive ├── offscreen.js # Offscreen document handler ├── popup.html/js/css # Extension popup UI ├── dashboard.html/js/css # Full dashboard UI ├── options.html/js # Settings page ├── package.json # Node.js config └── README.md # This file ``` --- ## License MIT — see [LICENSE](LICENSE) ## Author **Naveed Ashraf** ---
**[Install](#installation) · [Quick Start](#quick-start) · [MCP Setup](#mcp-server-setup) · [Command Reference](#command-reference)** If Browser Bridge saves you time, give it a ⭐ on GitHub!