Skip to content

Multi-agent concurrency and external browser mode#24

Open
mattheworiordan wants to merge 4 commits intoSawyerHood:mainfrom
mattheworiordan:feat/multi-agent-concurrency
Open

Multi-agent concurrency and external browser mode#24
mattheworiordan wants to merge 4 commits intoSawyerHood:mainfrom
mattheworiordan:feat/multi-agent-concurrency

Conversation

@mattheworiordan
Copy link

@mattheworiordan mattheworiordan commented Dec 30, 2025

Summary

  • Add external browser mode for Chrome for Testing / CDP connections
  • Enable multiple agents to run concurrently with dynamic port allocation
  • Add smart crash recovery with orphaned browser cleanup

Changes

External Browser Mode

Connect to external browsers (Chrome for Testing, Chrome Beta, etc.) via CDP:

  • Browser lifecycle managed externally - survives server shutdown
  • Auto-launch with BROWSER_PATH or connect to existing browser
  • Ideal for visible automation and manual inspection

Multi-Agent Concurrency

  • Dynamic port allocation from configurable range (default: 9222-9300, step 2)
  • Port registry prevents collisions between concurrent agents
  • Config file at ~/.dev-browser/config.json

Crash Recovery

  • Detect orphaned browsers from crashed sessions
  • Clean up stale port registrations automatically
  • Graceful handling of port conflicts

Test plan

  • Start multiple servers concurrently - each gets unique port
  • External browser mode connects to Chrome for Testing
  • Kill server process - browser stays open (external mode)
  • Crash recovery cleans up orphaned browsers on restart

This Depends on external browser mode #20. However, this PR is asking for merge to main, and thus includes commits from that branch. This is unavoidable because of Github :(

Add serveWithExternalBrowser() that connects to an existing browser via CDP
instead of launching Playwright's Chromium. Key features:

  - Connect to any browser with CDP enabled (Chrome for Testing, Chrome Beta, etc.)
  - Auto-launch browser if not running (with BROWSER_PATH env var)
  - Browser stays open after server stops (user manages lifecycle)
  - No extension required - direct CDP connection

New files:
  - src/external-browser.ts - Core implementation
  - scripts/start-external-browser.ts - Startup script

Use case: Local development with visible browser automation where you want
to inspect results after automation completes.
When multiple AI agents run browser automation tasks in parallel,
they need separate HTTP API ports while potentially sharing the same
browser instance. This adds automatic port allocation to avoid conflicts.

Key changes:
- Add port-manager.ts for dynamic port allocation (range 9222-9300)
- Server tracking via ~/.dev-browser/active-servers.json
- PORT=XXXX output for agent discovery
- Config file support at ~/.dev-browser/config.json
- Update both standalone and external browser modes

Architecture:
  Agent 1 → server (port 9222) ┐
  Agent 2 → server (port 9224) ├→ Shared Browser (CDP 9223)
  Agent 3 → server (port 9226) ┘

See docs/CONCURRENCY.md for design decisions and usage examples.
Addresses concerns raised in PR SawyerHood#15 about single-point congestion.
When a dev-browser server crashes, its Chrome browser may still be
running on the CDP port. This adds smart cleanup to detect and
terminate orphaned browsers before launching new ones.

Key changes:
- Enhanced ServerInfo structure to track CDP port and mode
- Added detectOrphanedBrowsers() to find browsers with no registered server
- Added cleanupOrphanedBrowsers() to safely terminate orphans
- Standalone mode now cleans orphans on startup (before launching browser)
- External mode tracks CDP port but doesn't clean (browser is intentionally external)

This restores crash recovery functionality that was previously in
start-server.ts, but in a smarter way that respects multi-agent scenarios.
  - Add ~/.dev-browser/config.json for browser configuration
  - Auto-detect Chrome for Testing on macOS/Linux/Windows
  - Add --standalone flag to force Playwright mode
  - Skip npm install when dependencies unchanged (hash check)
  - Rename port-manager.ts to config.ts with browser config
  - Let browser use default profile unless userDataDir explicitly set
  - Simplify SKILL.md documentation with single startup flow
mjdaly added a commit to mjdaly/dev-browser that referenced this pull request Jan 16, 2026
Adds support for Chrome for Testing via CDP and multi-agent concurrency.
- External browser mode keeps browser open after automation
- Auto-detects Chrome for Testing installation
- New config file at ~/.dev-browser/config.json
- Better support for multi-agent workflows

Source: SawyerHood#24
Co-authored-by: Matthew O'Riordan <matthew@ably.com>
mjdaly added a commit to mjdaly/dev-browser that referenced this pull request Jan 16, 2026
Adds support for Chrome for Testing via CDP and multi-agent concurrency.
- External browser mode keeps browser open after automation
- Auto-detects Chrome for Testing installation
- New config file at ~/.dev-browser/config.json
- Better support for multi-agent workflows

Source: SawyerHood#24
Co-authored-by: Matthew O'Riordan <matthew@ably.com>
@tylerlaprade
Copy link

Multi-agent concurrency would be very helpful to me. It seems unrelated to external browser mode. Please break your changes into separate PRs if possible.

@mattheworiordan
Copy link
Author

I would but this repo is a ghost town. No PRs are being merged so seems pointless.

@tylerlaprade
Copy link

That's a bummer. This skill has been amazing for me to get my agents to verify their own work.

I ended up switching to https://github.com/vercel-labs/agent-browser since it supports concurrent named sessions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants