OPENCLI_CDP_ENDPOINT only works for Electron apps, ignored for cookie-mode sites like YouTube
- Dominant language
- JavaScript
- Stars
- 29.5k
- Forks
- 2.9k
- Avg merge
- 15h 36m
- Merged PRs (30d)
- 70
Description
## Bug Description
When `OPENCLI_CDP_ENDPOINT` is set, opencli correctly uses CDP for Electron apps, but ignores it for non-Electron sites that require browser sessions (cookie mode). Commands like `opencli youtube search` still force the Browser Bridge extension and fail with:
\`\`\`
🔌 Browser Bridge not connected
Daemon ✓ running
Extension ✗ not connected
\`\`\`
## Root Cause
Two places in the code only check `OPENCLI_CDP_ENDPOINT` for Electron apps:
**1. `dist/src/runtime.js` — \`getBrowserFactory()\`**
\`\`\`js
export function getBrowserFactory(site) {
if (site && isElectronApp(site))
return CDPBridge; // only Electron → CDPBridge
return BrowserBridge; // everything else → requires extension
}
\`\`\`
**2. `dist/src/execution.js` — browser session setup**
\`\`\`js
const electron = isElectronApp(cmd.site);
let cdpEndpoint;
if (electron) {
// Only checks OPENCLI_CDP_ENDPOINT here
const manualEndpoint = process.env.OPENCLI_CDP_ENDPOINT;
...
} else {
// Non-Electron: throws if extension not connected
throw new BrowserConnectError("Browser Bridge extension not connected", ...);
}
\`\`\`
## Expected Behavior
When `OPENCLI_CDP_ENDPOINT` is set, it should work for **all** browser-based commands, not just Electron apps. The CDP endpoint is designed to reuse an already-authenticated browser instance — that is the whole point of it.
## Reproduction
\`\`\`bash
export OPENCLI_CDP_ENDPOINT="http://localhost:9222"
opencli youtube search opencli
# → "Browser Bridge not connected" (exit code 69)
\`\`\`
## Proposed Fix
**runtime.js:**
\`\`\`js
export function getBrowserFactory(site) {
if (process.env.OPENCLI_CDP_ENDPOINT)
return CDPBridge;
if (site && isElectronApp(site))
return CDPBridge;
return BrowserBridge;
}
\`\`\`
**execution.js:**
\`\`\`js
const electron = isElectronApp(cmd.site);
const manualEndpoint = process.env.OPENCLI_CDP_ENDPOINT;
let cdpEndpoint;
if (manualEndpoint) {
const port = Number(new URL(manualEndpoint).port);
if (!await probeCDP(port)) {
throw new CommandExecutionError(...);
}
cdpEndpoint = manualEndpoint;
} else if (electron) {
cdpEndpoint = await resolveElectronEndpoint(cmd.site);
} else {
// Browser Bridge: only require extension when no CDP endpoint
...
}
\`\`\`
## Impact
This makes `OPENCLI_CDP_ENDPOINT` unusable for any non-Electron site (YouTube, Twitter, etc.), which defeats the purpose of CDP mode — reusing an already-logged-in browser without installing the extension.
Contributor guide
Research direction
Start with getBrowserFactory() in dist/src/runtime.js and the browser session setup in dist/src/execution.js, then run the documented YouTube reproduction with OPENCLI_CDP_ENDPOINT set. Done means non-Electron browser commands use the configured CDP endpoint without requiring the Browser Bridge extension, while Electron behavior remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100