Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
### Changed
- `Ferrum::Network::Response#body` returns body or nil in case of errors
- Disable Chrome code sign clones [#555]
- `Ferrum::Browser` option `:pending_connection_errors` is set to false by default
- Ruby version required is >= 3.1 [#565]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/2-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 false.
for slow responses and timeout is reached. Default is true.
* `: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
Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/browser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, false)
@pending_connection_errors = @options.fetch(:pending_connection_errors, true)
@process_timeout = @options.fetch(:process_timeout, PROCESS_TIMEOUT)
@slowmo = @options[:slowmo].to_f

Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def size

private

def subscribe # rubocop:disable Metrics/PerceivedComplexity
def subscribe # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
@client.on("Target.attachedToTarget") do |params|
info, session_id = params.values_at("targetInfo", "sessionId")
next unless ALLOWED_TARGET_TYPES.include?(info["type"])
Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/cookies/cookie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def ==(other)
# The raw cookie string.
#
def to_s
string = String.new("#{@attributes['name']}=#{@attributes['value']}")
string = "#{@attributes['name']}=#{@attributes['value']}"

@attributes.each do |key, value|
case key
Expand Down
4 changes: 2 additions & 2 deletions spec/browser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@
end

it "supports :pending_connection_errors argument" do
browser = Ferrum::Browser.new(base_url: base_url, pending_connection_errors: true, timeout: 0.5)
browser = Ferrum::Browser.new(base_url: base_url, pending_connection_errors: false, timeout: 0.5)

expect { browser.go_to("/really_slow") }.to raise_error(Ferrum::PendingConnectionsError)
expect { browser.go_to("/really_slow") }.not_to raise_error
ensure
browser&.quit
end
Expand Down
3 changes: 0 additions & 3 deletions spec/cookies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"secure" => false,
"session" => true,
"priority" => "Medium",
"sameParty" => false,
"sourceScheme" => "NonSecure",
"sourcePort" => server.port)
]
Expand All @@ -47,7 +46,6 @@
"secure" => false,
"session" => true,
"priority" => "Medium",
"sameParty" => false,
"sourceScheme" => "NonSecure",
"sourcePort" => server.port)
]
Expand All @@ -72,7 +70,6 @@
"secure" => false,
"session" => true,
"priority" => "Medium",
"sameParty" => false,
"sourceScheme" => "NonSecure",
"sourcePort" => server.port) })
end
Expand Down
13 changes: 0 additions & 13 deletions spec/downloads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@
let(:filename) { "attachment.pdf" }
let(:save_path) { "/tmp/ferrum" }

def skip_browser_bug
# Also https://github.com/puppeteer/puppeteer/issues/10161
skip "https://bugs.chromium.org/p/chromium/issues/detail?id=1444729"
end

describe "#files" do
it "saves an attachment" do
skip_browser_bug

page.downloads.set_behavior(save_path: save_path)
page.go_to("/#{filename}")
page.downloads.wait
Expand Down Expand Up @@ -50,8 +43,6 @@ def skip_browser_bug
describe "#set_behavior" do
context "with absolute path" do
it "saves an attachment" do
skip_browser_bug

page.downloads.set_behavior(save_path: save_path)
page.go_to("/#{filename}")
page.downloads.wait
Expand All @@ -62,17 +53,13 @@ def skip_browser_bug
end

it "saves no attachment when behavior is deny" do
skip_browser_bug

page.downloads.set_behavior(save_path: save_path, behavior: :deny)
page.downloads.wait { page.go_to("/#{filename}") }

expect(File.exist?("#{save_path}/#{filename}")).to be false
end

it "saves an attachment on click" do
skip_browser_bug

page.downloads.set_behavior(save_path: save_path)
page.go_to("/attachment")
page.downloads.wait { page.at_css("#download").click }
Expand Down
7 changes: 6 additions & 1 deletion spec/network/exchange_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@
it "determines if exchange is not fully loaded" do
allow(page).to receive(:timeout) { 2 }

page.go_to("/visit_timeout")
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}
)

expect(last_exchange.pending?).to be true
end
Expand Down
3 changes: 0 additions & 3 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

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}
Expand All @@ -35,7 +34,6 @@

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}
Expand Down Expand Up @@ -166,7 +164,6 @@

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

Expand Down
13 changes: 8 additions & 5 deletions spec/support/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
module Ferrum
class Application < Sinatra::Base
configure { set :protection, except: :frame_options }
FERRUM_VIEWS = "#{File.dirname(__FILE__)}/views".freeze
FERRUM_PUBLIC = "#{File.dirname(__FILE__)}/public".freeze

set :root, File.dirname(__FILE__)
FERRUM_APP = File.dirname(__FILE__)
FERRUM_VIEWS = "#{FERRUM_APP}/views".freeze
FERRUM_PUBLIC = "#{FERRUM_APP}/public".freeze

set :root, FERRUM_APP
set :static, true
set :raise_errors, true
set :show_exceptions, false
Expand Down Expand Up @@ -65,8 +67,9 @@ def authorized?(login, password)
end

get "/attachment.pdf" do
attachment("attachment.pdf")
send_file("attachment.pdf")
send_file File.join(FERRUM_APP, "static", "attachment.pdf"),
disposition: :attachment,
filename: "attachment.pdf"
end

get "/foo" do
Expand Down
File renamed without changes.
Loading