Add dynamic CDP port allocation with per-profile meta.json#23
Add dynamic CDP port allocation with per-profile meta.json#23
Conversation
Chrome no longer hardcodes --remote-debugging-port=9222. Instead:
* startChrome() finds an available port in range 9222-12111
* Port assignment persisted in {profile-name}.meta.json alongside
the profile directory (sibling file, not inside it)
* On startup, checks meta.json for existing Chrome — reconnects
if alive (enables MCP restart without losing browser state)
* Stale meta.json detected via PID liveness + /json/version probe
* killChrome() cleans meta.json so other sessions know port is free
* showBrowser/hideBrowser preserve port across Chrome restart
* Port priority: explicit param > CHROME_WS_PORT env > dynamic
New internal functions:
- chromeHttpAt(host, port, path) for probing before activePort is set
- isPortAlive(host, port, pid) for stale detection
- isPortFree(port) via net.createServer probe
- findAvailablePort(start, end) sequential scan
- readProfileMeta/writeProfileMeta/clearProfileMeta
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MCP server (mcp/src/index.ts): * Parse --port=N from command line arguments * Simplify ensureChromeRunning() to delegate entirely to startChrome() which handles meta.json discovery, reconnection, and dynamic port allocation * Include port info in startup log when --port is specified CLI (skills/browsing/chrome-ws): * Parse --port=N from argv, filter from positional args * Use effectivePort in chromeHttp() and start command * Print correct debug base URL with effective port Bundle rebuilt with all changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Version bumped in package.json and mcp/package.json * CHANGELOG.md: v1.7.0 entry with full feature description * README.md: Add port allocation note, update Windows tip * SKILL.md: browser_mode returns port, note dynamic allocation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes the hardcoded
--remote-debugging-port=9222instartChrome(), which caused silent failures when port 9222 was busy and prevented multiple parallel Chrome instances.Closes #24
startChrome()finds an available port in range 9222–12111 vianet.createServerprobe. First session gets 9222 when available (backward compatible).~/.cache/superpowers/browser-profiles/{name}.meta.json(sibling to profile dir). Enables reconnection to existing Chrome after MCP restart and multi-instance awareness.--port=Nflag: Both MCP server and CLI accept explicit port override (node mcp/dist/index.js --port=9444,./chrome-ws start --port=9555).isPortAlive()verifies Chrome via/json/versionresponse + PID liveness check (process.kill(pid, 0)).--portparam >CHROME_WS_PORTenv var > dynamic allocation.Why this matters
Without this change, running two Claude Code sessions that both use superpowers-chrome would cause one to fail silently or connect to the wrong Chrome instance. With meta.json, sessions can discover each other's Chrome instances and avoid port collisions.
Test plan
npm run buildsucceeds (533KB bundle)timeout 2 node mcp/dist/index.jsstarts without errorstimeout 2 node mcp/dist/index.js --port=9444showsport: 9444 (via --port)in log~/.cache/superpowers/browser-profiles/superpowers-chrome.meta.jsoncreated with port/pid./chrome-ws start --port=9555→ Chrome starts on 9555🤖 Generated with Claude Code