File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,7 +124,8 @@ describe("pdf utils", () => {
124124 </body>
125125</html>` ;
126126 expect ( mockPage . setContent ) . toHaveBeenCalledWith ( expectedHtml , {
127- waitUntil : "networkidle0" ,
127+ timeout : 60000 ,
128+ waitUntil : "networkidle2" ,
128129 } ) ;
129130 expect ( mockPage . pdf ) . toHaveBeenCalledWith ( {
130131 path : outputFilePath ,
Original file line number Diff line number Diff line change @@ -60,7 +60,28 @@ export async function convertHtmlToPdf(
6060 }
6161 }
6262
63- await page . setContent ( finalHtml , { waitUntil : "networkidle0" } ) ;
63+ // Use a slightly more permissive network idle and increase the timeout to
64+ // avoid flaky CI failures when external resources are slow or blocked.
65+ // Also set a default navigation timeout on the page so Puppeteer's internal
66+ // navigation watchers use the same timeout value.
67+ const navigationTimeout = 60000 ; // 60s
68+ const maybeSetDefaultNavTimeout = page as unknown as {
69+ setDefaultNavigationTimeout ?: ( t : number ) => void ;
70+ } ;
71+ maybeSetDefaultNavTimeout . setDefaultNavigationTimeout ?.( navigationTimeout ) ;
72+
73+ try {
74+ await page . setContent ( finalHtml , { waitUntil : "networkidle2" , timeout : navigationTimeout } ) ;
75+ } catch ( err ) {
76+ // If setContent times out, warn and continue: in CI some external requests
77+ // (fonts, images) may hang or be blocked and we still want to produce a PDF.
78+ const msg = err instanceof Error ? err . message : String ( err ) ;
79+ if ( / N a v i g a t i o n t i m e o u t | T i m e o u t E r r o r / i. test ( msg ) ) {
80+ console . warn ( "Warning: page.setContent timed out - continuing without full network idle." ) ;
81+ } else {
82+ throw err ;
83+ }
84+ }
6485
6586 await page . pdf ( {
6687 path : outputFilePath ,
You can’t perform that action at this time.
0 commit comments