Class: Ferrum::Network::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/ferrum/network/exchange.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, id) ⇒ Exchange

Initializes the network exchange.

Parameters:

  • page (Page)
  • id (String)


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

#errorError?

The error object.

Returns:



29
30
31
# File 'lib/ferrum/network/exchange.rb', line 29

def error
  @error
end

#idObject (readonly)

ID of the request.

Returns:

  • String



9
10
11
# File 'lib/ferrum/network/exchange.rb', line 9

def id
  @id
end

#intercepted_requestInterceptedRequest?

The intercepted request.

Returns:



14
15
16
# File 'lib/ferrum/network/exchange.rb', line 14

def intercepted_request
  @intercepted_request
end

#requestRequest?

The request object.

Returns:



19
20
21
# File 'lib/ferrum/network/exchange.rb', line 19

def request
  @request
end

#request_extra_infoObject

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

#responseResponse?

The response object.

Returns:



24
25
26
# File 'lib/ferrum/network/exchange.rb', line 24

def response
  @response
end

#unknownObject

Determines if the network exchange is unknown due to a lost of its context

Returns:

  • Boolean



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.

Returns:

  • (Boolean)


82
83
84
# File 'lib/ferrum/network/exchange.rb', line 82

def blank?
  !request
end

#blob?Boolean

Determines if the exchange is blob.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


101
102
103
# File 'lib/ferrum/network/exchange.rb', line 101

def finished?
  blocked? || response&.loaded? || !error.nil? || ping? || blob? || unknown
end

#inspectString

Inspects the network exchange.

Returns:

  • (String)


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.

Returns:

  • (Boolean)


119
120
121
# File 'lib/ferrum/network/exchange.rb', line 119

def intercepted?
  !intercepted_request.nil?
end

#loader_idString?

The loader ID of the request.

Returns:

  • (String, nil)


73
74
75
# File 'lib/ferrum/network/exchange.rb', line 73

def loader_id
  request&.loader_id
end

Determines if the network exchange was caused by a page navigation event.

Parameters:

  • frame_id (String)

Returns:

  • (Boolean)


64
65
66
# File 'lib/ferrum/network/exchange.rb', line 64

def navigation_request?(frame_id)
  request&.type?(:document) && request&.frame_id == frame_id
end

#pending?Boolean

Determines if the network exchange is still not finished.

Returns:

  • (Boolean)


110
111
112
# File 'lib/ferrum/network/exchange.rb', line 110

def pending?
  !finished?
end

#ping?Boolean

Determines if the exchange is ping.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


137
138
139
# File 'lib/ferrum/network/exchange.rb', line 137

def redirect?
  response&.redirect?
end

#to_aArray

Converts the network exchange into a request, response, and error tuple.

Returns:

  • (Array)


173
174
175
# File 'lib/ferrum/network/exchange.rb', line 173

def to_a
  [request, response, error]
end

#urlString?

Returns request’s URL.

Returns:

  • (String, nil)


164
165
166
# File 'lib/ferrum/network/exchange.rb', line 164

def url
  request&.url
end

#xhr?Boolean

Determines if the exchange is XHR.

Returns:

  • (Boolean)


128
129
130
# File 'lib/ferrum/network/exchange.rb', line 128

def xhr?
  !!request&.xhr?
end