Skip to content

feat(browser): add CDP remote connection support for server environments#23

Closed
ByteYue wants to merge 3 commits intojackwener:mainfrom
ByteYue:feat/cdp-remote-connection
Closed

feat(browser): add CDP remote connection support for server environments#23
ByteYue wants to merge 3 commits intojackwener:mainfrom
ByteYue:feat/cdp-remote-connection

Conversation

@ByteYue
Copy link
Contributor

@ByteYue ByteYue commented Mar 16, 2026

This feature enables OpenCLI to connect to a Chrome browser running on a different machine (e.g., your local computer) from a headless server environment via Chrome DevTools Protocol (CDP).

Motivation

Server environments (CI, cloud VMs, headless Linux) cannot run Chrome with a GUI or install the Playwright MCP Bridge extension. This makes it impossible to use OpenCLI commands that require browser authentication.

Solution

Add support for the OPENCLI_CDP_ENDPOINT environment variable, which tells OpenCLI to connect to a remote Chrome instance via CDP instead of using the local extension mode.

Usage

  1. Start Chrome with remote debugging on local machine: chrome --remote-debugging-port=9222 --user-data-dir="$HOME/chrome-debug"

  2. Create SSH tunnel to forward port to server: ssh -R 9222:localhost:9222 your-server

  3. Run OpenCLI on server: export OPENCLI_CDP_ENDPOINT="http://localhost:9222" opencli bilibili hot --limit 5

Changes

  • src/browser.ts: Add CDP endpoint detection in buildMcpArgs()
  • src/doctor.ts: Show CDP mode status in doctor report
  • README.md: Add "Remote Chrome (Server/Headless)" section
  • README.zh-CN.md: Add corresponding Chinese documentation

🤖 Generated with Claude Code

@ByteYue ByteYue force-pushed the feat/cdp-remote-connection branch from 910aec8 to 19c3062 Compare March 16, 2026 15:18
@jackwener jackwener force-pushed the feat/cdp-remote-connection branch 2 times, most recently from 714027b to 0367673 Compare March 16, 2026 16:22
ByteYue and others added 2 commits March 17, 2026 22:30
This feature enables OpenCLI to connect to a Chrome browser running on a
different machine (e.g., your local computer) from a headless server
environment via Chrome DevTools Protocol (CDP).

Server environments (CI, cloud VMs, headless Linux) cannot run Chrome with
a GUI or install the Playwright MCP Bridge extension. This makes it
impossible to use OpenCLI commands that require browser authentication.

Add support for the `OPENCLI_CDP_ENDPOINT` environment variable, which
tells OpenCLI to connect to a remote Chrome instance via CDP instead of
using the local extension mode.

1. Start Chrome with remote debugging on local machine:
   ```
   chrome --remote-debugging-port=9222 --user-data-dir="$HOME/chrome-debug"
   ```

2. Create SSH tunnel to forward port to server:
   ```
   ssh -R 9222:localhost:9222 your-server
   ```

3. Run OpenCLI on server:
   ```
   export OPENCLI_CDP_ENDPOINT="http://localhost:9222"
   opencli bilibili hot --limit 5
   ```

- src/browser.ts: Add CDP endpoint detection in buildMcpArgs()
- src/doctor.ts: Show CDP mode status in doctor report
- README.md: Add "Remote Chrome (Server/Headless)" section
- README.zh-CN.md: Add corresponding Chinese documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This adds support for reading DevToolsActivePort (Chrome 144+) when OPENCLI_CDP_ENDPOINT=1, and fixes a bug where CDP connection failures were incorrectly reported as missing extension tokens.
@ByteYue ByteYue force-pushed the feat/cdp-remote-connection branch from 0367673 to b8ca5f3 Compare March 17, 2026 14:36
…nd classic CDP modes

- Document two connection methods: Chrome 144+ (no restart, ws://) and
  classic --remote-debugging-port (any version, http://)
- Add DevToolsActivePort file paths for all platforms (macOS, Linux,
  Windows) and browsers (Chrome, Chromium, Edge)
- Add environment variable reference table (OPENCLI_CDP_ENDPOINT,
  CHROME_USER_DATA_DIR)
- Add buildMcpArgs CDP unit test covering ws:// and http:// endpoints
- Update both README.md and README.zh-CN.md
@ByteYue
Copy link
Contributor Author

ByteYue commented Mar 18, 2026

#52 includes this pr

@ByteYue ByteYue closed this Mar 18, 2026
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