Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check if exchange exists before manipulating it #442

Merged
merged 2 commits into from
Feb 6, 2024
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 @@ instead of passing browser and making cyclic dependency on the browser instance,
- Exceptions within `.on()` were swallowed by a thread pool of `Concurrent::Async` [#432]
- `Ferrum::Context#add_target` puts wrong target to pendings sometimes [#433]
- Leaking connection descriptors in tests and after browser quit [#433]
- Check if network exchange exists before manipulating it [#442]

### Removed

Expand Down
18 changes: 10 additions & 8 deletions lib/ferrum/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,19 @@ def subscribe_request_will_be_sent
def subscribe_response_received
@page.on("Network.responseReceived") do |params|
exchange = select(params["requestId"]).last
next unless exchange

if exchange
response = Network::Response.new(@page, params)
exchange.response = response
end
response = Network::Response.new(@page, params)
exchange.response = response
end
end

def subscribe_loading_finished
@page.on("Network.loadingFinished") do |params|
response = select(params["requestId"]).last&.response
exchange = select(params["requestId"]).last
next unless exchange

if response
if (response = exchange.response)
response.loaded = true
response.body_size = params["encodedDataLength"]
end
Expand All @@ -407,8 +407,9 @@ def subscribe_loading_finished
def subscribe_loading_failed
@page.on("Network.loadingFailed") do |params|
exchange = select(params["requestId"]).last
exchange.error ||= Network::Error.new
next unless exchange

exchange.error ||= Network::Error.new
exchange.error.id = params["requestId"]
exchange.error.type = params["type"]
exchange.error.error_text = params["errorText"]
Expand All @@ -422,8 +423,9 @@ def subscribe_log_entry_added
entry = params["entry"] || {}
if entry["source"] == "network" && entry["level"] == "error"
exchange = select(entry["networkRequestId"]).last
exchange.error ||= Network::Error.new
next unless exchange

exchange.error ||= Network::Error.new
exchange.error.id = entry["networkRequestId"]
exchange.error.url = entry["url"]
exchange.error.description = entry["text"]
Expand Down
Loading