vercel / pkg

Package your Node.js project into an executable
https://npmjs.com/pkg
MIT License
24.28k stars 1.01k forks source link

Puppeteer not waiting for images to load before sending the pdf buffer as response #1978

Closed anvaymishra1 closed 9 months ago

anvaymishra1 commented 1 year ago

What version of pkg are you using?

5.8.1

What version of Node.js are you using?

18.17.1

What operating system are you using?

Debian GNU/Linux 12

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

node18-linux-x64

Describe the Bug

The code runs perfectly with all the configurations when I have not created the build i.e. the function waits for all the images to render in the dom and then prints the PDF which is the expected behaviour.

When I make the binary and run on the same amount of data. The report gets downloaded but it does not wait for all the images to render. It waits for 2-3 seconds and then generates the pdf.

I tried setting timeouts to inside the function to make it wait which works before creating the build but in the build it doesn't.

Expected Behavior

await page.evaluate(() => { return new Promise((resolve) => { const checkImagesLoaded = () => { const images = Array.from(document.images); console.log(images.length) if (images.every(img => img.complete && img.naturalWidth > 0)) { resolve(); } else { setTimeout(checkImagesLoaded, 10000); // Adjust the interval as needed } }; checkImagesLoaded(); }); });

This function waits for all the images to render in the dom before proceeding to send the response. Which works before packaging it as a build.

To Reproduce

Try creating a pdf from any HTML file with around 200 images in it.

github-actions[bot] commented 9 months ago

This issue is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 5 days. To ignore this issue entirely you can add the no-stale label

github-actions[bot] commented 9 months ago

This issue is now closed due to inactivity, you can of course reopen or reference this issue if you see fit.