You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Second, it intermittently throws an error that I don't expect: Protocol error (Page.captureScreenshot): Unable to capture screenshot
Third, it intermittently throws another that I don't expect: Error: Navigating frame was detached at #onFrameDetached
Intermittently, the screenshot taken is a blank image that does not represent the html at all (<6000 bytes)
This all can be reproduced by deploying the following to AWS Lambda using node 18 or 20 runtime:
importnodeHtmlToImagefrom"node-html-to-image";importpuppeteerCorefrom"puppeteer-core";importchromiumfrom"@sparticuz/chromium-min";exportconsthandler=async(event: any,context: any,callback: (err: any,response: any)=>void,)=>{constexecutablePath=awaitchromium.executablePath("https://github.com/Sparticuz/chromium/releases/download/v119.0.2/chromium-v119.0.2-pack.tar",)!;consthtml=` <html> <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" /> </head> <style> body { width: 1200px; height: 800px; } .content { position: absolute; left: 50%; top: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); } </style> <body style=" background-size: cover; " > <div class="content"> <h1 style="font-size: 100px">Hello World</h1> </div> </body></html>`try{for(leti=0;i<10;i++){constnodeHtmlToImageResponse=awaitnodeHtmlToImage({type: "png",
html,waitUntil: "networkidle0",puppeteer: puppeteerCore,puppeteerArgs: {args: [...chromium.args,"--disable-features=site-per-process",'--no-sandbox','--disable-setuid-sandbox','--disable-dev-shm-usage','--disable-accelerated-2d-canvas','--no-first-run','--no-zygote','--single-process','--disable-gpu'],headless: true,
executablePath,defaultViewport: {width: 1200,height: 800,},},});console.log({nodeHtmlToImageResponse});}}catch(e){// This cannot catch the following errors:// > Error: Navigating frame was detached at #onFrameDetached// > Protocol error (Page.captureScreenshot): Unable to capture screenshot// Instead, these cause runtime to exit with catch block never ran// > Runtime exited with error: exit status 1 Runtime.ExitError// Additionally, sometimes there is no error but the screenshot is erroneously blank (<3000 bytes)consterr=(easError).message;consterrorResponse={statusCode: 500,body: JSON.stringify({message: "screenshot failed",reason: err,}),};console.error({ errorResponse });returncallback(null,errorResponse);}constresponse={statusCode: 200,body: JSON.stringify({message: "screenshot successful!",}),};console.log({ response });returncallback(null,response);};
Once deployed, put the lambda on a cron trigger to run every few minutes. The errors are intermittent, but it doesn't take long to start seeing them in your lambda execution logs. Note that the catch block never hits - the unexpected failures within nodeHtmlToImage kill the lambda runtime completely without being catchable.
The text was updated successfully, but these errors were encountered:
This looks to be the culprit. This library is exiting the process on unexpected errors in the cluster. This is very unexpected behavior. I'll put in a PR sometime this week if I can find the time.
This issue is actually 4 issues.
nodeHtmlToImage
in a try/catch, some errors slip though going uncaught. See Catch puppeteer errors not possible? #165Protocol error (Page.captureScreenshot): Unable to capture screenshot
Error: Navigating frame was detached at #onFrameDetached
This all can be reproduced by deploying the following to AWS Lambda using node 18 or 20 runtime:
Once deployed, put the lambda on a cron trigger to run every few minutes. The errors are intermittent, but it doesn't take long to start seeing them in your lambda execution logs. Note that the
catch
block never hits - the unexpected failures withinnodeHtmlToImage
kill the lambda runtime completely without being catchable.The text was updated successfully, but these errors were encountered: