From 8a583a205d2ed8421c0ef872631f8086fb220a8f Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Fri, 20 Nov 2026 21:31:48 +0300 Subject: [PATCH] docs(events): note that on(:response) yields an Exchange, not a Response --- docs/7-network.md | 11 +++++++---- lib/ferrum/interceptable.rb | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/7-network.md b/docs/7-network.md index 3ade8340..0e2ecf1a 100644 --- a/docs/7-network.md +++ b/docs/7-network.md @@ -93,7 +93,8 @@ subscription id you can pass to `off` to unsubscribe. * `:request` an intercepted request, see `intercept` below. Requires `network.intercept` to be set up first. Callbacks run in the order they were added and the rest are skipped once one handles the request. -* `:response` a request's response once it's fully loaded, see below. Works without `intercept`. +* `:response` a request's response once it's fully loaded, yielded as a `Network::Exchange`, see below. Works + without `intercept`. * `:auth` a proxy/basic auth challenge, see `authorize` below. Requires `network.intercept` to be set up first. Works like `:request`, an unhandled challenge gets Chrome's default response. * `:dialog` a JS dialog (`alert`/`confirm`/`prompt`), see [Dialogs](./16-dialogs.md). @@ -103,9 +104,11 @@ subscription id you can pass to `off` to unsubscribe. Subscribes to a callback fired once a request's response has fully loaded, i.e. after Chrome's `Network.loadingFinished` event, so `exchange.response.body` is always -available. Doesn't require `intercept` to be set up. The block receives the -`Network::Exchange` for that request; it's never yielded for requests that fail to -load (use `traffic` to inspect those instead). +available. Doesn't require `intercept` to be set up. Despite the event's name, the block +receives the `Network::Exchange` for that request, not a `Network::Response`: it pairs +`exchange.request` with `exchange.response`, so you can tell which request a response +belongs to. It's never yielded for requests that fail to load (use `traffic` to inspect +those instead). ```ruby page.on(:response) do |exchange| diff --git a/lib/ferrum/interceptable.rb b/lib/ferrum/interceptable.rb index 1ce1f3f0..60f092e6 100644 --- a/lib/ferrum/interceptable.rb +++ b/lib/ferrum/interceptable.rb @@ -21,7 +21,8 @@ module Interceptable # # @yieldparam [Network::InterceptedRequest, Network::Exchange, Network::AuthRequest, Console::Message, Hash] arg # For `:request`, the intercepted {Network::InterceptedRequest}. For - # `:response`, the finished {Network::Exchange}. For `:auth`, the + # `:response`, the finished {Network::Exchange}, not a {Network::Response}: + # read the response via `exchange.response`. For `:auth`, the # {Network::AuthRequest} challenge. For `:console`, the new # {Console::Message}. For any other (raw CDP) event name, the event's # params `Hash`.