Skip to content

OPENCLI_CDP_ENDPOINT only works for Electron apps, ignored for cookie-mode sites like YouTube #867

@pedh

Description

@pedh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions