diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d2c9a5..0b44d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ ### Fixed - `:ws_url` option is now used without modifications WYSIWYG. +- `Network.requestWillBeSent` callback didn't handle params in a type-safe way ### Removed diff --git a/lib/ferrum/network.rb b/lib/ferrum/network.rb index 2ede0d4..6d8c2c3 100644 --- a/lib/ferrum/network.rb +++ b/lib/ferrum/network.rb @@ -368,26 +368,24 @@ def subscribe_request_will_be_sent @page.on("Network.requestWillBeSent") do |params| request = Network::Request.new(params) - # We can build exchange in two places, here on the event or when request - # is interrupted. So we have to be careful when to create new one. We - # create new exchange only if there's no with such id or there's but - # it's filled with request which means this one is new but has response - # for a redirect. So we assign response from the params to previous - # exchange and build new exchange to assign this request to it. - exchange = select(request.id).last - exchange = build_exchange(request.id) unless exchange&.blank? - # On redirects Chrome doesn't change `requestId` and there's no # `Network.responseReceived` event for such request. If there's already # exchange object with this id then we got redirected and params has # `redirectResponse` key which contains the response. - if params["redirectResponse"] - previous_exchange = select(request.id)[-2] + if params["redirectResponse"] && (previous_exchange = select(request.id).last) response = Network::Response.new(@page, params) response.loaded = true previous_exchange.response = response end + # We can build exchange in two places, here on the event or when request + # is interrupted. So we have to be careful when to create new one. We + # create new exchange only if there's no with such id or there's but + # it's filled with request which means this one is new but has response + # for a redirect. So we assign response from the params to previous + # exchange and build new exchange to assign this request to it. + exchange = select(request.id).last + exchange = build_exchange(request.id) unless exchange&.blank? exchange.request = request @exchange = exchange if exchange.navigation_request?(@page.main_frame.id)