Haven’t tried it in a Meteor env yet, but in a standard nodejs/express env.
I would just install https://github.com/GoogleChrome/puppeteer and use it on the server to create PDFs and either stream them to the client or just save it on the server and open it via a server route. Shouldn’t be too hard I guess or maybe I am missing something …
FYI - puppeteer is awesome, and works great locally - but - Galaxy has trouble running it inside Docker containers. I don’t have a solution for this, just mentioning it for those looking into the same problem.
Hi, could you please indicate how did you solve that issue?
I’m starting a migration of a project using Nightmare.js to Puppeteer and I having the same issue in meteor. In node.js works fine.
Thanks!
Hey, hard reset of the project helped i.e., meteor reset. Also, make sure you install puppeteer, like so meteor npm install --save puppeteer. Then, simply use it in an async method on your server.
I’m trying to use Puppeteer / headless Chrome in a METEOR@1.6.1 project.
I’ve installed puppeteer using: meteor npm install --save puppeteer
When I run my app, after 30 seconds it crashes with this error: (node:13927) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Navigation Timeout Exceeded: 30000ms exceeded
I have not run any Puppeteer script. All I have done is install Puppeteer and run my app as usual. So it seems Puppeteer has completely broken my app!
Has anybody seen a similar problem or got any ideas? I have googled for this error and it seems to be common but always after you have run a .js script, which I have not done.
I created a file example.js as per the Puppeteer documentation, with some code to run in Puppeteer. And I saved it in the root of my Meteor project. So of course Meteor automatically ran it - before the app had launched and the page rendered.
Moving my example.js into the /tests folder solved the problem: the file now does not execute until I run it manually.
Leaving this up here in case anybody else makes the same simple mistake and this post can save them some time.
// We set the page content as the generated html by handlebars
await page.setContent(html_string)
// we Use pdf function to generate the pdf in the same folder as this file.
await page.pdf({ path: '/usr/Data/Meteor/project/one2/public/allFiles/'+fileName + '.pdf', format: 'A4' })
await browser.close();
console.log("PDF Generated")
built_app/programs/server/npm/node_modules/puppeteer/.local-chromium/linux-768783/chrome-linux/chrome: error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
Using Mup JS for Deployment. Please Suggest if anyone experienced the same
I’ve been using puppeteer for a while now. When using puppeteer with Meteor and deploying with MUP you’ll need to install necessary shared library dependencies as desicribed here.
Alternatively you can use the custom imageI’ve created in your mup.js config file:
docker: {
// change to 'abernix/meteord:base' if your app is using Meteor 1.4 - 1.5
image: 'fedescoinc/meteord-node-with-chromium_dumb-init:node-12.16.1-base',
},
Like @zayco mentioned you can use a Meteor.call to get the base64 string to serve.
I haven’t served static files like this before but I’m not sure if bigger files will become an issue when going the Meteor.call route. (Maybe someone can clarify or correct me)
When not specifying a path property like page.pdf({path: 'path_to_save_file_to'}) the file is saved in memory (as described here).
What I’ve found to work is to install the meteorhacks:picker package and body-parser npm package. Then serve an endpoint to the file like so:
This will allow you to go to a url like http://localhost:3000/viewpdf?url=https://example.com and including the url in the params to view the file in memory. You’ll need extra error handling etc but I hope you get the point.
This is what I’ve found works and I’m not saying it’s the best option. If anyone has a better solution please share it.