File tree Expand file tree Collapse file tree 5 files changed +44
-7
lines changed Expand file tree Collapse file tree 5 files changed +44
-7
lines changed Original file line number Diff line number Diff line change 1
1
## [ Unreleased] ( https://github.com/rubycdp/ferrum/compare/v0.13...main ) ##
2
2
3
3
### Added
4
+ - ` Ferrum::Network::Exchange#xhr? ` determines if the exchange is XHR
5
+ - ` Ferrum::Network::Request#xhr? ` determines if the request is XHR
6
+ - ` Ferrum::Network::Response#loaded? ` returns true if the response is fully loaded
4
7
5
8
### Changed
6
9
7
10
### Fixed
11
+ - ` Ferrum::Network::Exchange#finished? ` returns ` true ` only fully loaded responses
8
12
9
13
### Removed
10
14
Original file line number Diff line number Diff line change @@ -374,8 +374,12 @@ def subscribe_response_received
374
374
375
375
def subscribe_loading_finished
376
376
@page . on ( "Network.loadingFinished" ) do |params |
377
- exchange = select ( params [ "requestId" ] ) . last
378
- exchange . response . body_size = params [ "encodedDataLength" ] if exchange &.response
377
+ response = select ( params [ "requestId" ] ) . last &.response
378
+
379
+ if response
380
+ response . loaded = true
381
+ response . body_size = params [ "encodedDataLength" ]
382
+ end
379
383
end
380
384
end
381
385
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ def blocked?
79
79
# @return [Boolean]
80
80
#
81
81
def finished?
82
- blocked? || ! response . nil ? || !error . nil?
82
+ blocked? || response &. loaded ? || !error . nil?
83
83
end
84
84
85
85
#
@@ -100,6 +100,15 @@ def intercepted?
100
100
!intercepted_request . nil?
101
101
end
102
102
103
+ #
104
+ # Determines if the exchange is XHR.
105
+ #
106
+ # @return [Boolean]
107
+ #
108
+ def xhr?
109
+ !!request &.xhr?
110
+ end
111
+
103
112
#
104
113
# Returns request's URL.
105
114
#
Original file line number Diff line number Diff line change @@ -50,6 +50,15 @@ def type?(value)
50
50
type . downcase == value . to_s . downcase
51
51
end
52
52
53
+ #
54
+ # Determines if the request is XHR.
55
+ #
56
+ # @return [Boolean]
57
+ #
58
+ def xhr?
59
+ type? ( "xhr" )
60
+ end
61
+
53
62
#
54
63
# The frame ID of the request.
55
64
#
Original file line number Diff line number Diff line change @@ -18,8 +18,13 @@ class Response
18
18
# @return [Hash{String => Object}]
19
19
attr_reader :params
20
20
21
+ # The response is fully loaded by the browser.
21
22
#
22
- # Initializes the respones object.
23
+ # @return [Boolean]
24
+ attr_writer :loaded
25
+
26
+ #
27
+ # Initializes the responses object.
23
28
#
24
29
# @param [Page] page
25
30
# The page associated with the network response.
@@ -121,9 +126,8 @@ def body_size=(size)
121
126
#
122
127
def body
123
128
@body ||= begin
124
- body , encoded = @page
125
- . command ( "Network.getResponseBody" , requestId : id )
126
- . values_at ( "body" , "base64Encoded" )
129
+ body , encoded = @page . command ( "Network.getResponseBody" , requestId : id )
130
+ . values_at ( "body" , "base64Encoded" )
127
131
encoded ? Base64 . decode64 ( body ) : body
128
132
end
129
133
end
@@ -135,6 +139,13 @@ def main?
135
139
@page . network . response == self
136
140
end
137
141
142
+ # The response is fully loaded by the browser or not.
143
+ #
144
+ # @return [Boolean]
145
+ def loaded?
146
+ @loaded
147
+ end
148
+
138
149
#
139
150
# Comapres the respones ID to another response's ID.
140
151
#
You can’t perform that action at this time.
0 commit comments