Studiosity / grover

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

Page.navigate timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed. #233

Open rekonder opened 4 months ago

rekonder commented 4 months ago

Hello,

We encountered the following error when using Grover to convert HTML to PDF with the to_pdf:

Page.navigate timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.

Grover Configuration:

Grover.configure do |config|
  config.options = {
    cache: false,
    executable_path: './bin/chromium',
    launch_args: ['--no-sandbox'],
    timeout: 300000
  }
end

Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated.

Grover version: 1.1.5

abrom commented 3 months ago

Can you provide any details of how you're actually calling to to_pdf? Are you passing in a URL, or HTML? Are you passing any other options to the Grover initialiser?

The timeout option you're setting is used for both the request and conversion timeouts.. although note that this ISN'T used for the launch timeout, which is currently just going to be the default of 30s.. but if you're hitting that you've likely got some pretty nasty resource constraint issues!

Have you had a read of the debugging section of the readme?

rekonder commented 3 months ago

We are passing HTML to the to_pdf. We initialize and generate pdf with the next call

Grover.new(
        @report_html,
        format: 'A4',
        print_background: true,
        margin: current_margin,
        display_header_footer: true,
        header_template: @header_html,
        footer_template: @footer_html,
        style_tag_options: @style_tag_options,
        script_tag_options: @script_tag_options,
        page_ranges: "#{cover_pages_shift}-999999",
        emulate_media: 'screen',
        display_url: Rails.application.routes.default_url_options[:host]
      ).to_pdf(@file.path)

I've reviewed the debugging section of the readme, but unfortunately, we're encountering this issue only in our production environment and haven't been able to reproduce it locally.

Can be this issue connected to the next issue Protocol error (Page.navigate): Target closed? Because on the same HTML generation, we now get the mentioned error.

Additionally, regarding the default 30-second timeout, is there a way to adjust this setting?