DEV Community

Discussion on: Generate a PDF in AWS Lambda with NodeJS and Puppeteer

Collapse
 
egatjens profile image
Esteban Gatjens

Hi,
Thanks for the article.
I have an issue where the pdf comes empty randomly, to solve it setContent should wait for everything to be loaded.

await page.setContent(html, { waitUntil: ['load', 'domcontentloaded', 'networkidle0'] });
Enter fullscreen mode Exit fullscreen mode
Collapse
 
akirautio profile image
Aki Rautio

Thanks :) Very good point and interesting find. I haven't seen this when loading html as string but this very well can happen.

WaitUntil is very good to use and even necessary if page itself loads external content.

Collapse
 
yash150411 profile image
Yash Rajesh Dave

i tried following this step but the page of the PDf is still empty

Collapse
 
akirautio profile image
Aki Rautio

Do you have some content that is loaded conditionally and could cause the issue? I have seen that if there is enough long gap between two loading elements, Puppeteer will treat the page final before all the data has been loaded.

Collapse
 
cuchu profile image
Maximiliano Schvindt

Thanks for your comment! I had the same issue trying to run puppeteer in a EC2 linux instance but with your adjust it is working now.