Studiosity / grover

A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer/Chromium
MIT License
945 stars 109 forks source link

Grover::JavaScript::TimeoutError (Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r1045629 is guaranteed to work. #227

Closed JennsiS closed 8 months ago

JennsiS commented 8 months ago

Hello, i have the following error working on a Ubuntu server. The error is triggered randomly, i can't identify the reason.

SteveyblamWork commented 8 months ago

👋 We seem to be getting the same issue. On ubuntu aswell. Chromium browser installed.

abrom commented 8 months ago

You're going to have to provide some details about what you're actually doing here. How are you using the library. What options are you setting. etc etc.

There are a LOT of reasons you might get a timeout! How you're trying to use the library would likely go a long way to explain it

JennsiS commented 8 months ago

You're going to have to provide some details about what you're actually doing here. How are you using the library. What options are you setting. etc etc.

There are a LOT of reasons you might get a timeout! How you're trying to use the library would likely go a long way to explain it

Hello @abrom, i'm using the library on a ruby on rails application to generate a pdf from an html.erb template to send this pdf through a mail using action mailer.

Exact code where i'm generating the pdf:

  html_string = render_to_string({
      template: '/template_path',
      layout: 'pdf',
      formats: [:html]
  })

pdf = Grover.new(html_string, timeout: 0, format: 'letter', print_background: true, margin: {top: '10px'}).to_pdf

Using: ubuntu 20.04 grover version: (1.1.6) Chromium 122.0.6261.94 snap

Also while using the library a problem was installing puppeter because the most recent versions doesn't work so i have to downgrade to version 18.1.0.

The problem is sometimes it works and generates the pdf correctly and sometimes it throws this error and the server goes down. The pdf have some information retreived from records created and i also show some charts.

abrom commented 8 months ago

ok, so I think at least part of the issue here is the timeout parameter and what it actually does. At the moment it only does two things

What it isn't used for is the "launch timeout" and I believe that's what you're hitting up on. See https://pptr.dev/api/puppeteer.launchoptions thus the default of 30s is used.

If the issue is with v19+ of Puppeteer then I suspect the problem is something to do with the cache directory. The puppeteer project made some changes in v19 to do with how the browser is downloaded/installed. As such you'll probably want to take a look at https://github.com/puppeteer/puppeteer/blob/main/README.md#configuration

I see you're also installing the Chromium snap?? By default the puppeteer npm package will install its own version of Chromium with the intent of keeping the NPM package version expectation and the chromium version in step. That would likely also explain why you're seeing Only Chrome at revision r1045629 is guaranteed to work suggesting that the version of Chromium that you're installing is not guaranteed compatible with the puppeteer npm package you've installed. If you are wanting to manage the Chromium version yourself, you'd likely want to follow the following instructions (from the README I linked to above):

You should use puppeteer-core if you are connecting to a remote browser or managing browsers yourself. If you are managing browsers yourself, you will need to call puppeteer.launch with an explicit executablePath (or channel if it's installed in a standard location).

Note in grover you'd use the executable_path key to specify an alternate browser path.

SteveyblamWork commented 8 months ago

We fixed our problem. Nothing wrong with Grover. It was this

https://github.com/Studiosity/grover/issues/189

We had just put our admin behind a VPN so grover couldn't hit it. Allowing access for grover to hit the server being PDFd made it work.

JennsiS commented 8 months ago

ok, so I think at least part of the issue here is the timeout parameter and what it actually does. At the moment it only does two things

* page request timeout (which can also be set using `request_timeout`)

* conversion timeout (which can also be set using `convert_timeout`)

What it isn't used for is the "launch timeout" and I believe that's what you're hitting up on. See https://pptr.dev/api/puppeteer.launchoptions thus the default of 30s is used.

If the issue is with v19+ of Puppeteer then I suspect the problem is something to do with the cache directory. The puppeteer project made some changes in v19 to do with how the browser is downloaded/installed. As such you'll probably want to take a look at https://github.com/puppeteer/puppeteer/blob/main/README.md#configuration

I see you're also installing the Chromium snap?? By default the puppeteer npm package will install its own version of Chromium with the intent of keeping the NPM package version expectation and the chromium version in step. That would likely also explain why you're seeing Only Chrome at revision r1045629 is guaranteed to work suggesting that the version of Chromium that you're installing is not guaranteed compatible with the puppeteer npm package you've installed. If you are wanting to manage the Chromium version yourself, you'd likely want to follow the following instructions (from the README I linked to above):

You should use puppeteer-core if you are connecting to a remote browser or managing browsers yourself. If you are managing browsers yourself, you will need to call puppeteer.launch with an explicit executablePath (or channel if it's installed in a standard location).

Note in grover you'd use the executable_path key to specify an alternate browser path.

Thank you for your explanation and effective response. I think the problem was because the system resources were not enough to convert to PDF and that is why a get a timeout.