From ff5bf723d78ad687bc222c394babe3edef6bee37 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sat, 1 Oct 2022 15:41:18 -0700 Subject: [PATCH] Add support for `browser.on(:response)`. * This adds an additional callback for the `Network.responseReceived` event when a response is received. It will look up the `Ferrum::Network::Exchange` object with the matching `requestId` and passes it back to the block, once a response has been received for a request. --- lib/ferrum/page.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ferrum/page.rb b/lib/ferrum/page.rb index 205e4b4d..55a92b61 100644 --- a/lib/ferrum/page.rb +++ b/lib/ferrum/page.rb @@ -303,6 +303,14 @@ def on(name, &block) exchange.intercepted_request = request block.call(request, index, total) end + when :response + @client.on('Network.responseReceived') do |params, index, total| + exchange = network.select(params["requestId"]).last + + if exchange + block.call(exchange, index, total) + end + end when :auth @client.on("Fetch.authRequired") do |params, index, total| request = Network::AuthRequest.new(self, params)