Skip to content

feat(connect): honor BU_CDP_WS env var in session.connect()#45

Merged
Alezander9 merged 1 commit intomainfrom
feat/connect-bu-cdp-ws-env
May 9, 2026
Merged

feat(connect): honor BU_CDP_WS env var in session.connect()#45
Alezander9 merged 1 commit intomainfrom
feat/connect-bu-cdp-ws-env

Conversation

@Alezander9
Copy link
Copy Markdown
Member

Why

Eval harnesses and CI need to hand the agent a preconfigured browser without burying the WS URL in the prompt. The pre-port Python harness honored BU_CDP_WS for exactly this; v0.1.0 lost it during the TS port. Re-adopting the same convention.

What

When session.connect() is called with no args, check BU_CDP_WS (and alias BU_CDP_URL) before the OS scan:

async connect(opts: ConnectOptions = {}): Promise<void> {
  const timeoutMs = opts.timeoutMs ?? 5_000
  if (opts.wsUrl || opts.profileDir) { /* unchanged */ }
  const envWsUrl = process.env.BU_CDP_WS ?? process.env.BU_CDP_URL
  if (envWsUrl) {
    await this.openWs(envWsUrl, timeoutMs)
    return
  }
  /* unchanged OS scan */
}

Explicit { wsUrl } / { profileDir } calls ignore the env var. If the env var is set but the endpoint is unreachable, the error surfaces rather than silently falling through to OS scan — matches Python harness PR #300, which closed exactly that hole (was billing for a cloud browser while silently using a local Chrome).

Scope

  • packages/bcode-browser/src/cdp/session.ts — ~5 line addition in connect(), doc-comment expanded to spell out the precedence.
  • packages/bcode-browser/skills/BROWSER.md — one-paragraph note under "Connecting".
  • packages/bcode-browser/test/connect-env.test.ts — 4 tests covering: BU_CDP_WS path, BU_CDP_URL alias, explicit-opts-override-env, fail-fast on stale env URL. Uses a tiny Bun.serve WS upgrade endpoint; no Chrome needed.

+117 lines, mostly the new test file.

Verified

  • bun typecheck clean from packages/bcode-browser/ and from repo root (filtered turbo run).
  • bun test from packages/bcode-browser/: 12 pass + 5 chrome-gated skip (was 8 + 5; +4 from this PR).

Eval team usage

export BU_CDP_WS=ws://path-to-preconfigured-browser/devtools/browser/<uuid>
bcode --prompt "do the eval task"

The agent's natural snippet await session.connect() lands on the eval browser. No prompt boilerplate, no skill changes per-eval, no risk of the model picking a different browser.

Eval harnesses and CI need to hand the agent a preconfigured browser
without putting the WS URL in the prompt. Restores the convention from
the pre-port Python harness: when `BU_CDP_WS` (or alias `BU_CDP_URL`)
is set, no-args `session.connect()` connects there directly, ahead of
OS scan. Explicit { wsUrl } / { profileDir } calls ignore the env var.

If the env var is set but unreachable, surface the error rather than
silently falling through to OS scan — matches Python harness PR #300
which closed the same hole.

- src/cdp/session.ts: env-var precedence in connect(), ~5 lines.
- skills/BROWSER.md: one-paragraph note under Connecting.
- test/connect-env.test.ts: 4 tests covering precedence, fallback, override.

Verified: bun typecheck clean, bun test 12 pass + 5 chrome-gated skip
(was 8 + 5 baseline; +4 from the new tests).
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@Alezander9 Alezander9 merged commit 8e84726 into main May 9, 2026
3 checks passed
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