diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0866bc..029778c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ferrum/network/auth_request.rb b/lib/ferrum/network/auth_request.rb index a65e2568..e4a6e5d0 100644 --- a/lib/ferrum/network/auth_request.rb +++ b/lib/ferrum/network/auth_request.rb @@ -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 # diff --git a/spec/network/auth_request_spec.rb b/spec/network/auth_request_spec.rb index 4f56b73b..3025750c 100644 --- a/spec/network/auth_request_spec.rb +++ b/spec/network/auth_request_spec.rb @@ -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"))