From d746400ba63d350bbdb00511b6708fa93e128db4 Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Mon, 23 Mar 2026 11:24:43 +0300 Subject: [PATCH] feat: set `:pending_connection_errors` default to false --- CHANGELOG.md | 10 ++++++++++ docs/2-customization.md | 2 +- lib/ferrum/browser/options.rb | 2 +- spec/browser_spec.rb | 4 ++-- spec/network/exchange_spec.rb | 7 +------ spec/page_spec.rb | 3 +++ 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 461c4c05..cebb147a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [Unreleased] ## + +### Added + +### Changed +- `Ferrum::Browser` option `:pending_connection_errors` is set to false by default + +### Fixed + + ## [Unreleased](https://github.com/rubycdp/ferrum/compare/v0.17.1...main) ## ### Added diff --git a/docs/2-customization.md b/docs/2-customization.md index fa262c94..4764d25f 100644 --- a/docs/2-customization.md +++ b/docs/2-customization.md @@ -29,7 +29,7 @@ Ferrum::Browser.new(options) communicating with browser. Default is 5. * `:js_errors` (Boolean) - When true, JavaScript errors get re-raised in Ruby. * `:pending_connection_errors` (Boolean) - Raise `PendingConnectionsError` when main frame is still waiting - for slow responses and timeout is reached. Default is true. + for slow responses and timeout is reached. Default is false. * `:browser_name` (Symbol) - `:chrome` by default, only experimental support for `:firefox` for now. * `:browser_path` (String) - Path to Chrome binary, you can also set ENV diff --git a/lib/ferrum/browser/options.rb b/lib/ferrum/browser/options.rb index a638369c..fa396e13 100644 --- a/lib/ferrum/browser/options.rb +++ b/lib/ferrum/browser/options.rb @@ -30,7 +30,7 @@ def initialize(options = nil) @incognito = @options.fetch(:incognito, true) @dockerize = @options.fetch(:dockerize, false) @flatten = @options.fetch(:flatten, true) - @pending_connection_errors = @options.fetch(:pending_connection_errors, true) + @pending_connection_errors = @options.fetch(:pending_connection_errors, false) @process_timeout = @options.fetch(:process_timeout, PROCESS_TIMEOUT) @slowmo = @options[:slowmo].to_f diff --git a/spec/browser_spec.rb b/spec/browser_spec.rb index 601bae58..c77141c5 100644 --- a/spec/browser_spec.rb +++ b/spec/browser_spec.rb @@ -236,9 +236,9 @@ end it "supports :pending_connection_errors argument" do - browser = Ferrum::Browser.new(base_url: base_url, pending_connection_errors: false, timeout: 0.5) + browser = Ferrum::Browser.new(base_url: base_url, pending_connection_errors: true, timeout: 0.5) - expect { browser.go_to("/really_slow") }.not_to raise_error + expect { browser.go_to("/really_slow") }.to raise_error(Ferrum::PendingConnectionsError) ensure browser&.quit end diff --git a/spec/network/exchange_spec.rb b/spec/network/exchange_spec.rb index 1d13917d..1e92c083 100644 --- a/spec/network/exchange_spec.rb +++ b/spec/network/exchange_spec.rb @@ -197,12 +197,7 @@ it "determines if exchange is not fully loaded" do allow(page).to receive(:timeout) { 2 } - expect do - page.go_to("/visit_timeout") - end.to raise_error( - Ferrum::PendingConnectionsError, - %r{Request to http://.*/visit_timeout reached server, but there are still pending connections: http://.*/really_slow} - ) + page.go_to("/visit_timeout") expect(last_exchange.pending?).to be true end diff --git a/spec/page_spec.rb b/spec/page_spec.rb index ddf56c1c..429e9f42 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -25,6 +25,7 @@ it "reports pending connection for image" do with_timeout(2) do + allow(browser.options).to receive(:pending_connection_errors).and_return(true) expect { browser.go_to("/visit_timeout") }.to raise_error( Ferrum::PendingConnectionsError, %r{Request to http://.*/visit_timeout reached server, but there are still pending connections: http://.*/really_slow} @@ -34,6 +35,7 @@ it "reports pending connection for main frame" do with_timeout(0.5) do + allow(browser.options).to receive(:pending_connection_errors).and_return(true) expect { browser.go_to("/really_slow") }.to raise_error( Ferrum::PendingConnectionsError, %r{Request to http://.*/really_slow reached server, but there are still pending connections: http://.*/really_slow} @@ -164,6 +166,7 @@ describe "#timeout=" do it "supports to change timeout dynamically" do + allow(browser.options).to receive(:pending_connection_errors).and_return(true) page.timeout = 4 expect { page.go_to("/really_slow") }.not_to raise_error