Skip to content

Commit cd6681e

Browse files
committed
Make font loading more reliable
1 parent e4fb36f commit cd6681e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/utils/pdf.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function convertHtmlToPdf(
7171
maybeSetDefaultNavTimeout.setDefaultNavigationTimeout?.(navigationTimeout);
7272

7373
try {
74-
await page.setContent(finalHtml, { waitUntil: "networkidle2", timeout: navigationTimeout });
74+
await page.setContent(finalHtml, { waitUntil: "networkidle0", timeout: navigationTimeout });
7575
} catch (err) {
7676
// If setContent times out, warn and continue: in CI some external requests
7777
// (fonts, images) may hang or be blocked and we still want to produce a PDF.
@@ -83,6 +83,15 @@ export async function convertHtmlToPdf(
8383
}
8484
}
8585

86+
// Wait for fonts to load before generating PDF
87+
try {
88+
// @ts-expect-error Suppressing type error for evaluate context
89+
// eslint-disable-next-line no-undef
90+
await page.evaluate(() => document.fonts.ready);
91+
} catch (err) {
92+
console.warn("Warning: failed to wait for fonts - continuing anyway:", err);
93+
}
94+
8695
await page.pdf({
8796
path: outputFilePath,
8897
format: "A4",

0 commit comments

Comments
 (0)