fix: replace networkidle0 with load + image-complete wait for file:// pages

networkidle0 is unreliable for large local documents; explicit image
decode check is more robust.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-04 21:19:55 +02:00
parent f6f15a376e
commit 38ac178ab7
+7 -1
View File
@@ -101,7 +101,13 @@ async function generate() {
page.setDefaultNavigationTimeout(120_000); page.setDefaultNavigationTimeout(120_000);
page.setDefaultTimeout(120_000); page.setDefaultTimeout(120_000);
await page.goto(`file://${inputPath}`, { waitUntil: 'networkidle0', timeout: 120_000 }); await page.goto(`file://${inputPath}`, { waitUntil: 'load', timeout: 120_000 });
// Wait until every <img> has finished decoding (handles large local images)
await page.waitForFunction(
() => [...document.images].every(img => img.complete && img.naturalHeight > 0),
{ timeout: 120_000 },
);
// Write to temp file first so Ghostscript can read it // Write to temp file first so Ghostscript can read it
await page.pdf({ await page.pdf({