Skip to content

fix(extension): retry console capture when a domain enable fails#39

Open
hobostay wants to merge 1 commit into
Tencent:mainfrom
hobostay:fix/console-capture-retry-on-failure
Open

fix(extension): retry console capture when a domain enable fails#39
hobostay wants to merge 1 commit into
Tencent:mainfrom
hobostay:fix/console-capture-retry-on-failure

Conversation

@hobostay

Copy link
Copy Markdown

Problem

enableConsoleDomains marked the tab as attempted before issuing Runtime.enable / Log.enable and swallowed any error:

private async enableConsoleDomains(tabId: number): Promise<void> {
  if (this.consoleDomainsAttemptedTabs.has(tabId)) return;
  this.consoleDomainsAttemptedTabs.add(tabId);          // set BEFORE success
  for (const method of ["Runtime.enable", "Log.enable"]) {
    try {
      await this.api.sendCommand({ tabId }, method, {});
    } catch (err) {
      console.debug("[bsk cdp] console domain enable failed", ...); // swallowed
    }
  }
}

So a transient failure (e.g. a restricted page during attach) permanently disabled console capture for that tab: every later ensureConsoleCapture hit the early return and the agent silently got an empty console buffer, with no indication capture was broken — for the tab's whole lifetime.

This is inconsistent with enableNetworkDomain right next to it, which records the tab only after Network.enable succeeds and is explicitly tested as "retries and surfaces failures" (chromium-cdp.test.ts).

Fix

Record the tab only after both domains enable successfully, so a later ensureConsoleCapture can recover from a transient failure — mirroring enableNetworkDomain exactly:

let failed = false;
for (const method of ["Runtime.enable", "Log.enable"]) {
  try { await this.api.sendCommand({ tabId }, method, {}); }
  catch (err) { failed = true; console.debug(...); }
}
if (!failed) this.consoleDomainsEnabledTabs.add(tabId);

Also renamed the flag consoleDomainsAttemptedTabsconsoleDomainsEnabledTabs to match networkDomainsEnabledTabs and reflect the new (correct) semantics.

Attach stays best-effort: it still succeeds when a domain can't be enabled (console/network are best-effort during attach). The change only affects whether capture can be retried later.

Test

  • Updated the existing "best-effort during attach" test to only assert attach-time behaviour (it previously also asserted the no-retry outcome, which is the behaviour being changed).
  • Added a regression test: Log.enable fails during attach, then ensureConsoleCapture is shown to retry both domains (2 → 4 enable calls). This test fails on the previous code (stays at 2, no retry).

Validation

Frontend CI gates run locally against this branch:

  • pnpm ext:test — 428 passed ✅
  • pnpm --filter @browser-skill/extension compile (tsc --noEmit) ✅
  • pnpm lint (biome + stylelint) ✅
  • pnpm ext:build

🤖 Generated with Claude Code

`enableConsoleDomains` marked the tab in `consoleDomainsAttemptedTabs`
before issuing `Runtime.enable`/`Log.enable` and swallowed any errors,
so a transient failure (e.g. a restricted page during attach)
permanently disabled console capture for that tab: every later
`ensureConsoleCapture` was a no-op and the agent silently got an empty
console buffer with no indication that capture was broken.

This was inconsistent with `enableNetworkDomain`, which records the tab
only after `Network.enable` succeeds (and is explicitly tested as
"retries and surfaces failures"). Bring `enableConsoleDomains` in line:
mark the tab only after both domains enable successfully, so a later
`ensureConsoleCapture` can recover from a transient failure. Renamed
the flag `consoleDomainsAttemptedTabs` -> `consoleDomainsEnabledTabs`
to match `networkDomainsEnabledTabs` and reflect the new semantics.

Attach remains best-effort (it still succeeds when a domain can't be
enabled). Adds a regression test asserting `ensureConsoleCapture`
retries after a failed enable; it fails (no retry) on the previous code.

Co-Authored-By: Claude <noreply@anthropic.com>
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