{"record":{"id":"91a26aa4308ebc2f","repo":"jackwener/OpenCLI","slug":"gmail-operation-response-exceeded-the-browser-c","errorCode":null,"errorMessage":"Gmail ${operation} response exceeded the browser capture limit","messagePattern":"Gmail (.+?) response exceeded the browser capture limit","errorType":"error_code","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gmail/utils.js","lineNumber":100,"sourceCode":"    .replace(/<br\\s*\\/?\\s*>/gi, '\\n')\n    .replace(/<\\/(p|div|li|tr|h[1-6])>/gi, '\\n')\n    .replace(/<[^>]+>/g, ' '))\n    .replace(/[ \\t]+/g, ' ')\n    .replace(/ *\\n */g, '\\n')\n    .replace(/\\n{3,}/g, '\\n\\n')\n    .trim();\n}\n\nfunction parseJsonCapture(entry, operation) {\n  const status = Number(entry?.responseStatus || 0);\n  if (status === 401 || status === 403) {\n    throw new AuthRequiredError(GMAIL_HOST, `Gmail ${operation} returned HTTP ${status}`);\n  }\n  if (status !== 200) {\n    throw new CommandExecutionError(`Gmail ${operation} returned HTTP ${status || 'unknown'}`);\n  }\n  if (entry?.responseBodyTruncated === true) {\n    throw new CommandExecutionError(`Gmail ${operation} response exceeded the browser capture limit`);\n  }\n  const body = entry?.responsePreview;\n  if (Array.isArray(body)) return body;\n  if (typeof body !== 'string') {\n    throw new CommandExecutionError(`Gmail ${operation} response body was unavailable`);\n  }\n  try {\n    const parsed = JSON.parse(body.replace(/^\\)\\]\\}'\\s*/, ''));\n    if (!Array.isArray(parsed)) throw new Error('not an array');\n    return parsed;\n  } catch {\n    throw new CommandExecutionError(`Gmail ${operation} returned malformed JSON`);\n  }\n}\n\nfunction addressRef(value) {\n  if (!Array.isArray(value)) return null;\n  const address = cleanString(value[1]);","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gmail/utils.js#L82-L118","documentation":"This CommandExecutionError is thrown by parseJsonCapture when the browser-bridge network capture for a Gmail /sync response has responseBodyTruncated === true, meaning the response body exceeded the capture buffer (MAX_BODY_CHARS / bridge capture limit) and was cut off. The library refuses to parse a truncated body because partial JSON would silently drop threads or messages. It is thrown before any parsing is attempted.","triggerScenarios":"waitGmailCaptures receives a capture entry for /i/bv or /i/fd whose body was truncated by the bridge; typically a query returning a very large page (limit near MAX_LIMIT=200, huge threads, wide search like in:anywhere) so the /sync/u/<account>/i/bv or /i/fd response exceeds the capture limit.","commonSituations":"Listing or searching large mailboxes (hundreds of threads per page), fetching threads with very long HTML bodies or many attachments, low bridge capture-size configuration, older bridge versions with smaller capture buffers.","solutions":["Reduce the requested limit (e.g. --limit 20 instead of 200) and paginate instead of pulling one huge page.","Narrow the search query (add is:unread, after:, label:, or sender filters) so each response page is smaller.","Retry the operation; on a fresh page load Gmail may return a smaller/simpler response.","Update the browser bridge / opencli to a version with a larger capture buffer (MAX_BODY_CHARS)."],"exampleFix":"// before\nawait queryThreads(page, 'in:anywhere', { account: 0, limit: 200 });\n// after\nawait queryThreads(page, 'in:anywhere newer_than:30d', { account: 0, limit: 50 }); // paginate instead","handlingStrategy":"retry","validationCode":"// keep the requested page small before calling\nconst limit = Math.min(userLimit, 50);\nif (!/\\b(is:|after:|before:|label:|from:)/.test(query) && limit > 50) {\n  throw new Error('Broad query with large limit will overflow the capture buffer; narrow the query or lower the limit');\n}","typeGuard":"function isCompleteCapture(entry) {\n  return Boolean(entry) && entry.responseBodyTruncated !== true\n    && (typeof entry.responsePreview === 'string' || Array.isArray(entry.responsePreview));\n}","tryCatchPattern":"try {\n  threads = await queryThreads(page, query, { limit });\n} catch (error) {\n  if (error instanceof CommandExecutionError && String(error.message).includes('capture limit')) {\n    threads = await queryThreads(page, query, { limit: Math.ceil(limit / 4) }); // retry with smaller pages\n  } else throw error;\n}","preventionTips":["Keep per-call limits modest (<=50) and paginate instead of pulling 200 threads at once.","Always constrain broad queries (in:anywhere) with date or label filters.","Run an up-to-date browser bridge with the largest capture buffer.","Watch for this error right after increasing limit — it is a size signal, not a bug."],"tags":["gmail","browser-bridge","truncated-response","network-capture"],"backgroundTag":"response-body-truncated","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}