Skip to content

Commit

Permalink
fix: Network.requestWillBeSent should handle params in a type-safe way
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Jul 29, 2024
1 parent a5275bf commit 11ccf79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 9 additions & 11 deletions lib/ferrum/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 11ccf79

Please sign in to comment.