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

wait_for_selector fails with extra_http_headers #243

Closed Mohamed-Zkaria closed 4 months ago

Mohamed-Zkaria commented 4 months ago

Hi, I am trying to use grover in a protected route and I am passing the following options to grover:

headers = {'grover-token': ENV['TOKEN_KEY']}

grover_options = {
                format: 'A4', 
                wait_for_selector: ".map_renderer svg",
                timeout: 60000, 
                extra_http_headers: headers
            }
grover = Grover.new(path, **grover_options)

grover.to_pdf

And for some reason it fails to wait on the map selection whenever I pass extra headers and it fails after 30000ms even though I am modifying it. Any idea why this is happening?

error log:

Grover::JavaScript::TimeoutError (Waiting for selector `.map_renderer svg` failed: Waiting failed: 30000ms exceeded)
abrom commented 4 months ago

there are a lot of places timeouts can occur. At the moment the timeout option only applies to the request and conversion stages. Although TBH it likely makes sense for this option to also apply to the Page.setDefaultTimeout

For now though, you can provide the wait for selector timeout override via:

wait_for_selector_options: { timeout: 60000 }

See https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.waitforselectoroptions.md

Mohamed-Zkaria commented 4 months ago

Thank you, appreciate your response.