puppeteer-ruby 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -2
- data/lib/puppeteer.rb +7 -1
- data/lib/puppeteer/browser.rb +36 -9
- data/lib/puppeteer/browser_context.rb +35 -5
- data/lib/puppeteer/connection.rb +6 -1
- data/lib/puppeteer/debug_print.rb +1 -1
- data/lib/puppeteer/dom_world.rb +16 -13
- data/lib/puppeteer/element_handle.rb +4 -3
- data/lib/puppeteer/env.rb +18 -0
- data/lib/puppeteer/keyboard.rb +3 -2
- data/lib/puppeteer/mouse.rb +16 -0
- data/lib/puppeteer/page.rb +33 -13
- data/lib/puppeteer/request.rb +23 -29
- data/lib/puppeteer/version.rb +1 -1
- data/lib/puppeteer/web_socket.rb +7 -0
- data/puppeteer-ruby.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2277fda99720c2566927af9a2acfc56da2b8e87ee10521871c368fd4a05649b2
|
4
|
+
data.tar.gz: 59636e168935b0fb6c964cd62355ae3becf8199ed2ee1af58cb512ccacc9d7cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b45495a2ae160e740e242bc04bb81bfa493c1101583393f78e8e7ff3d065c00594fe0196b8225ac73e281a17428127597d11c8f8323ba6b58d64b437e2979d97
|
7
|
+
data.tar.gz: 72c9bd1ca17f37927ceb51a79904583c638066e29cdb08cc2534e77bcc7b3ee348e53e69546ecd579917bd6d8db9c4413d4a63cf617ffa33b8c69c756603439e
|
data/.circleci/config.yml
CHANGED
@@ -13,10 +13,10 @@ jobs:
|
|
13
13
|
- run:
|
14
14
|
name: rspec
|
15
15
|
command: |
|
16
|
-
bundle exec rspec --profile 10 \
|
16
|
+
DEBUG=1 bundle exec rspec --profile 10 \
|
17
17
|
--format RspecJunitFormatter \
|
18
18
|
--out test_results/rspec.xml \
|
19
|
-
--format
|
19
|
+
--format documentation
|
20
20
|
|
21
21
|
deploy:
|
22
22
|
docker:
|
data/lib/puppeteer.rb
CHANGED
@@ -2,6 +2,8 @@ require 'concurrent'
|
|
2
2
|
|
3
3
|
class Puppeteer; end
|
4
4
|
|
5
|
+
require 'puppeteer/env'
|
6
|
+
|
5
7
|
# Custom data types.
|
6
8
|
require 'puppeteer/device'
|
7
9
|
require 'puppeteer/errors'
|
@@ -168,7 +170,11 @@ class Puppeteer
|
|
168
170
|
}.compact
|
169
171
|
browser = launcher.connect(options)
|
170
172
|
if block_given?
|
171
|
-
|
173
|
+
begin
|
174
|
+
yield(browser)
|
175
|
+
ensure
|
176
|
+
browser.disconnect
|
177
|
+
end
|
172
178
|
else
|
173
179
|
browser
|
174
180
|
end
|
data/lib/puppeteer/browser.rb
CHANGED
@@ -43,7 +43,7 @@ class Puppeteer::Browser
|
|
43
43
|
@default_context = Puppeteer::BrowserContext.new(@connection, self, nil)
|
44
44
|
@contexts = {}
|
45
45
|
context_ids.each do |context_id|
|
46
|
-
@contexts[context_id] = Puppeteer::BrowserContext.new(@connection, self
|
46
|
+
@contexts[context_id] = Puppeteer::BrowserContext.new(@connection, self, context_id)
|
47
47
|
end
|
48
48
|
@targets = {}
|
49
49
|
@connection.on_event 'Events.Connection.Disconnected' do
|
@@ -70,6 +70,15 @@ class Puppeteer::Browser
|
|
70
70
|
add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
|
71
71
|
end
|
72
72
|
|
73
|
+
# @param event_name [Symbol]
|
74
|
+
def once(event_name, &block)
|
75
|
+
unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
|
76
|
+
raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
|
77
|
+
end
|
78
|
+
|
79
|
+
observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
|
80
|
+
end
|
81
|
+
|
73
82
|
# @return [Puppeteer::BrowserRunner::BrowserProcess]
|
74
83
|
def process
|
75
84
|
@process
|
@@ -94,7 +103,7 @@ class Puppeteer::Browser
|
|
94
103
|
# @param context_id [String]
|
95
104
|
def dispose_context(context_id)
|
96
105
|
@connection.send_message('Target.disposeBrowserContext', browserContextId: context_id)
|
97
|
-
@contexts.
|
106
|
+
@contexts.delete(context_id)
|
98
107
|
end
|
99
108
|
|
100
109
|
class TargetAlreadyExistError < StandardError
|
@@ -166,7 +175,7 @@ class Puppeteer::Browser
|
|
166
175
|
end
|
167
176
|
|
168
177
|
# @return [String]
|
169
|
-
def
|
178
|
+
def ws_endpoint
|
170
179
|
@connection.url
|
171
180
|
end
|
172
181
|
|
@@ -196,7 +205,7 @@ class Puppeteer::Browser
|
|
196
205
|
|
197
206
|
# @return {!Target}
|
198
207
|
def target
|
199
|
-
targets.
|
208
|
+
targets.find { |target| target.type == 'browser' }
|
200
209
|
end
|
201
210
|
|
202
211
|
# used only in Target#opener
|
@@ -204,12 +213,11 @@ class Puppeteer::Browser
|
|
204
213
|
@targets[target_id]
|
205
214
|
end
|
206
215
|
|
207
|
-
# @param
|
208
|
-
# @
|
209
|
-
# @return {!Promise<!Target>}
|
216
|
+
# @param predicate [Proc(Puppeteer::Target -> Boolean)]
|
217
|
+
# @return [Puppeteer::Target]
|
210
218
|
def wait_for_target(predicate:, timeout: nil)
|
211
219
|
timeout_in_sec = (timeout || 30000).to_i / 1000.0
|
212
|
-
existing_target = targets.
|
220
|
+
existing_target = targets.find { |target| predicate.call(target) }
|
213
221
|
return existing_target if existing_target
|
214
222
|
|
215
223
|
event_listening_ids = []
|
@@ -233,11 +241,18 @@ class Puppeteer::Browser
|
|
233
241
|
else
|
234
242
|
target_promise.value!
|
235
243
|
end
|
244
|
+
rescue Timeout::Error
|
245
|
+
raise Puppeteer::TimeoutError.new("waiting for target failed: timeout #{timeout}ms exceeded")
|
236
246
|
ensure
|
237
247
|
remove_event_listener(*event_listening_ids)
|
238
248
|
end
|
239
249
|
end
|
240
250
|
|
251
|
+
# @!method async_wait_for_target(predicate:, timeout: nil)
|
252
|
+
#
|
253
|
+
# @param predicate [Proc(Puppeteer::Target -> Boolean)]
|
254
|
+
define_async_method :async_wait_for_target
|
255
|
+
|
241
256
|
# @return {!Promise<!Array<!Puppeteer.Page>>}
|
242
257
|
def pages
|
243
258
|
browser_contexts.flat_map(&:pages)
|
@@ -266,7 +281,19 @@ class Puppeteer::Browser
|
|
266
281
|
!@connection.closed?
|
267
282
|
end
|
268
283
|
|
284
|
+
class Version
|
285
|
+
def initialize(hash)
|
286
|
+
@protocol_version = hash['protocolVersion']
|
287
|
+
@product = hash['product']
|
288
|
+
@revision = hash['revision']
|
289
|
+
@user_agent = hash['userAgent']
|
290
|
+
@js_version = hash['jsVersion']
|
291
|
+
end
|
292
|
+
|
293
|
+
attr_reader :protocol_version, :product, :revision, :user_agent, :js_version
|
294
|
+
end
|
295
|
+
|
269
296
|
private def get_version
|
270
|
-
@connection.send_message('Browser.getVersion')
|
297
|
+
Version.new(@connection.send_message('Browser.getVersion'))
|
271
298
|
end
|
272
299
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class Puppeteer::BrowserContext
|
2
2
|
include Puppeteer::EventCallbackable
|
3
|
+
using Puppeteer::DefineAsyncMethod
|
3
4
|
|
4
5
|
# @param {!Puppeteer.Connection} connection
|
5
6
|
# @param {!Browser} browser
|
@@ -10,14 +11,38 @@ class Puppeteer::BrowserContext
|
|
10
11
|
@id = context_id
|
11
12
|
end
|
12
13
|
|
14
|
+
EVENT_MAPPINGS = {
|
15
|
+
disconnected: 'Events.BrowserContext.Disconnected',
|
16
|
+
targetcreated: 'Events.BrowserContext.TargetCreated',
|
17
|
+
targetchanged: 'Events.BrowserContext.TargetChanged',
|
18
|
+
targetdestroyed: 'Events.BrowserContext.TargetDestroyed',
|
19
|
+
}
|
20
|
+
|
21
|
+
# @param event_name [Symbol] either of :disconnected, :targetcreated, :targetchanged, :targetdestroyed
|
22
|
+
def on(event_name, &block)
|
23
|
+
unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
|
24
|
+
raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
|
25
|
+
end
|
26
|
+
|
27
|
+
add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param event_name [Symbol]
|
31
|
+
def once(event_name, &block)
|
32
|
+
unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
|
33
|
+
raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
|
34
|
+
end
|
35
|
+
|
36
|
+
observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
|
37
|
+
end
|
38
|
+
|
13
39
|
# @return {!Array<!Target>} target
|
14
40
|
def targets
|
15
41
|
@browser.targets.select { |target| target.browser_context == self }
|
16
42
|
end
|
17
43
|
|
18
|
-
# @param
|
19
|
-
# @
|
20
|
-
# @return {!Promise<!Target>}
|
44
|
+
# @param predicate [Proc(Puppeteer::Target -> Boolean)]
|
45
|
+
# @return [Puppeteer::Target]
|
21
46
|
def wait_for_target(predicate:, timeout: nil)
|
22
47
|
@browser.wait_for_target(
|
23
48
|
predicate: ->(target) { target.browser_context == self && predicate.call(target) },
|
@@ -25,13 +50,18 @@ class Puppeteer::BrowserContext
|
|
25
50
|
)
|
26
51
|
end
|
27
52
|
|
53
|
+
# @!method async_wait_for_target(predicate:, timeout: nil)
|
54
|
+
#
|
55
|
+
# @param predicate [Proc(Puppeteer::Target -> Boolean)]
|
56
|
+
define_async_method :async_wait_for_target
|
57
|
+
|
28
58
|
# @return {!Promise<!Array<!Puppeteer.Page>>}
|
29
59
|
def pages
|
30
60
|
targets.select { |target| target.type == 'page' }.map(&:page).reject { |page| !page }
|
31
61
|
end
|
32
62
|
|
33
63
|
def incognito?
|
34
|
-
|
64
|
+
!!@id
|
35
65
|
end
|
36
66
|
|
37
67
|
# /**
|
@@ -82,7 +112,7 @@ class Puppeteer::BrowserContext
|
|
82
112
|
end
|
83
113
|
|
84
114
|
def close
|
85
|
-
|
115
|
+
unless @id
|
86
116
|
raise 'Non-incognito profiles cannot be closed!'
|
87
117
|
end
|
88
118
|
@browser.dispose_context(@id)
|
data/lib/puppeteer/connection.rb
CHANGED
@@ -49,13 +49,18 @@ class Puppeteer::Connection
|
|
49
49
|
async_handle_message(message)
|
50
50
|
end
|
51
51
|
@transport.on_close do |reason, code|
|
52
|
-
handle_close
|
52
|
+
handle_close
|
53
53
|
end
|
54
54
|
|
55
55
|
@sessions = {}
|
56
56
|
@closed = false
|
57
57
|
end
|
58
58
|
|
59
|
+
# used only in Browser#connected?
|
60
|
+
def closed?
|
61
|
+
@closed
|
62
|
+
end
|
63
|
+
|
59
64
|
private def sleep_before_handling_message(message)
|
60
65
|
# Puppeteer doesn't handle any Network monitoring responses.
|
61
66
|
# So we don't have to sleep.
|
data/lib/puppeteer/dom_world.rb
CHANGED
@@ -314,25 +314,28 @@ class Puppeteer::DOMWorld
|
|
314
314
|
# }
|
315
315
|
# }
|
316
316
|
|
317
|
+
class ElementNotFoundError < StandardError
|
318
|
+
def initialize(selector)
|
319
|
+
super("No node found for selector: #{selector}")
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
317
323
|
# @param selector [String]
|
318
324
|
# @param delay [Number]
|
319
325
|
# @param button [String] "left"|"right"|"middle"
|
320
326
|
# @param click_count [Number]
|
321
327
|
def click(selector, delay: nil, button: nil, click_count: nil)
|
322
|
-
handle = S(selector)
|
328
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
323
329
|
handle.click(delay: delay, button: button, click_count: click_count)
|
324
330
|
handle.dispose
|
325
331
|
end
|
326
332
|
|
327
|
-
#
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
# await handle.focus();
|
334
|
-
# await handle.dispose();
|
335
|
-
# }
|
333
|
+
# @param selector [String]
|
334
|
+
def focus(selector)
|
335
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
336
|
+
handle.focus
|
337
|
+
handle.dispose
|
338
|
+
end
|
336
339
|
|
337
340
|
# /**
|
338
341
|
# * @param {string} selector
|
@@ -347,7 +350,7 @@ class Puppeteer::DOMWorld
|
|
347
350
|
# @param selector [String]
|
348
351
|
# @return [Array<String>]
|
349
352
|
def select(selector, *values)
|
350
|
-
handle = S(selector)
|
353
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
351
354
|
result = handle.select(*values)
|
352
355
|
handle.dispose
|
353
356
|
|
@@ -356,7 +359,7 @@ class Puppeteer::DOMWorld
|
|
356
359
|
|
357
360
|
# @param selector [String]
|
358
361
|
def tap(selector)
|
359
|
-
handle = S(selector)
|
362
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
360
363
|
handle.tap
|
361
364
|
handle.dispose
|
362
365
|
end
|
@@ -365,7 +368,7 @@ class Puppeteer::DOMWorld
|
|
365
368
|
# @param text [String]
|
366
369
|
# @param delay [Number]
|
367
370
|
def type_text(selector, text, delay: nil)
|
368
|
-
handle = S(selector)
|
371
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
369
372
|
handle.type_text(text, delay: delay)
|
370
373
|
handle.dispose
|
371
374
|
end
|
@@ -23,7 +23,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def content_frame
|
26
|
-
node_info = @remote_object.node_info
|
26
|
+
node_info = @remote_object.node_info(@client)
|
27
27
|
frame_id = node_info['node']['frameId']
|
28
28
|
if frame_id.is_a?(String)
|
29
29
|
@frame_manager.frame(frame_id)
|
@@ -208,10 +208,11 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
208
208
|
define_async_method :async_type_text
|
209
209
|
|
210
210
|
# @param key [String]
|
211
|
+
# @param text [String]
|
211
212
|
# @param delay [number|nil]
|
212
|
-
def press(key, delay: nil)
|
213
|
+
def press(key, delay: nil, text: nil)
|
213
214
|
focus
|
214
|
-
@page.keyboard.press(key, delay: delay)
|
215
|
+
@page.keyboard.press(key, delay: delay, text: text)
|
215
216
|
end
|
216
217
|
|
217
218
|
define_async_method :async_press
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Puppeteer::Env
|
2
|
+
# indicates whether DEBUG=1 is specified.
|
3
|
+
#
|
4
|
+
# @return [Boolean]
|
5
|
+
def debug?
|
6
|
+
['1', 'true'].include?(ENV['DEBUG'].to_s)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ci?
|
10
|
+
['1', 'true'].include?(ENV['CI'].to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Puppeteer
|
15
|
+
def self.env
|
16
|
+
Puppeteer::Env.new
|
17
|
+
end
|
18
|
+
end
|
data/lib/puppeteer/keyboard.rb
CHANGED
@@ -149,9 +149,10 @@ class Puppeteer::Keyboard
|
|
149
149
|
define_async_method :async_type_text
|
150
150
|
|
151
151
|
# @param key [String]
|
152
|
+
# @param text [String]
|
152
153
|
# @return [Future]
|
153
|
-
def press(key, delay: nil)
|
154
|
-
down(key)
|
154
|
+
def press(key, delay: nil, text: nil)
|
155
|
+
down(key, text: text)
|
155
156
|
if delay
|
156
157
|
sleep(delay.to_i / 1000.0)
|
157
158
|
end
|
data/lib/puppeteer/mouse.rb
CHANGED
@@ -94,5 +94,21 @@ class Puppeteer::Mouse
|
|
94
94
|
)
|
95
95
|
end
|
96
96
|
|
97
|
+
# Dispatches a `mousewheel` event.
|
98
|
+
#
|
99
|
+
# @param delta_x [Integer]
|
100
|
+
# @param delta_y [Integer]
|
101
|
+
def wheel(delta_x: 0, delta_y: 0)
|
102
|
+
@client.send_message('Input.dispatchMouseEvent',
|
103
|
+
type: 'mouseWheel',
|
104
|
+
x: @x,
|
105
|
+
y: @y,
|
106
|
+
deltaX: delta_x,
|
107
|
+
deltaY: delta_y,
|
108
|
+
modifiers: @keyboard.modifiers,
|
109
|
+
pointerType: 'mouse',
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
97
113
|
define_async_method :async_up
|
98
114
|
end
|
data/lib/puppeteer/page.rb
CHANGED
@@ -681,12 +681,14 @@ class Puppeteer::Page
|
|
681
681
|
).first
|
682
682
|
end
|
683
683
|
|
684
|
-
# @param timeout [number|nil]
|
685
|
-
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
686
684
|
private def wait_for_navigation(timeout: nil, wait_until: nil)
|
687
685
|
main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
|
688
686
|
end
|
689
687
|
|
688
|
+
# @!method async_wait_for_navigation(timeout: nil, wait_until: nil)
|
689
|
+
#
|
690
|
+
# @param timeout [number|nil]
|
691
|
+
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
690
692
|
define_async_method :async_wait_for_navigation
|
691
693
|
|
692
694
|
private def wait_for_network_manager_event(event_name, predicate:, timeout:)
|
@@ -725,13 +727,6 @@ class Puppeteer::Page
|
|
725
727
|
end
|
726
728
|
end
|
727
729
|
|
728
|
-
# - Waits until request URL matches
|
729
|
-
# `wait_for_request(url: 'https://example.com/awesome')`
|
730
|
-
# - Waits until request matches the given predicate
|
731
|
-
# `wait_for_request(predicate: -> (req){ req.url.start_with?('https://example.com/search') })`
|
732
|
-
#
|
733
|
-
# @param url [String]
|
734
|
-
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
|
735
730
|
private def wait_for_request(url: nil, predicate: nil, timeout: nil)
|
736
731
|
if !url && !predicate
|
737
732
|
raise ArgumentError.new('url or predicate must be specified')
|
@@ -752,10 +747,20 @@ class Puppeteer::Page
|
|
752
747
|
)
|
753
748
|
end
|
754
749
|
|
755
|
-
|
756
|
-
|
750
|
+
# @!method async_wait_for_request(url: nil, predicate: nil, timeout: nil)
|
751
|
+
#
|
752
|
+
# Waits until request URL matches or request matches the given predicate.
|
753
|
+
#
|
754
|
+
# Waits until request URL matches
|
755
|
+
# wait_for_request(url: 'https://example.com/awesome')
|
756
|
+
#
|
757
|
+
# Waits until request matches the given predicate
|
758
|
+
# wait_for_request(predicate: -> (req){ req.url.start_with?('https://example.com/search') })
|
759
|
+
#
|
757
760
|
# @param url [String]
|
758
761
|
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
|
762
|
+
define_async_method :async_wait_for_request
|
763
|
+
|
759
764
|
private def wait_for_response(url: nil, predicate: nil, timeout: nil)
|
760
765
|
if !url && !predicate
|
761
766
|
raise ArgumentError.new('url or predicate must be specified')
|
@@ -776,6 +781,10 @@ class Puppeteer::Page
|
|
776
781
|
)
|
777
782
|
end
|
778
783
|
|
784
|
+
# @!method async_wait_for_response(url: nil, predicate: nil, timeout: nil)
|
785
|
+
#
|
786
|
+
# @param url [String]
|
787
|
+
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
|
779
788
|
define_async_method :async_wait_for_response
|
780
789
|
|
781
790
|
# @param timeout [number|nil]
|
@@ -1071,8 +1080,19 @@ class Puppeteer::Page
|
|
1071
1080
|
define_async_method :async_select
|
1072
1081
|
|
1073
1082
|
# @param selector [String]
|
1074
|
-
def tap(selector)
|
1075
|
-
|
1083
|
+
def tap(selector: nil, &block)
|
1084
|
+
# resolves double meaning of tap.
|
1085
|
+
if selector.nil? && block
|
1086
|
+
# Original usage of Object#tap.
|
1087
|
+
#
|
1088
|
+
# browser.new_page.tap do |page|
|
1089
|
+
# ...
|
1090
|
+
# end
|
1091
|
+
super(&block)
|
1092
|
+
else
|
1093
|
+
# Puppeteer's Page#tap.
|
1094
|
+
main_frame.tap(selector)
|
1095
|
+
end
|
1076
1096
|
end
|
1077
1097
|
|
1078
1098
|
define_async_method :async_tap
|
data/lib/puppeteer/request.rb
CHANGED
@@ -106,17 +106,15 @@ class Puppeteer::Request
|
|
106
106
|
#
|
107
107
|
# Example:
|
108
108
|
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# ```
|
119
|
-
#`
|
109
|
+
# page.on 'request' do |req|
|
110
|
+
# # Override headers
|
111
|
+
# headers = req.headers.merge(
|
112
|
+
# foo: 'bar', # set "foo" header
|
113
|
+
# origin: nil, # remove "origin" header
|
114
|
+
# )
|
115
|
+
# req.continue(headers: headers)
|
116
|
+
# end
|
117
|
+
#
|
120
118
|
# @param error_code [String|Symbol]
|
121
119
|
def continue(url: nil, method: nil, post_data: nil, headers: nil)
|
122
120
|
# Request interception is not supported for data: urls.
|
@@ -152,15 +150,13 @@ class Puppeteer::Request
|
|
152
150
|
#
|
153
151
|
# Example:
|
154
152
|
#
|
155
|
-
#
|
156
|
-
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
# end
|
163
|
-
# ````
|
153
|
+
# page.on 'request' do |req|
|
154
|
+
# req.respond(
|
155
|
+
# status: 404,
|
156
|
+
# content_type: 'text/plain',
|
157
|
+
# body: 'Not Found!'
|
158
|
+
# )
|
159
|
+
# end
|
164
160
|
#
|
165
161
|
# @param status [Integer]
|
166
162
|
# @param headers [Hash<String, String>]
|
@@ -211,16 +207,14 @@ class Puppeteer::Request
|
|
211
207
|
#
|
212
208
|
# Example:
|
213
209
|
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
#
|
219
|
-
#
|
210
|
+
# page.on 'request' do |req|
|
211
|
+
# if req.url.include?("porn")
|
212
|
+
# req.abort
|
213
|
+
# else
|
214
|
+
# req.continue
|
215
|
+
# end
|
220
216
|
# end
|
221
|
-
#
|
222
|
-
# ```
|
223
|
-
#`
|
217
|
+
#
|
224
218
|
# @param error_code [String|Symbol]
|
225
219
|
def abort(error_code: :failed)
|
226
220
|
# Request interception is not supported for data: urls.
|
data/lib/puppeteer/version.rb
CHANGED
data/lib/puppeteer/web_socket.rb
CHANGED
@@ -16,10 +16,14 @@ class Puppeteer::WebSocket
|
|
16
16
|
|
17
17
|
def write(data)
|
18
18
|
@socket.write(data)
|
19
|
+
rescue Errno::EPIPE
|
20
|
+
raise EOFError.new('already closed')
|
19
21
|
end
|
20
22
|
|
21
23
|
def readpartial(maxlen = 1024)
|
22
24
|
@socket.readpartial(maxlen)
|
25
|
+
rescue Errno::ECONNRESET
|
26
|
+
raise EOFError.new('closed by remote')
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -40,6 +44,9 @@ class Puppeteer::WebSocket
|
|
40
44
|
rescue EOFError
|
41
45
|
# Google Chrome was gone.
|
42
46
|
# We have nothing todo. Just finish polling.
|
47
|
+
if @ready_state < STATE_CLOSING
|
48
|
+
handle_on_close(reason: 'Going Away', code: 1001)
|
49
|
+
end
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
data/puppeteer-ruby.gemspec
CHANGED
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
29
29
|
spec.add_development_dependency 'rubocop', '~> 0.86.0'
|
30
30
|
spec.add_development_dependency 'rubocop-rspec'
|
31
|
+
spec.add_development_dependency 'sinatra'
|
31
32
|
spec.add_development_dependency 'yard'
|
32
33
|
end
|
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.0.
|
4
|
+
version: 0.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sinatra
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: yard
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,6 +217,7 @@ files:
|
|
203
217
|
- lib/puppeteer/element_handle/box_model.rb
|
204
218
|
- lib/puppeteer/element_handle/point.rb
|
205
219
|
- lib/puppeteer/emulation_manager.rb
|
220
|
+
- lib/puppeteer/env.rb
|
206
221
|
- lib/puppeteer/errors.rb
|
207
222
|
- lib/puppeteer/event_callbackable.rb
|
208
223
|
- lib/puppeteer/execution_context.rb
|