Skip to content

Commit 11ccf79

Browse files
committed
fix: Network.requestWillBeSent should handle params in a type-safe way
1 parent a5275bf commit 11ccf79

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
### Fixed
1717

1818
- `:ws_url` option is now used without modifications WYSIWYG.
19+
- `Network.requestWillBeSent` callback didn't handle params in a type-safe way
1920

2021
### Removed
2122

lib/ferrum/network.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,26 +368,24 @@ def subscribe_request_will_be_sent
368368
@page.on("Network.requestWillBeSent") do |params|
369369
request = Network::Request.new(params)
370370

371-
# We can build exchange in two places, here on the event or when request
372-
# is interrupted. So we have to be careful when to create new one. We
373-
# create new exchange only if there's no with such id or there's but
374-
# it's filled with request which means this one is new but has response
375-
# for a redirect. So we assign response from the params to previous
376-
# exchange and build new exchange to assign this request to it.
377-
exchange = select(request.id).last
378-
exchange = build_exchange(request.id) unless exchange&.blank?
379-
380371
# On redirects Chrome doesn't change `requestId` and there's no
381372
# `Network.responseReceived` event for such request. If there's already
382373
# exchange object with this id then we got redirected and params has
383374
# `redirectResponse` key which contains the response.
384-
if params["redirectResponse"]
385-
previous_exchange = select(request.id)[-2]
375+
if params["redirectResponse"] && (previous_exchange = select(request.id).last)
386376
response = Network::Response.new(@page, params)
387377
response.loaded = true
388378
previous_exchange.response = response
389379
end
390380

381+
# We can build exchange in two places, here on the event or when request
382+
# is interrupted. So we have to be careful when to create new one. We
383+
# create new exchange only if there's no with such id or there's but
384+
# it's filled with request which means this one is new but has response
385+
# for a redirect. So we assign response from the params to previous
386+
# exchange and build new exchange to assign this request to it.
387+
exchange = select(request.id).last
388+
exchange = build_exchange(request.id) unless exchange&.blank?
391389
exchange.request = request
392390

393391
@exchange = exchange if exchange.navigation_request?(@page.main_frame.id)

0 commit comments

Comments
 (0)