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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
`go_to` instead

### Fixed
- `AuthRequest#abort` raised `BrowserError` and left the page hanging, it cancels the auth challenge now
- `InterceptedRequest#navigation_request?` and `AuthRequest#navigation_request?` always returned `nil`, they are true
for document requests now
- `evaluate` raised `NoMethodError` when a node inside a `Map` or `Set` was also referenced elsewhere in the result
Expand Down
5 changes: 3 additions & 2 deletions lib/ferrum/network/auth_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ def continue(**options)
end

#
# Cancels the authentication challenge and the request.
# Cancels the authentication challenge, so the request completes with
# the unauthorized response.
#
def abort
@page.command("Fetch.failRequest", requestId: request_id, errorReason: "BlockedByClient")
continue(authChallengeResponse: { response: "CancelAuth" })
end

#
Expand Down
13 changes: 13 additions & 0 deletions spec/network/auth_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
end
end

describe "#abort" do
it "cancels the auth challenge and lets the page load the unauthorized response" do
network.intercept
page.on(:request) { |request, _index, _total| request.continue }
page.on(:auth) { |request, _index, _total| request.abort }

page.go_to("/basic_auth")

expect(network.status).to eq(401)
expect(page.body).not_to include("Welcome, authenticated client")
end
end

describe "#url" do
it "returns the url of the request" do
expect(auth_request("/basic_auth").url).to eq(base_url("/basic_auth"))
Expand Down
Loading