{"record":{"id":"3b2b22ed1ac80555","repo":"can1357/oh-my-pi","slug":"timed-out-rendering-pdf-page-page-in-chromium","errorCode":null,"errorMessage":"Timed out rendering PDF page ${page} in Chromium.","messagePattern":"Timed out rendering PDF page (.+?) in Chromium\\.","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/read-pdf.ts","lineNumber":133,"sourceCode":"\t\t\t}),\n\t\t);\n\t\ttabOpened = true;\n\t\tawait releaseBrowser(acquiredBrowser, { kill: false });\n\t\tbrowserLease = false;\n\n\t\tconst result = await runInTab(tabName, {\n\t\t\tcode: PDF_SCREENSHOT_CODE,\n\t\t\ttimeoutMs: PDF_RENDER_TIMEOUT_MS,\n\t\t\tsignal: renderSignal,\n\t\t\tsession,\n\t\t});\n\t\tconst screenshot = result.screenshots.at(-1);\n\t\tif (!screenshot) throw new ToolError(`Chromium did not capture PDF page ${page}.`);\n\t\treturn screenshot;\n\t} catch (error) {\n\t\tif (signal?.aborted) throw new ToolAbortError();\n\t\tif (timeoutSignal.aborted) {\n\t\t\tthrow new ToolError(`Timed out rendering PDF page ${page} in Chromium.`);\n\t\t}\n\t\tthrow error;\n\t} finally {\n\t\tif (tabOpened) await releaseTab(tabName, { kill: false });\n\t\tif (browserLease && browser) await releaseBrowser(browser, { kill: false });\n\t}\n}\n","sourceCodeStart":115,"sourceCodeEnd":141,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/read-pdf.ts#L115-L141","documentation":"renderPdfPageScreenshot enforces PDF_RENDER_TIMEOUT_MS via AbortSignal.timeout. If acquiring Chromium, opening the PDF tab, or running the screenshot code exceeds that budget, the catch block detects timeoutSignal.aborted and throws a ToolError 'Timed out rendering PDF page N in Chromium.' It means the headless browser pipeline did not produce a capture in time.","triggerScenarios":"Cold Chromium download/startup takes too long; the PDF viewer page never reaches 'load'; the PDF page is huge/complex so the screenshot script runs past PDF_RENDER_TIMEOUT_MS; acquireTab's shared deadline (deadlineStartMs) is exhausted.","commonSituations":"First-ever PDF read in an environment where Chromium must be fetched; slow or resource-starved CI containers; very large scanned PDFs; browser registry contention delaying acquisition.","solutions":["Retry the read — a warm browser usually renders well within the timeout.","Pre-warm the headless browser before batch PDF processing.","Verify Chromium is installed/downloaded locally so startup isn't dominated by download.","Check machine CPU/memory pressure; headless rendering is CPU-bound.","If it persists, split the PDF and read fewer/smaller pages per call."],"exampleFix":"// before: unbounded single attempt\nconst shot = await renderPdfPageScreenshot(session, pdfPath, page);\n// after: warm retry\ntry { shot = await renderPdfPageScreenshot(session, pdfPath, page); }\ncatch (e) {\n  if (String(e).includes('Timed out rendering PDF page')) {\n    await warmBrowser(session); // second attempt reuses warm browser\n    shot = await renderPdfPageScreenshot(session, pdfPath, page);\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":"// pre-flight: ensure a browser is available before the timed render\nconst browser = await acquireBrowser({ kind: 'headless', headless: true }, { cwd, signal });\nawait releaseBrowser(browser, { kill: false }); // warm the registry","typeGuard":null,"tryCatchPattern":"try {\n  return await renderPdfPageScreenshot(session, pdfPath, page, signal);\n} catch (e) {\n  if (e instanceof ToolError && /Timed out rendering PDF page/.test(e.message)) {\n    await Bun.sleep(500); // warm browser, then one retry\n    return await renderPdfPageScreenshot(session, pdfPath, page, signal);\n  }\n  throw e;\n}","preventionTips":["Pre-warm the headless browser before processing many PDFs.","Avoid first-run environments where Chromium must be downloaded on demand.","Render on a machine with adequate CPU/RAM; headless rendering is CPU-bound.","Split huge PDFs; render fewer pages per call."],"tags":["timeout","pdf","chromium","browser"],"backgroundTag":"headless-browser-timeout","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}