Using headless-chrome / Chromeless with Meteor for PDF generation


#1

I’m working on a project that requires PDF generation, and in terms of getting a sharp look, nothing does it better than Chrome.

We are looking into using headless-chrome or Chromeless inside the Meteor application. Does anyone have any experience with this?

In particular - I am trying to understand how this would work in terms of deploying to a managed deployment platform like Galaxy or Heroku.


#2

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 …


#3

I think so too. Do you know if Puppeteer requires you to install Chrome on the server?


#4

Nope, just install puppeteer and you are pretty much good to go.


#5

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.


#6

Hey, I was wondering how you managed to get puppeteer working with Meteor? I am getting the following error:

(node:56561) UnhandledPromiseRejectionWarning: TypeError: puppeteer.launch is not a function

Btw, I am trying to use puppeteer from a Meteor method like so:

import { Meteor } from 'meteor/meteor'
import puppeteer from 'puppeteer'

Meteor.methods({
  async puppetTest() {
    const browser = await puppeteer.launch()
    const page = await browser.newPage()
    await page.goto('https://google.com')
    await page.screenshot({path: 'test.png'})
    await browser.close()
  }
})

For some reason puppeteer returns {} rather than [Function]

UPDATE
The issue was solved.


#7

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!


#8

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.