Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adamreisnz opened this issue Aug 3, 2021 · 5 comments

Comments

@adamreisnz
Copy link

adamreisnz commented Aug 3, 2021

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

@westy92
Copy link
Owner

westy92 commented Aug 3, 2021

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

@adamreisnz
Copy link
Author

adamreisnz commented Aug 4, 2021

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?

@westy92
Copy link
Owner

westy92 commented Aug 5, 2021

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.

@westy92 westy92 changed the title Keep chrome running on Heroku Allow Chrome instance to launch on first run and persist for future runs Aug 5, 2021
@adamreisnz
Copy link
Author

adamreisnz commented Aug 5, 2021 via email

@adamreisnz
Copy link
Author

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 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants