Skip to content

fix(runtime): honor OPENCLI_CDP_ENDPOINT for non-Electron browser commands#1598

Open
KhanCold wants to merge 1 commit into
jackwener:mainfrom
KhanCold:fix/cdp-endpoint-non-electron
Open

fix(runtime): honor OPENCLI_CDP_ENDPOINT for non-Electron browser commands#1598
KhanCold wants to merge 1 commit into
jackwener:mainfrom
KhanCold:fix/cdp-endpoint-non-electron

Conversation

@KhanCold
Copy link
Copy Markdown

Description

Honor OPENCLI_CDP_ENDPOINT for non-Electron browser commands that were still forcing Browser Bridge.

Previously, OPENCLI_CDP_ENDPOINT was only respected for Electron apps (e.g., Cursor, Codex). Non-Electron browser commands (e.g., opencli youtube, opencli hackernews) always used BrowserBridge, which requires the Chrome extension and fails in headless environments without a GUI.

This PR fixes the routing logic so that when OPENCLI_CDP_ENDPOINT is set, all browser-backed commands route through CDPBridge, enabling headless/remote server usage.

Related issue: #867

Type of Change

  • 🐛 Bug fix

Checklist

  • I ran the checks relevant to this PR
  • I updated tests or docs if needed
  • I included output or screenshots when useful

Changes

src/runtime.ts

  • getBrowserFactory() now accepts an optional cdpEndpoint parameter
  • Returns CDPBridge when cdpEndpoint is provided or OPENCLI_CDP_ENDPOINT env var is set
  • Falls back to existing behavior (Electron check → BrowserBridge) when neither is present

src/execution.ts

  • Non-Electron browser commands now read OPENCLI_CDP_ENDPOINT and pass it to getBrowserFactory()
  • Electron app logic unchanged (still probes endpoint and auto-detects)

src/runtime.test.ts (new)

  • Tests for getBrowserFactory() with cdpEndpoint argument
  • Tests for getBrowserFactory() with OPENCLI_CDP_ENDPOINT env var
  • Tests for Electron app routing (unchanged behavior)
  • Tests for default BrowserBridge routing
  • Tests for whitespace-only env var being ignored

Test Results

$ npx vitest run src/runtime.test.ts
 ✓  unit  src/runtime.test.ts (8 tests) 22ms

$ npx vitest run src/execution.test.ts
 ✓  unit  src/execution.test.ts (22 tests) 113ms

$ npx vitest run src/browser/cdp.test.ts
 ✓  unit  src/browser/cdp.test.ts (2 tests) 8ms

$ npx vitest run src/cli.test.ts
 ✓  unit  src/cli.test.ts (159 tests) 530ms

$ npm run build
✅ Manifest compiled: 815 entries

Screenshots / Output

Before (with OPENCLI_CDP_ENDPOINT set):

$ opencli browser test open https://example.com
# Hangs for 60s then times out — BrowserBridge tries to load extension

After (with OPENCLI_CDP_ENDPOINT set):

$ export OPENCLI_CDP_ENDPOINT="http://127.0.0.1:9222"
$ opencli browser test open https://example.com
# Uses CDPBridge, connects directly to Chrome via CDP

Backward Compatibility

  • No breaking changes
  • Without OPENCLI_CDP_ENDPOINT, behavior is identical to before
  • Electron app auto-launch logic is untouched

…mands

Previously, OPENCLI_CDP_ENDPOINT was only respected for Electron apps.
Non-Electron browser commands (e.g., YouTube, HackerNews) always used
BrowserBridge, which requires the Chrome extension and fails in headless
environments.

Changes:
- getBrowserFactory() now accepts an optional cdpEndpoint parameter and
  returns CDPBridge when a CDP endpoint is provided (via argument or
  OPENCLI_CDP_ENDPOINT env var), regardless of site type.
- execution.ts now passes the CDP endpoint to getBrowserFactory() for
  non-Electron browser commands when OPENCLI_CDP_ENDPOINT is set.

Fixes jackwener#867
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