rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.74k stars 123 forks source link

Headless new gives Ferrum::NoSuchPageError on screenshot #404

Closed phlegx closed 11 months ago

phlegx commented 1 year ago

HI there.

with latest ferrum 0.14 when we try the new flag for headless we frequently get an error on image/screenshot creation

Ferrum::NoSuchPageError

This is the part of the code where it happens

    out = nil
    browser.create_page() do |page|
      page.go_to(absolute_internal_path_to_image.gsub("'", "\\\\'"))
      out = if page.network.status.between?(200, 226)
              page.screenshot(quality:  AC['uploaders']['instant']['quality'],
                              format:   AC['uploaders']['instant']['file_format'],
                              encoding: :binary)
            else
              logger.info "  [error #{browser.network.status}] Ferrum browser bad status!"
            end
      page.close
    end

The browser now we initialize like that:

  def initialize
    @browser = Ferrum::Browser.new(browser_options: { 'headless':               'new',
                                                      'no-sandbox':             nil,
                                                      'disable-setuid-sandbox': nil,
                                                      'disable-dev-shm-usage':  nil },
                                   window_size:     [AC['uploaders']['instant']['width'],
                                                     AC['uploaders']['instant']['height']])
  end

With 0.13 version and headless to true this was working like a charm.

Any ideas what might causing that?

erickguan commented 1 year ago

Can it be page is loading something more? If you wait a few 50ms-500ms before screenshot, does it get better?

route commented 11 months ago

For this I need debug mode turned on and logs, run with FERRUM_DEBUG=true and attach logs or send them privately and I reopen.