Skip to content

feat: Auto-connect to existing Chrome when profile is locked#8

Open
Alllynnn wants to merge 1 commit into
zhizhuodemao:mainfrom
Alllynnn:feat/share-chrome-across-instances
Open

feat: Auto-connect to existing Chrome when profile is locked#8
Alllynnn wants to merge 1 commit into
zhizhuodemao:mainfrom
Alllynnn:feat/share-chrome-across-instances

Conversation

@Alllynnn

@Alllynnn Alllynnn commented Feb 26, 2026

Copy link
Copy Markdown

Summary

  • 当第二个 MCP 实例尝试启动 Chrome 但 profile 目录已被锁定时,自动通过 WebSocket 连接到已运行的 Chrome,而非报错
  • 在 Chrome 启动参数中添加 --remote-debugging-port=0,使 Chrome 写入 DevToolsActivePort 文件(含随机本地端口)
  • 新增 connectToExistingBrowser() 辅助函数,读取端口文件并通过 puppeteer.connect() 接入
  • 仅在非 isolated 模式下生效,--isolated / --browserUrl / --wsEndpoint 路径完全不受影响

Test plan

  • npm run build 编译通过
  • 启动实例 A → Chrome 正常启动
  • 启动实例 B → 不报错,自动连接到同一 Chrome
  • 实例 A 和 B 各自可以独立操作不同页面
  • 关闭实例 A → 实例 B 下次调用自动重新启动 Chrome
  • --isolated 模式行为不变

When a second MCP instance attempts to launch Chrome with the same
user data directory, instead of throwing an error, it now automatically
connects to the already-running browser via WebSocket.

- Add --remote-debugging-port=0 on launch so Chrome writes
  DevToolsActivePort with a random local port
- Add connectToExistingBrowser() to read the port file and connect
- Modify catch block to attempt connection before falling back to error
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.

1 participant