westy92/html-pdf-chrome

Allow Chrome instance to launch on first run and persist for future runs

adamreisnz opened this issue ยท 5 comments

Hi @westy92 , we're using this library on Heroku and it's doing the job of generating PDF files without issues. However, we are trying to ascertain whether the Heroku buildpack starts and runs chrome in the background or whether this library is forced to start it up for each use.

Is there a way to log/debug that using this library?

And is there perhaps a flag or setting we can use to keep the app running after a first PDF has been generated?

Keen to hear your suggestions/tips, as I think currently it's starting chrome up for every PDF causing needless overhead.

I have a related ticket open at heroku/heroku-buildpack-google-chrome#111

If you pass a host and port in the CreateOptions then this library will not launch Chrome. If you omit them, it will, since there is no existing instance of Chrome for it to use. See:
https://github.com/westy92/html-pdf-chrome/blob/master/src/index.ts#L32

As recommended in the README, you can look into a solution like this to ensure Chrome runs once and stays running: https://github.com/westy92/html-pdf-chrome#usage

I am enquiring for a solution specifically for Heroku. As far as I'm aware, Heroku has it's own process manager to ensure that a web process keeps running and restarts after it crashes. So as far as I'm aware, it's not possible to install pm2 on it and use it to keep Chrome running.

What I am asking for, is a solution with this library. Since it is obviously capable of starting chrome instance on demand if needed, would it not be capable of starting Chrome and keep it running so that any future PDF generation calls can utilise this existing Chrome instance?

For example, if we don't specify host/port, and it launches a Chrome instance, can we pass a flag like keepAlive: true to ensure the instance will keep running? And for future calls to use this instance, if it is available?

Ah, I understand the intention, thank you for explaining more.

I think your best action would be to directly use what this library uses under the hood, chrome-launcher.

This library isn't currently designed to hold any state between runs, but I will mark this as a feature request.

This seems to work well, using the Chrome launcher under the hood. We now use it to launch an instance of Chrome and pass the port to this library, which then reuses this instance rather than launching one itself (and terminating it afterwards).

Would still be keen on a flag to possible keep the instance alive ๐Ÿ‘๐Ÿผ