{"record":{"id":"b86842692f4e5085","repo":"santifer/career-ops","slug":"page-cleanup-failed-err-message","errorCode":null,"errorMessage":"⚠️  Page cleanup failed: ${err.message}","messagePattern":"⚠️  Page cleanup failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"generate-pdf.mjs","lineNumber":1799,"sourceCode":"    console.log(`📊 Pages: ${pageCount}`);\n    console.log(`📦 Size: ${(pdfBuffer.length / 1024).toFixed(1)} KB`);\n\n    try {\n      updatePDFManifest(reportNum, outputPath, inputPath, format);\n      console.log(`🔗 Manifest: data/pdf-index.tsv updated${reportNum ? ` (report ${reportNum})` : ' (no --report given)'}`);\n    } catch (err) {\n      // The PDF itself succeeded — never fail the run over manifest bookkeeping.\n      console.error(`⚠️  Manifest update failed: ${err.message}`);\n    }\n\n    return { outputPath, pageCount, size: pdfBuffer.length };\n  } finally {\n    // Close the page so a batch does not accumulate pages into the shared\n    // browser (leak → OOM). Optional-chained: the single path's browser.close()\n    // already reclaims the page, and minimal test doubles may omit close().\n    if (page && typeof page.close === 'function') {\n      await page.close().catch((err) => {\n        console.warn(`⚠️  Page cleanup failed: ${err.message}`);\n      });\n    }\n    // Close the per-document context too, so the JS-disabled context created\n    // above does not accumulate in the shared browser across a batch (#2384).\n    if (context && typeof context.close === 'function') {\n      await context.close().catch((err) => {\n        console.warn(`⚠️  Context cleanup failed: ${err.message}`);\n      });\n    }\n    // Clean up temp file\n    await unlink(tmpHtmlPath).catch((err) => {\n      if (err?.code !== 'ENOENT') {\n        console.warn(`⚠️  Temporary HTML cleanup failed: ${err.message}`);\n      }\n    });\n  }\n}\n","sourceCodeStart":1781,"sourceCodeEnd":1817,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/generate-pdf.mjs#L1781-L1817","documentation":"Warning logged when closing the Playwright Page after a PDF render rejects. It lives in a finally block so page teardown failures never mask the render result; the page is closed to keep shared batch browsers from accumulating pages and leaking memory into OOM.","triggerScenarios":"page.close() rejects in the finally of renderInPage batching — page already crashed (target closed), browser connection lost before the page could be closed, or a minimal test double implementing the page without a working close().","commonSituations":"Long batch runs where an earlier render crashed the shared browser; page killed by navigation abort or timeout; unit tests injecting stub page objects whose close() throws.","solutions":["Treat as benign when the batch result is intact — the browser.close() in the same finally reclaims the page","Verify no renderer crash preceded it (check earlier console output for 'Target crashed')","Update Playwright and Chromium deps if crashes repeat","In tests, provide doubles whose close() resolves or omit close() entirely (the typeof guard already skips function-less doubles)"],"exampleFix":"// before\nawait page.close().catch((err) => console.warn(`⚠️  Page cleanup failed: ${err.message}`));\n// after\nawait page.close().catch((err) => {\n  if (!err.message.includes('Target closed')) {\n    console.warn(`⚠️  Page cleanup failed: ${err.message}`);\n  }\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"if (page && typeof page.close === 'function') { /* safe to close */ }","tryCatchPattern":"await page.close().catch((err) => {\n  if (!/Target closed|Connection closed/i.test(err.message)) {\n    console.warn(`Page cleanup failed: ${err.message}`);\n  }\n});","preventionTips":["Always close pages in finally blocks when sharing one browser across a batch","Provide complete test doubles (or none) so the typeof close() guard behaves predictably","Restart the shared browser periodically in long batch runs","Monitor the first error in a batch — later teardown warnings are usually its fallout"],"tags":["playwright","page","cleanup","batch"],"backgroundTag":"browser-cleanup-failed","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}