Class: Ferrum::Network::Exchange
- Inherits:
-
Object
- Object
- Ferrum::Network::Exchange
- Defined in:
- lib/ferrum/network/exchange.rb
Instance Attribute Summary collapse
-
#error ⇒ Error?
The error object.
-
#id ⇒ Object
readonly
ID of the request.
-
#intercepted_request ⇒ InterceptedRequest?
The intercepted request.
-
#request ⇒ Request?
The request object.
- #request_extra_info ⇒ Object private
-
#response ⇒ Response?
The response object.
-
#unknown ⇒ Object
Determines if the network exchange is unknown due to a lost of its context.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Determines if the network exchange has a request.
-
#blob? ⇒ Boolean
Determines if the exchange is blob.
-
#blocked? ⇒ Boolean
Determines if the request was intercepted and blocked.
-
#finished? ⇒ Boolean
Determines if the request was blocked, a response was returned, or if an error occurred or the exchange is unknown and cannot be inferred.
-
#initialize(page, id) ⇒ Exchange
constructor
Initializes the network exchange.
-
#inspect ⇒ String
Inspects the network exchange.
-
#intercepted? ⇒ Boolean
Determines if the exchange’s request was intercepted.
-
#loader_id ⇒ String?
The loader ID of the request.
-
#navigation_request?(frame_id) ⇒ Boolean
Determines if the network exchange was caused by a page navigation event.
-
#pending? ⇒ Boolean
Determines if the network exchange is still not finished.
-
#ping? ⇒ Boolean
Determines if the exchange is ping.
-
#redirect? ⇒ Boolean
Determines if the exchange is a redirect.
-
#to_a ⇒ Array
Converts the network exchange into a request, response, and error tuple.
-
#url ⇒ String?
Returns request’s URL.
-
#xhr? ⇒ Boolean
Determines if the exchange is XHR.
Constructor Details
#initialize(page, id) ⇒ Exchange
Initializes the network exchange.
47 48 49 50 51 52 53 54 |
# File 'lib/ferrum/network/exchange.rb', line 47 def initialize(page, id) @id = id @page = page @intercepted_request = nil @request = @response = @error = nil @request_extra_info = nil @unknown = false end |
Instance Attribute Details
#error ⇒ Error?
The error object.
29 30 31 |
# File 'lib/ferrum/network/exchange.rb', line 29 def error @error end |
#id ⇒ Object (readonly)
ID of the request.
9 10 11 |
# File 'lib/ferrum/network/exchange.rb', line 9 def id @id end |
#intercepted_request ⇒ InterceptedRequest?
The intercepted request.
14 15 16 |
# File 'lib/ferrum/network/exchange.rb', line 14 def intercepted_request @intercepted_request end |
#request ⇒ Request?
The request object.
19 20 21 |
# File 'lib/ferrum/network/exchange.rb', line 19 def request @request end |
#request_extra_info ⇒ Object
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.
38 39 40 |
# File 'lib/ferrum/network/exchange.rb', line 38 def request_extra_info @request_extra_info end |
#response ⇒ Response?
The response object.
24 25 26 |
# File 'lib/ferrum/network/exchange.rb', line 24 def response @response end |
#unknown ⇒ Object
Determines if the network exchange is unknown due to a lost of its context
35 36 37 |
# File 'lib/ferrum/network/exchange.rb', line 35 def unknown @unknown end |
Instance Method Details
#blank? ⇒ Boolean
Determines if the network exchange has a request.
82 83 84 |
# File 'lib/ferrum/network/exchange.rb', line 82 def blank? !request end |
#blob? ⇒ Boolean
Determines if the exchange is blob.
155 156 157 |
# File 'lib/ferrum/network/exchange.rb', line 155 def blob? !!url&.start_with?("blob:") end |
#blocked? ⇒ Boolean
Determines if the request was intercepted and blocked.
91 92 93 |
# File 'lib/ferrum/network/exchange.rb', line 91 def blocked? intercepted? && intercepted_request.status?(:aborted) end |
#finished? ⇒ Boolean
Determines if the request was blocked, a response was returned, or if an error occurred or the exchange is unknown and cannot be inferred.
101 102 103 |
# File 'lib/ferrum/network/exchange.rb', line 101 def finished? blocked? || response&.loaded? || !error.nil? || ping? || blob? || unknown end |
#inspect ⇒ String
Inspects the network exchange.
182 183 184 185 186 187 188 189 190 |
# File 'lib/ferrum/network/exchange.rb', line 182 def inspect "#<#{self.class} " \ "@id=#{@id.inspect} " \ "@intercepted_request=#{@intercepted_request.inspect} " \ "@request=#{@request.inspect} " \ "@response=#{@response.inspect} " \ "@error=#{@error.inspect}> " \ "@unknown=#{@unknown.inspect}>" end |
#intercepted? ⇒ Boolean
Determines if the exchange’s request was intercepted.
119 120 121 |
# File 'lib/ferrum/network/exchange.rb', line 119 def intercepted? !intercepted_request.nil? end |
#loader_id ⇒ String?
The loader ID of the request.
73 74 75 |
# File 'lib/ferrum/network/exchange.rb', line 73 def loader_id request&.loader_id end |
#navigation_request?(frame_id) ⇒ Boolean
Determines if the network exchange was caused by a page navigation event.
64 65 66 |
# File 'lib/ferrum/network/exchange.rb', line 64 def (frame_id) request&.type?(:document) && request&.frame_id == frame_id end |
#pending? ⇒ Boolean
Determines if the network exchange is still not finished.
110 111 112 |
# File 'lib/ferrum/network/exchange.rb', line 110 def pending? !finished? end |
#ping? ⇒ Boolean
Determines if the exchange is ping.
146 147 148 |
# File 'lib/ferrum/network/exchange.rb', line 146 def ping? !!request&.ping? end |
#redirect? ⇒ Boolean
Determines if the exchange is a redirect.
137 138 139 |
# File 'lib/ferrum/network/exchange.rb', line 137 def redirect? response&.redirect? end |
#to_a ⇒ Array
Converts the network exchange into a request, response, and error tuple.
173 174 175 |
# File 'lib/ferrum/network/exchange.rb', line 173 def to_a [request, response, error] end |
#url ⇒ String?
Returns request’s URL.
164 165 166 |
# File 'lib/ferrum/network/exchange.rb', line 164 def url request&.url end |
#xhr? ⇒ Boolean
Determines if the exchange is XHR.
128 129 130 |
# File 'lib/ferrum/network/exchange.rb', line 128 def xhr? !!request&.xhr? end |