jackwener/OpenCLI · error · CommandExecutionError

Gmail ${operation} could not start browser response intercep

Error message

Gmail ${operation} could not start browser response interception

What it means

installGmailCapture throws this CommandExecutionError when page.startNetworkCapture exists but returns falsy, meaning the browser failed to arm interception for /sync/u/{account}/i/{endpoint}. The library refuses to continue because subsequent capture reads would silently return nothing.

Source

Thrown at clis/gmail/utils.js:297

    await page.goto(`${GMAIL_ORIGIN}/mail/u/${account}/#inbox`);
  }
  for (let attempt = 0; attempt < 60; attempt += 1) {
    const ready = unwrapBrowserResult(await page.evaluate(`() => !!document.querySelector('input[name="q"]')`), `${operation} readiness probe`);
    if (ready === true) return;
    await page.sleep(0.5);
  }
  throw new TimeoutError(`Gmail ${operation} page`, 30, 'The Gmail search surface did not become ready. Reload Gmail in the browser and retry.');
}

async function installGmailCapture(page, account, endpoint, operation) {
  if (
    typeof page?.startNetworkCapture !== 'function'
    || typeof page?.readNetworkCapture !== 'function'
  ) {
    throw new CommandExecutionError(`Gmail ${operation} requires browser response interception`);
  }
  if (!await page.startNetworkCapture(`/sync/u/${account}/i/${endpoint}`)) {
    throw new CommandExecutionError(`Gmail ${operation} could not start browser response interception`);
  }
  await page.readNetworkCapture();
}

async function waitGmailCaptures(page, endpoint, operation, timeoutSeconds = CAPTURE_WAIT_SECONDS) {
  const deadline = Date.now() + timeoutSeconds * 1000;
  let bodylessCaptureObserved = false;
  // The bridge capture queue is request-oriented: reading it while a response
  // is still in flight drains that request before its status/body arrive.
  // Give Gmail's own action time to settle before the first read.
  await page.sleep(endpoint === 'fd' ? 1 : 3);
  while (Date.now() < deadline) {
    const entries = await page.readNetworkCapture();
    const endpointEntries = (Array.isArray(entries) ? entries : [])
      .filter((entry) => String(entry?.url || '').includes(`/i/${endpoint}`));
    if (endpointEntries.some((entry) => (
      typeof entry?.responsePreview !== 'string'
      && entry?.responseBodyTruncated !== true

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the operation after confirming the browser/page is still open and responsive
  2. Recreate the page (close and reopen) so interception can be re-armed on a fresh target
  3. Update the browser automation driver to a version that supports response interception for the pattern used
  4. Reduce concurrent operations on the same page that may conflict over CDP interception
Defensive patterns

Strategy: retry

Validate before calling

if (typeof page?.startNetworkCapture !== 'function') throw new Error('capture API unavailable');
if (!(await page.startNetworkCapture('/sync/u/0/i/s'))) throw new Error('pre-flight interception failed; restart the page');

Try / catch

try {
  await fetchThread(page, 0, threadId);
} catch (e) {
  if (/could not start browser response interception/.test(e.message)) {
    page = await reopenPage(browser); // fresh target, re-arm interception
    await fetchThread(page, 0, threadId);
  } else throw e;
}

Prevention

When it happens

Trigger: page.startNetworkCapture('/sync/u/<account>/i/<endpoint>') resolves false: CDP Fetch/Network domain enable failed, the page is in a broken/closed state, or the driver rejected the interception pattern.

Common situations: CDP connection dropped mid-session (browser crashed or was closed); Puppeteer/Playwright version where the interception request pattern is rejected; too many concurrent interception handlers; page navigated away between checks.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/084694a147a6f4df. Report an issue: GitHub.