Reputation: 1428
The page running inside puppeteer download images. When calling page.evaluate
, some of the images must be written to disk before doing other operations on them.
What's the best way to do this? Be able to write those images from the browser running in puppeteer? Send buffers from puppeteer to node.js?
NOTE: some of these images might be result canvas operations, so they're not necessary the result of a request.
Upvotes: 1
Views: 354
Reputation: 2525
There is a few possible solutions:
1. If the page allows cors, you can send those images to your backend server. Use something like fetch
2. Another option is to get all images from page and pass them back to server. Here is also a few possible implementations:
2.1. You can get all image urls with something like this return JSON.stringify(Array.from(document.querySelectorAll('img'), i => i.src))
and then download them directly to your server.
2.2. Put image to canvas, and then use toDataUrl()
to get base64 encoded data, which you could then pass and process on backend. More info here and here is about saving base64 data on disk
P.S. Just remember to JSON.stringify()
your data when returning from puppeteer to backend, because puppeteer could not process the data.
Upvotes: 1