Module: Ferrum::Interceptable
- Defined in:
- lib/ferrum/interceptable.rb,
lib/ferrum/interceptable/chain.rb,
sig/ferrum/interceptable.rbs,
sig/ferrum/interceptable/chain.rbs
Overview
Shared by Page and Worker: subscribes to the CDP events behind the
:request (Fetch-domain request interception), :response (a request's
response has fully loaded), :auth (proxy/basic auth challenges) and
:console (a new console message) pseudo-events, on top of the
includer's own client, network and console. Anything else is passed
straight through to client.
Defined Under Namespace
Classes: Chain
Instance Method Summary collapse
-
#off(name, id) ⇒ void
Unsubscribes a listener previously registered via #on.
-
#on(name) {|arg, arg0| ... } ⇒ Integer
Subscribes to a CDP event, or to
:request/:response/:auth/:console. -
#subscribe_interception ⇒ void
private
Listens to paused requests and auth challenges for good, so the ones no callback handles are still answered, even after the last one is removed.
-
#subscribed?(event) ⇒ Boolean
Whether there's at least one callback registered for the event.
Instance Method Details
#off(name, id) ⇒ void
This method returns an undefined value.
Unsubscribes a listener previously registered via #on.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ferrum/interceptable.rb', line 67 def off(name, id) case name when :console console.off(id) when :request, :auth chain(name).remove(id) when :response client.off("Network.loadingFinished", id) else client.off(name, id) end end |
#on(arg0) ⇒ Integer #on(arg0) ⇒ Integer #on(arg0) ⇒ Integer #on(arg0) ⇒ Integer #on(name) ⇒ Integer
Subscribes to a CDP event, or to :request/:response/:auth/:console.
:request and :auth callbacks form a chain: they run in the order they
were added, and the rest are skipped as soon as one of them handles the
object (continue, respond, abort). An object nobody handled is
continued, an auth challenge gets Chrome's default response.
The first :request or :auth callback turns request interception on,
call network.intercept first only to narrow what it pauses.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ferrum/interceptable.rb', line 41 def on(name, &block) case name when :console console.on(&block) when :request, :auth id = chain(name).add(&block) network.ensure_interception(auth: name == :auth) id when :response client.on("Network.loadingFinished") do |params| exchange = network.select(params["requestId"]).last block.call(exchange) if exchange end else client.on(name, &block) end end |
#subscribe_interception ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Listens to paused requests and auth challenges for good, so the ones no callback handles are still answered, even after the last one is removed.
95 96 97 98 |
# File 'lib/ferrum/interceptable.rb', line 95 def subscribe_interception chain(:request) chain(:auth) end |
#subscribed?(event) ⇒ Boolean
Whether there's at least one callback registered for the event.
85 86 87 |
# File 'lib/ferrum/interceptable.rb', line 85 def subscribed?(event) client.subscribed?(event) end |