rubycdp / ferrum

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

Ferrum::PendingConnectionsError - what to do? #437

Closed yshmarov closed 5 months ago

yshmarov commented 5 months ago

In my app I want to have a "generate pdf" controller action

Scenario:

when a user clicks

link_to 'Projects PDF', projects_path(format: :pdf)

it hits the controller action in PDF format, that opens a ferrum browser and visits the controller action in HTML format:

# app/controllers/projects_controller.rb
def index
  respond_to do |format|
    format.html
    format.pdf do
      browser = Ferrum::Browser.new
      browser.go_to(projects_path)
      browser.pdf
    end
  end
end

In this case I will often get the Ferrum::PendingConnectionsError error with Request to http://localhost:3000/projects reached server, but there are still pending connections: http:/localhost:3000/projects

Screenshot 2024-01-15 at 13 16 24

Are there some best practices to follow to avoid this error?