Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF download timing out on Chromium > 127 #279

Open
brianclinkenbeard opened this issue Nov 8, 2024 · 7 comments
Open

PDF download timing out on Chromium > 127 #279

brianclinkenbeard opened this issue Nov 8, 2024 · 7 comments

Comments

@brianclinkenbeard
Copy link

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: rubycdp/ferrum#457 (reply in thread)

@huda-kh
Copy link

huda-kh commented Dec 1, 2024

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

@RST-J
Copy link

RST-J commented Dec 9, 2024

Thanks for the hint @brianclinkenbeard. Recently our tests related to file downloads started to fail and I had no clue why. We use the same or similar download handling code. I could get some tests running again by changing the way kt-paperclip constructs URLs (sic), but other still failed and I didn't really know how to proceed.

After reading your issue I thought, maybe that hit us as well.
We have a layered Docker setup for our app. The lowest layer is a base image derived from the ruby-3.3 image. Into this image we install additionally required external tools like chrome by adding the chrome repo from Google and installing the package google-chrome-stable. For an unrelated reason I built a new version of this image and after that the aforementioned issues started to occur.

I replaced the repo version of chrome by the headless variant found here: https://googlechromelabs.github.io/chrome-for-testing/ (back linked to from here https://developer.chrome.com/blog/chrome-for-testing, so I believe it is credible). First I used some older version (some 127) but then I wondered whether newer versions also work. And indeed, the currently latest stable version 131.0.6778.87 also works.

I changed our base image to install chrome from that archive file rather then the repo, so we have control over the actually used version and when to update.

@route
Copy link
Member

route commented Jan 7, 2025

It's not cuprite/ferrum issue, find the version that still works

@route route closed this as completed Jan 7, 2025
@noniq
Copy link

noniq commented Jan 8, 2025

For me, the problem only occurs with specific versions of cuprite / ferrum:

  • cuprite 0.15 / ferrum 0.14: Dowloading works
  • cuprite 0.15.1 / ferrum 0.15: Downloading fails

It does not seem to be affected by the version of Chrome (I tried both Chrome for Testing v113.0.5672.0 and v133.0.6943.2).

Also, the problem seems to be triggered by opening a new (second) browser window during a test. We have tests like this (using RSpec and Capybara):

scenario "foo" do
  visit root_path
  print_view_window = window_opened_by do
    click_on "Open print view"
  end
  within_window print_view_window do
    expect(page).to have_css("h1", text: "Dolor lorem ipsum")
  end
  print_view_window.close
end

These tests run fine. However, as soon as one such test has been executed, all subsequent tests trying to download a file fail. Again, this only happens with cuprite 0.15.1 / ferrum 0.15.

@route
Copy link
Member

route commented Jan 8, 2025

Interesting, @noniq could you try to activate given page with rubycdp/ferrum@600d63d for ferrum 0.15

@route route reopened this Jan 8, 2025
@noniq
Copy link

noniq commented Jan 8, 2025

Not really sure if I got this right – I tried the following:

scenario "foo" do
  visit root_path
  print_view_window = window_opened_by do
    click_on "Open print view"
  end

  # ADDED 
  print_view_window.session.driver.browser.page.activate

  within_window print_view_window do
    expect(page).to have_css("h1", text: "Dolor lorem ipsum")
  end
  print_view_window.close
end

This does not make a difference, though.

@route
Copy link
Member

route commented Jan 8, 2025

hm I think wrong target is active, I have a sense what's going on. Let me try to reproduce it with pure Cuprite test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants