Skip to main content

Chrome Extension

A Chrome Extension that enables AI-powered browser automation through the Chrome DevTools Protocol (CDP) with multi-layer persistence for reliable connections.

Quick Start

1

Install

2

Create a browser automation agent

Architecture Overview

The extension uses a multi-layer architecture to ensure reliable browser automation: The user asks for a browser task; the Chrome extension and agent automate the page via CDP.

Multi-Layer Connection Strategy

Chrome Manifest V3 service workers terminate after 30 seconds of inactivity, which can kill WebSocket connections. We use a three-layer approach to maintain persistent connections:

Layer 1: Offscreen Document (PRIMARY)

The offscreen document is the primary method for maintaining WebSocket connections:
Why Offscreen Document?
  • Lives longer than service workers
  • Can maintain WebSocket connections indefinitely
  • Auto-reconnects when bridge server restarts
  • Sends heartbeats to keep connection alive

Layer 2: Service Worker Bridge (FALLBACK)

If the offscreen document fails, the service worker maintains its own WebSocket:
When Used:
  • Offscreen document creation fails
  • Chrome doesn’t support offscreen API
  • Temporary connection until offscreen is ready

Layer 3: Content Script Keep-Alive (BACKUP)

Content scripts open persistent ports to keep the service worker alive:

Internal Message Flow

When using extension mode, messages flow through multiple components:

Message Types

Why This Architecture?

The offscreen document holds the actual WebSocket connection because:
  • Service workers may terminate after 30s of inactivity
  • Offscreen documents persist longer
  • All outgoing messages route through offscreen
The background script’s bridgeClient handles:
  • Parsing incoming messages
  • Calling appropriate handlers (e.g., onStartAutomation)
  • Forwarding outgoing messages to offscreen
Key Insight: The bridgeClient in the background script doesn’t have its own WebSocket. It routes all messages through the offscreen document’s WebSocket connection.

Browser Automation Engines

Extension Mode (PRIMARY)

Extension mode uses the WebSocket bridge for AI-driven browser automation:
How it works:
  1. Bridge server starts on localhost:8765
  2. Chrome launches with extension loaded
  3. Extension connects to bridge via WebSocket
  4. AI agent sends actions, extension executes them
Advantages:
  • ✅ Full browser context (cookies, sessions)
  • ✅ Access to all tabs
  • ✅ User-like interactions

CDP Mode (FALLBACK)

CDP mode uses direct Chrome DevTools Protocol for reliable automation:
How it works:
  1. Chrome launches with --remote-debugging-port
  2. Python connects directly via CDP
  3. No extension needed
  4. Direct browser control
Advantages:
  • ✅ Always reliable
  • ✅ No extension required
  • ✅ Faster for simple tasks

Browser Subagent

The browser subagent is a specialized AI agent that handles browser interactions:

What Is It?

The browser subagent is a secondary agent with browser-specific tools:
  • click - Click elements
  • type - Enter text
  • navigate - Go to URLs
  • scroll - Scroll pages
  • screenshot - Capture screenshots
  • wait - Wait for elements

How It’s Used

  1. Main agent delegates browser tasks to browser subagent
  2. Browser subagent uses CDP to control Chrome
  3. Results returned to main agent

Is It a Fallback?

No - The browser subagent is the main agent for browser control. It’s used by both:
  • Extension mode (via WebSocket bridge)
  • CDP mode (direct control)

Technology Stack

Project Structure

Installation

From Source

  1. Clone and build:
  1. Load in Chrome:
    • Open chrome://extensions
    • Enable “Developer mode”
    • Click “Load unpacked”
    • Select the dist folder

Via CLI

The CLI automatically loads the extension:

Manual Load Recovery (Chrome 137+ / Windows)

The CLI’s auto-load can silently fail on Chrome 137+ / Windows, which blocks automated --load-extension. When that happens, launch prints a manual “Load unpacked” flow — load the extension into your daily “Work” Chrome instead.
1

Open chrome://extensions

Use your normal Chrome (Work profile) and enable Developer mode.
2

Load unpacked

Click Load unpacked and select the dist/ folder.
3

Verify the connection

If you launched with --no-server, start the bridge first (praisonai browser start), then re-run praisonai browser doctor extension. See the full flow in Manual Extension Load.

Keyboard Shortcuts

Mac users: Use Cmd instead of Ctrl

Configuration

Profile Persistence

By default, PraisonAI uses a persistent Chrome profile at ~/.praisonai/browser_profile. This provides:
  • Consistent Extension ID: Same ID across runs for reliable automation
  • Session Persistence: Cookies, login state, and history preserved
  • Faster Startup: No need to re-initialize extension settings

Default Behavior (Persistent)

Custom Profile Path

Temporary Profile

For isolated testing or clean sessions, use --temp-profile:
Chrome 137+ Note: The --load-extension flag will be removed in Chrome 137 (June 2025) for branded Chrome. For continued automation, use:
  • Chromium (open-source)
  • Chrome for Testing (automation-optimized)

Troubleshooting

Extension Not Connecting

If you see “Timeout after 30s” errors:
  1. Check bridge server:
  2. Check extension console:
    • Go to chrome://extensions
    • Find “PraisonAI Browser Agent”
    • Click “Inspect views: service worker”
    • Look for connection errors
  3. Use CDP fallback:

CLI says “No automation steps in 30s”

The praisonai browser run first-step watchdog fired because start_automation was not confirmed delivered to an extension. Verify the bridge sees an extension and that no other client holds it:
Use the side panel or the CLI, not both at once. For extension-free automation, add --engine cdp.

”Receiving End Does Not Exist” Error

This occurs when the offscreen document isn’t ready. The extension now:
  • Waits 1 second after creating offscreen document
  • Retries 3 times with 500ms delay
  • Falls back to service worker bridge

Chrome Instance Management

The CLI only manages its own Chrome instance:
  • ✅ Only kills the Chrome window it launched
  • ✅ Does NOT kill your manually opened Chrome windows
  • ✅ Reuses existing session when possible

Permissions

The extension requires:

Development

Best Practices

The Chrome extension is ideal for sites that require login or render content with JavaScript.
The extension preserves browser session cookies - use it for sites requiring authentication.
Request only the browser permissions your automation needs to reduce security risk.
Run in headless mode for CI/CD pipelines and server-side automation without a display.

Custom Tools

Build your own agent tools

Tools Overview

Browse PraisonAI tool documentation