rubycdp / cuprite

Headless Chrome/Chromium driver for Capybara
https://cuprite.rubycdp.com
MIT License
1.25k stars 92 forks source link

PDF download timing out on Chromium > 127 #279

Open brianclinkenbeard opened 3 weeks ago

brianclinkenbeard commented 3 weeks ago

After updating past Chromium 127, running RSpec tests on PDF downloads now uniformly time out. We use this somewhat popular helper code to yield the download after clicking a PDF link:

module DownloadHelpers
  TIMEOUT = 10
  PATH    = Capybara.save_path

  module_function

  def downloads
    Dir[PATH.join('*.{pdf,csv}')]
  end

  def download
    downloads.first
  end

  def download_content
    wait_for_download
    File.read(download)
  end

  def wait_for_download
    Timeout.timeout(TIMEOUT) do
      sleep 0.1 until downloaded?
    end
  end

  def downloaded?
    !downloading? && downloads.any?
  end

  def downloading?
    downloads.grep(/\.crdownload$/).any?
  end

  def clear_downloads
    FileUtils.rm_f(downloads)
  end
end

RSpec.configure do |config|
  config.include DownloadHelpers, type: :system

  config.before(:each, type: :system) do
    clear_downloads
  end
  config.after(:each, type: :system) do
    clear_downloads
  end
end

Waiting for a PDF download just hangs indefinitely. Watching with headless turned off, the PDF will never load in the new tab, however, trying this manually on a clean instance of Chromium will load the PDF perfectly. Perhaps an upstream regression with the CDP? Maybe also related: https://github.com/rubycdp/ferrum/discussions/457#discussioncomment-9151778

huda-kh commented 2 days ago

Any luck here? I am having the same issue with the same helper downloading a file (not a PDF).