puppeteer-ruby 0.40.5 → 0.40.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/docs/api_coverage.md +4 -4
- data/lib/puppeteer/http_request.rb +76 -31
- data/lib/puppeteer/network_manager.rb +8 -0
- data/lib/puppeteer/page.rb +13 -0
- data/lib/puppeteer/version.rb +1 -1
- data/puppeteer-ruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51b26b6b3710f06e7a7cfb7e9f5730bbb9517396fd30a7f271161820bb6902c6
|
4
|
+
data.tar.gz: 528fd6520a029cf9d85424a105cf19a156f428435dc795a8b8753c8cbfa442db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad616ae1574e76f71cb7e7cb1dae5cba4ae4ad65865ab6a5e6cb92c6033b9ce654de2b364b5d5351e69302f88fc48231c2a9bd97765af9ed827862e762f9d748
|
7
|
+
data.tar.gz: 9a194d8df09c6c6eda97ef095d67dafd693b7ff386e612d926925bdbcf41b3b2a21c06862eff90525e39f85c7d8a5ded419bb8c4b4a3ecb33413c7ccdf47215e
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
### main [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.
|
1
|
+
### main [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.6...main)]
|
2
2
|
|
3
3
|
- xxx
|
4
4
|
|
5
|
+
### 0.40.6 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.5...0.40.6)]
|
6
|
+
|
7
|
+
- Port Puppeteer v13.1-v13.5 features mainly for request interception.
|
8
|
+
|
5
9
|
### 0.40.5 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.40.4...0.40.5)]
|
6
10
|
|
7
11
|
Bugfix:
|
data/docs/api_coverage.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# API coverages
|
2
|
-
- Puppeteer version: v13.5.
|
3
|
-
- puppeteer-ruby version: 0.40.
|
2
|
+
- Puppeteer version: v13.5.2
|
3
|
+
- puppeteer-ruby version: 0.40.6
|
4
4
|
|
5
5
|
## Puppeteer
|
6
6
|
|
@@ -310,8 +310,8 @@
|
|
310
310
|
* frame
|
311
311
|
* headers
|
312
312
|
* initiator
|
313
|
-
*
|
314
|
-
*
|
313
|
+
* interceptResolutionState => `#intercept_resolution_state`
|
314
|
+
* isInterceptResolutionHandled => `#intercept_resolution_handled?`
|
315
315
|
* isNavigationRequest => `#navigation_request?`
|
316
316
|
* method
|
317
317
|
* postData => `#post_data`
|
@@ -2,6 +2,8 @@ class Puppeteer::HTTPRequest
|
|
2
2
|
include Puppeteer::DebugPrint
|
3
3
|
include Puppeteer::IfPresent
|
4
4
|
|
5
|
+
DEFAULT_INTERCEPT_RESOLUTION_PRIORITY = 0
|
6
|
+
|
5
7
|
# defines some methods used only in NetworkManager, Response
|
6
8
|
class InternalAccessor
|
7
9
|
def initialize(request)
|
@@ -38,6 +40,43 @@ class Puppeteer::HTTPRequest
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
43
|
+
class InterceptResolutionState
|
44
|
+
def self.abort(priority: nil)
|
45
|
+
new(action: 'abort', priority: priority)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.respond(priority: nil)
|
49
|
+
new(action: 'respond', priority: priority)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.continue(priority: nil)
|
53
|
+
new(action: 'continue', priority: priority)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.disabled(priority: nil)
|
57
|
+
new(action: 'disabled', priority: priority)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.none(priority: nil)
|
61
|
+
new(action: 'none', priority: priority)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.already_handled(priority: nil)
|
65
|
+
new(action: 'already-handled', priority: priority)
|
66
|
+
end
|
67
|
+
|
68
|
+
private def initialize(action:, priority:)
|
69
|
+
@action = action
|
70
|
+
@priority = priority
|
71
|
+
end
|
72
|
+
|
73
|
+
def priority_unspecified?
|
74
|
+
@priority.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
attr_reader :action, :priority
|
78
|
+
end
|
79
|
+
|
41
80
|
# @param client [Puppeteer::CDPSession]
|
42
81
|
# @param frame [Puppeteer::Frame]
|
43
82
|
# @param interception_id [string|nil]
|
@@ -57,9 +96,8 @@ class Puppeteer::HTTPRequest
|
|
57
96
|
@frame = frame
|
58
97
|
@redirect_chain = redirect_chain
|
59
98
|
@continue_request_overrides = {}
|
60
|
-
@
|
61
|
-
@
|
62
|
-
@intercept_actions = []
|
99
|
+
@intercept_resolution_state = InterceptResolutionState.none
|
100
|
+
@intercept_handlers = []
|
63
101
|
@initiator = event['initiator']
|
64
102
|
|
65
103
|
@headers = {}
|
@@ -115,19 +153,29 @@ class Puppeteer::HTTPRequest
|
|
115
153
|
@abort_error_reason
|
116
154
|
end
|
117
155
|
|
118
|
-
# @returns An
|
119
|
-
#
|
120
|
-
#
|
121
|
-
|
156
|
+
# @returns An InterceptResolutionState object describing the current resolution
|
157
|
+
# action and priority.
|
158
|
+
#
|
159
|
+
# InterceptResolutionState contains:
|
160
|
+
# action: InterceptResolutionAction
|
161
|
+
# priority?: number
|
162
|
+
#
|
163
|
+
# InterceptResolutionAction is one of: `abort`, `respond`, `continue`,
|
164
|
+
# `disabled`, `none`, or `alreay-handled`
|
165
|
+
def intercept_resolution_state
|
122
166
|
if !@allow_interception
|
123
|
-
|
167
|
+
InterceptResolutionState.disabled
|
124
168
|
elsif @interception_handled
|
125
|
-
|
169
|
+
InterceptResolutionState.already_handled
|
126
170
|
else
|
127
|
-
|
171
|
+
@intercept_resolution_state.dup
|
128
172
|
end
|
129
173
|
end
|
130
174
|
|
175
|
+
def intercept_resolution_handled?
|
176
|
+
@interception_handled
|
177
|
+
end
|
178
|
+
|
131
179
|
# Adds an async request handler to the processing queue.
|
132
180
|
# Deferred handlers are not guaranteed to execute in any particular order,
|
133
181
|
# but they are guarnateed to resolve before the request interception
|
@@ -135,19 +183,19 @@ class Puppeteer::HTTPRequest
|
|
135
183
|
#
|
136
184
|
# @param pending_handler [Proc]
|
137
185
|
def enqueue_intercept_action(pending_handler)
|
138
|
-
@
|
186
|
+
@intercept_handlers << pending_handler
|
139
187
|
end
|
140
188
|
|
141
189
|
# Awaits pending interception handlers and then decides how to fulfill
|
142
190
|
# the request interception.
|
143
191
|
def finalize_interceptions
|
144
|
-
@
|
145
|
-
case @intercept_resolution
|
146
|
-
when
|
192
|
+
@intercept_handlers.each(&:call)
|
193
|
+
case @intercept_resolution.action
|
194
|
+
when 'abort'
|
147
195
|
abort_impl(**@abort_error_reason)
|
148
|
-
when
|
196
|
+
when 'respond'
|
149
197
|
respond_impl(**@response_for_request)
|
150
|
-
when
|
198
|
+
when 'continue'
|
151
199
|
continue_impl(@continue_request_overrides)
|
152
200
|
end
|
153
201
|
end
|
@@ -220,17 +268,16 @@ class Puppeteer::HTTPRequest
|
|
220
268
|
end
|
221
269
|
|
222
270
|
@continue_request_overrides = overrides
|
223
|
-
if @
|
224
|
-
@
|
225
|
-
@current_priority = priority
|
271
|
+
if @intercept_resolution_state.priority_unspecified? || priority > @intercept_resolution_state.priority
|
272
|
+
@intercept_resolution_state = InterceptResolutionState.continue(priority: priority)
|
226
273
|
return
|
227
274
|
end
|
228
275
|
|
229
|
-
if priority == @
|
230
|
-
if @
|
276
|
+
if priority == @intercept_resolution_state.priority
|
277
|
+
if @intercept_resolution_state.action == :abort || @intercept_resolution_state.action == :respond
|
231
278
|
return
|
232
279
|
end
|
233
|
-
@
|
280
|
+
@intercept_resolution_state = InterceptResolutionState.continue(priority: priority)
|
234
281
|
end
|
235
282
|
end
|
236
283
|
|
@@ -284,17 +331,16 @@ class Puppeteer::HTTPRequest
|
|
284
331
|
body: body,
|
285
332
|
}
|
286
333
|
|
287
|
-
if @
|
288
|
-
@
|
289
|
-
@current_priority = priority
|
334
|
+
if @intercept_resolution_state.priority_unspecified? || priority > @intercept_resolution_state.priority
|
335
|
+
@intercept_resolution_state = InterceptResolutionState.respond(priority: priority)
|
290
336
|
return
|
291
337
|
end
|
292
338
|
|
293
|
-
if priority == @
|
294
|
-
if @
|
339
|
+
if priority == @intercept_resolution_state.priority
|
340
|
+
if @intercept_resolution_state.action == :abort
|
295
341
|
return
|
296
342
|
end
|
297
|
-
@
|
343
|
+
@intercept_resolution_state = InterceptResolutionState.respond(priority: priority)
|
298
344
|
end
|
299
345
|
end
|
300
346
|
|
@@ -360,9 +406,8 @@ class Puppeteer::HTTPRequest
|
|
360
406
|
end
|
361
407
|
@abort_error_reason = error_reason
|
362
408
|
|
363
|
-
if @
|
364
|
-
@
|
365
|
-
@current_priority = priority
|
409
|
+
if @intercept_resolution_state.priority_unspecified? || priority > @intercept_resolution_state.priority
|
410
|
+
@intercept_resolution_state = InterceptResolutionState.abort(priority: priority)
|
366
411
|
end
|
367
412
|
end
|
368
413
|
|
@@ -217,6 +217,7 @@ class Puppeteer::NetworkManager
|
|
217
217
|
# CDP may have sent a Fetch.requestPaused event already. Check for it.
|
218
218
|
if_present(@network_event_manager.get_request_paused(network_request_id)) do |request_paused_event|
|
219
219
|
fetch_request_id = request_paused_event['requestId']
|
220
|
+
patch_request_event_headers(event, request_paused_event)
|
220
221
|
handle_request(event, fetch_request_id)
|
221
222
|
@network_event_manager.forget_request_paused(network_request_id)
|
222
223
|
end
|
@@ -277,12 +278,19 @@ class Puppeteer::NetworkManager
|
|
277
278
|
end
|
278
279
|
|
279
280
|
if request_will_be_sent_event
|
281
|
+
patch_request_event_headers(request_will_be_sent_event, event)
|
280
282
|
handle_request(request_will_be_sent_event, fetch_request_id)
|
281
283
|
else
|
282
284
|
@network_event_manager.store_request_paused(network_request_id, event)
|
283
285
|
end
|
284
286
|
end
|
285
287
|
|
288
|
+
private def patch_request_event_headers(request_will_be_sent_event, request_paused_event)
|
289
|
+
request_will_be_sent_event['request']['headers'].merge!(
|
290
|
+
# includes extra headers, like: Accept, Origin
|
291
|
+
request_paused_event['request']['headers'])
|
292
|
+
end
|
293
|
+
|
286
294
|
private def handle_request(event, fetch_request_id)
|
287
295
|
redirect_chain = []
|
288
296
|
if event['redirectResponse']
|
data/lib/puppeteer/page.rb
CHANGED
@@ -389,7 +389,18 @@ class Puppeteer::Page
|
|
389
389
|
@client.send_message('Network.getCookies', urls: (urls.empty? ? [url] : urls))['cookies']
|
390
390
|
end
|
391
391
|
|
392
|
+
# check if each cookie element has required fields ('name' and 'value')
|
393
|
+
private def assert_cookie_params(cookies, requires:)
|
394
|
+
return if cookies.all? do |cookie|
|
395
|
+
requires.all? { |field_name| cookie[field_name] || cookie[field_name.to_s] }
|
396
|
+
end
|
397
|
+
|
398
|
+
raise ArgumentError.new("Each coookie must have #{requires.join(" and ")} attribute.")
|
399
|
+
end
|
400
|
+
|
392
401
|
def delete_cookie(*cookies)
|
402
|
+
assert_cookie_params(cookies, requires: %i(name))
|
403
|
+
|
393
404
|
page_url = url
|
394
405
|
starts_with_http = page_url.start_with?("http")
|
395
406
|
cookies.each do |cookie|
|
@@ -399,6 +410,8 @@ class Puppeteer::Page
|
|
399
410
|
end
|
400
411
|
|
401
412
|
def set_cookie(*cookies)
|
413
|
+
assert_cookie_params(cookies, requires: %i(name value))
|
414
|
+
|
402
415
|
page_url = url
|
403
416
|
starts_with_http = page_url.start_with?("http")
|
404
417
|
items = cookies.map do |cookie|
|
data/lib/puppeteer/version.rb
CHANGED
data/puppeteer-ruby.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'rollbar'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.11.0'
|
34
34
|
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
35
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.27.0'
|
36
36
|
spec.add_development_dependency 'rubocop-rspec'
|
37
37
|
spec.add_development_dependency 'sinatra'
|
38
38
|
spec.add_development_dependency 'webrick'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppeteer-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.40.
|
4
|
+
version: 0.40.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.
|
173
|
+
version: 1.27.0
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.
|
180
|
+
version: 1.27.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rubocop-rspec
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|