puppeteer-ruby 0.32.1 → 0.34.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -1
- data/README.md +10 -10
- data/docs/api_coverage.md +9 -8
- data/lib/puppeteer/browser_runner.rb +4 -0
- data/lib/puppeteer/concurrent_ruby_utils.rb +20 -2
- data/lib/puppeteer/define_async_method.rb +55 -4
- data/lib/puppeteer/emulation_manager.rb +8 -4
- data/lib/puppeteer/events.rb +16 -18
- data/lib/puppeteer/frame.rb +1 -1
- data/lib/puppeteer/keyboard/us_keyboard_layout.rb +2 -2
- data/lib/puppeteer/page.rb +35 -19
- data/lib/puppeteer/page/pdf_options.rb +4 -4
- data/lib/puppeteer/puppeteer.rb +8 -3
- data/lib/puppeteer/version.rb +1 -1
- data/puppeteer-ruby.gemspec +2 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5338fde85118520d164288e9853e88f3edfadd0c0d6be491edcbde0c9d5609c
|
4
|
+
data.tar.gz: b6ac2dada9f4c7ce72401cf75b39ca452801165d68d5bd6ae537cf3a390e68ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eacd79d2af5cf69228ef6592739d20fd4f1739ec990355d904c32eb226c5dc998f7a37df7364a145df3e8beb763c304eaa8b1e1707c6aa8a237d4d8ec40f3b07
|
7
|
+
data.tar.gz: f0a725e220a109e0498c34e2f3e0d8e8e979b89d6003124d8cff7bb30c8b3579e72e5d1531a6f80669307d5a81a13f62fe99ee3c811ab9cffcb617bd12969830
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,40 @@
|
|
1
|
-
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.
|
1
|
+
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.0...master)]
|
2
2
|
|
3
3
|
* xxx
|
4
4
|
|
5
|
+
### 0.34.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.33.0...0.34.0)]
|
6
|
+
|
7
|
+
New features:
|
8
|
+
|
9
|
+
* Sync API with block
|
10
|
+
|
11
|
+
### 0.33.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.4...0.33.0)]
|
12
|
+
|
13
|
+
NOTE: Requires Ruby version >= 2.6 explicitly since this version.
|
14
|
+
|
15
|
+
Bugfix:
|
16
|
+
|
17
|
+
* Fix PDF options to work correctly on decimal numbers specified.
|
18
|
+
|
19
|
+
### 0.32.4 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.3...0.32.4)]
|
20
|
+
|
21
|
+
Bugfix:
|
22
|
+
|
23
|
+
* Fix `#type_text` to input '<' correctly.
|
24
|
+
|
25
|
+
### 0.32.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.2...0.32.3)]
|
26
|
+
|
27
|
+
Bugfix:
|
28
|
+
|
29
|
+
* Fix puppeteer-ruby to work on Rails in development mode.
|
30
|
+
|
31
|
+
|
32
|
+
### 0.32.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.1...0.32.2)]
|
33
|
+
|
34
|
+
Bugfix:
|
35
|
+
|
36
|
+
* Fix full_page option in screenshot.
|
37
|
+
|
5
38
|
### 0.32.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.0...0.32.1)]
|
6
39
|
|
7
40
|
Bugfix:
|
data/README.md
CHANGED
@@ -49,12 +49,13 @@ Puppeteer.launch(headless: false, slow_mo: 50, args: ['--guest', '--window-size=
|
|
49
49
|
page.goto("https://github.com/", wait_until: 'domcontentloaded')
|
50
50
|
|
51
51
|
form = page.query_selector("form.js-site-search-form")
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
search_input = form.query_selector("input.header-search-input")
|
53
|
+
search_input.click
|
54
|
+
page.keyboard.type_text("puppeteer")
|
55
|
+
|
56
|
+
page.wait_for_navigation do
|
57
|
+
search_input.press('Enter')
|
58
|
+
end
|
58
59
|
|
59
60
|
list = page.query_selector("ul.repo-list")
|
60
61
|
items = list.query_selector_all("div.f4")
|
@@ -136,10 +137,9 @@ RSpec.describe 'hotel.testplanisphere.dev', type: :feature do
|
|
136
137
|
|
137
138
|
reservation_link = puppeteer_page.query_selector_all('li.nav-item')[1]
|
138
139
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
)
|
140
|
+
puppeteer_page.wait_for_navigation do
|
141
|
+
reservation_link.click
|
142
|
+
end
|
143
143
|
|
144
144
|
# expectation with Capybara DSL
|
145
145
|
expect(page).to have_text('宿泊プラン一覧')
|
data/docs/api_coverage.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# API coverages
|
2
|
-
- Puppeteer version:
|
3
|
-
- puppeteer-ruby version: 0.
|
2
|
+
- Puppeteer version: v10.0.0
|
3
|
+
- puppeteer-ruby version: 0.34.0
|
4
4
|
|
5
5
|
## Puppeteer
|
6
6
|
|
@@ -81,11 +81,11 @@
|
|
81
81
|
* deleteCookie => `#delete_cookie`
|
82
82
|
* emulate
|
83
83
|
* emulateIdleState => `#emulate_idle_state`
|
84
|
-
*
|
84
|
+
* emulateMediaFeatures => `#emulate_media_features`
|
85
85
|
* emulateMediaType => `#emulate_media_type`
|
86
86
|
* ~~emulateNetworkConditions~~
|
87
87
|
* emulateTimezone => `#emulate_timezone`
|
88
|
-
*
|
88
|
+
* emulateVisionDeficiency => `#emulate_vision_deficiency`
|
89
89
|
* evaluate
|
90
90
|
* evaluateHandle => `#evaluate_handle`
|
91
91
|
* evaluateOnNewDocument => `#evaluate_on_new_document`
|
@@ -131,9 +131,9 @@
|
|
131
131
|
* ~~waitFor~~
|
132
132
|
* waitForFileChooser => `#wait_for_file_chooser`
|
133
133
|
* waitForFunction => `#wait_for_function`
|
134
|
-
* waitForNavigation => `#
|
135
|
-
* waitForRequest => `#
|
136
|
-
* waitForResponse => `#
|
134
|
+
* waitForNavigation => `#wait_for_navigation`
|
135
|
+
* waitForRequest => `#wait_for_request`
|
136
|
+
* waitForResponse => `#wait_for_response`
|
137
137
|
* waitForSelector => `#wait_for_selector`
|
138
138
|
* waitForTimeout => `#wait_for_timeout`
|
139
139
|
* waitForXPath => `#wait_for_xpath`
|
@@ -226,7 +226,7 @@
|
|
226
226
|
* url
|
227
227
|
* ~~waitFor~~
|
228
228
|
* waitForFunction => `#wait_for_function`
|
229
|
-
* waitForNavigation => `#
|
229
|
+
* waitForNavigation => `#wait_for_navigation`
|
230
230
|
* waitForSelector => `#wait_for_selector`
|
231
231
|
* waitForTimeout => `#wait_for_timeout`
|
232
232
|
* waitForXPath => `#wait_for_xpath`
|
@@ -334,6 +334,7 @@
|
|
334
334
|
|
335
335
|
## CDPSession
|
336
336
|
|
337
|
+
* connection
|
337
338
|
* detach
|
338
339
|
* send
|
339
340
|
|
@@ -161,14 +161,18 @@ class Puppeteer::BrowserRunner
|
|
161
161
|
end
|
162
162
|
|
163
163
|
private def wait_for_ws_endpoint(browser_process, timeout, preferred_revision)
|
164
|
+
lines = []
|
164
165
|
Timeout.timeout(timeout / 1000.0) do
|
165
166
|
loop do
|
166
167
|
line = browser_process.stderr.readline
|
167
168
|
/^DevTools listening on (ws:\/\/.*)$/.match(line) do |m|
|
168
169
|
return m[1]
|
169
170
|
end
|
171
|
+
lines << line
|
170
172
|
end
|
171
173
|
end
|
174
|
+
rescue EOFError
|
175
|
+
raise LaunchError.new("\n#{lines.join("\n")}\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md")
|
172
176
|
rescue Timeout::Error
|
173
177
|
raise Puppeteer::TimeoutError.new("Timed out after #{timeout} ms while trying to connect to the browser! Only Chrome at revision r#{preferred_revision} is guaranteed to work.")
|
174
178
|
end
|
@@ -1,5 +1,23 @@
|
|
1
1
|
# utility methods for Concurrent::Promises.
|
2
2
|
module Puppeteer::ConcurrentRubyUtils
|
3
|
+
module ConcurrentPromisesFutureExtension
|
4
|
+
# Extension for describing 2 concurrent tasks smartly.
|
5
|
+
#
|
6
|
+
# page.async_for_navigation.with_waiting_for_complete do
|
7
|
+
# page.click('#submit')
|
8
|
+
# end
|
9
|
+
def with_waiting_for_complete(&block)
|
10
|
+
async_block_call = Concurrent::Promises.future do
|
11
|
+
block.call
|
12
|
+
rescue => err
|
13
|
+
Logger.new($stderr).warn(err)
|
14
|
+
raise err
|
15
|
+
end
|
16
|
+
|
17
|
+
Concurrent::Promises.zip(self, async_block_call).value!.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
3
21
|
# wait for all promises.
|
4
22
|
# REMARK: This method doesn't assure the order of calling.
|
5
23
|
# for example, await_all(async1, async2) calls calls2 -> calls1 often.
|
@@ -48,7 +66,7 @@ module Puppeteer::ConcurrentRubyUtils
|
|
48
66
|
rescue => err
|
49
67
|
Logger.new($stderr).warn(err)
|
50
68
|
raise err
|
51
|
-
end
|
69
|
+
end.extend(ConcurrentPromisesFutureExtension)
|
52
70
|
end
|
53
71
|
|
54
72
|
def resolvable_future(&block)
|
@@ -56,7 +74,7 @@ module Puppeteer::ConcurrentRubyUtils
|
|
56
74
|
if block
|
57
75
|
block.call(future)
|
58
76
|
end
|
59
|
-
future
|
77
|
+
future.extend(ConcurrentPromisesFutureExtension)
|
60
78
|
end
|
61
79
|
end
|
62
80
|
|
@@ -9,22 +9,73 @@ module Puppeteer::DefineAsyncMethod
|
|
9
9
|
raise ArgumentError.new("#{async_method_name} is already defined")
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
original_method_name = async_method_name[6..-1]
|
13
|
+
original_method = instance_method(original_method_name)
|
14
|
+
|
15
|
+
# - Modify only wait_for_xxx
|
16
|
+
# - Do not modify private methods.
|
17
|
+
if method_defined?(original_method_name) && original_method_name.start_with?('wait_for_')
|
18
|
+
# def wait_for_xxx(xx, yy, &block)
|
19
|
+
#
|
20
|
+
# -> await_all(
|
21
|
+
# async_wait_for_xxx(xx, yy),
|
22
|
+
# future { block.call },
|
23
|
+
# ).first
|
24
|
+
define_method(original_method_name) do |*args, **kwargs, &block|
|
25
|
+
if block
|
26
|
+
async_method_call =
|
27
|
+
if kwargs.empty? # for Ruby 2.6
|
28
|
+
Concurrent::Promises.future do
|
29
|
+
original_method.bind(self).call(*args)
|
30
|
+
rescue => err
|
31
|
+
Logger.new($stderr).warn(err)
|
32
|
+
raise err
|
33
|
+
end
|
34
|
+
else
|
35
|
+
Concurrent::Promises.future do
|
36
|
+
original_method.bind(self).call(*args, **kwargs)
|
37
|
+
rescue => err
|
38
|
+
Logger.new($stderr).warn(err)
|
39
|
+
raise err
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
async_block_call = Concurrent::Promises.future do
|
44
|
+
block.call
|
45
|
+
rescue => err
|
46
|
+
Logger.new($stderr).warn(err)
|
47
|
+
raise err
|
48
|
+
end
|
49
|
+
|
50
|
+
Concurrent::Promises.zip(
|
51
|
+
async_method_call,
|
52
|
+
async_block_call,
|
53
|
+
).value!.first
|
54
|
+
else
|
55
|
+
if kwargs.empty? # for Ruby 2.6
|
56
|
+
original_method.bind(self).call(*args)
|
57
|
+
else
|
58
|
+
original_method.bind(self).call(*args, **kwargs)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
13
64
|
define_method(async_method_name) do |*args, **kwargs|
|
14
|
-
if kwargs.empty? # for Ruby
|
65
|
+
if kwargs.empty? # for Ruby 2.6
|
15
66
|
Concurrent::Promises.future do
|
16
67
|
original_method.bind(self).call(*args)
|
17
68
|
rescue => err
|
18
69
|
Logger.new($stderr).warn(err)
|
19
70
|
raise err
|
20
|
-
end
|
71
|
+
end.extend(Puppeteer::ConcurrentRubyUtils::ConcurrentPromisesFutureExtension)
|
21
72
|
else
|
22
73
|
Concurrent::Promises.future do
|
23
74
|
original_method.bind(self).call(*args, **kwargs)
|
24
75
|
rescue => err
|
25
76
|
Logger.new($stderr).warn(err)
|
26
77
|
raise err
|
27
|
-
end
|
78
|
+
end.extend(Puppeteer::ConcurrentRubyUtils::ConcurrentPromisesFutureExtension)
|
28
79
|
end
|
29
80
|
end
|
30
81
|
end
|
@@ -15,8 +15,12 @@ class Puppeteer::EmulationManager
|
|
15
15
|
width = viewport.width
|
16
16
|
height = viewport.height
|
17
17
|
device_scale_factor = viewport.device_scale_factor
|
18
|
-
|
19
|
-
|
18
|
+
screen_orientation =
|
19
|
+
if viewport.landscape?
|
20
|
+
{ angle: 90, type: 'landscapePrimary' }
|
21
|
+
else
|
22
|
+
{ angle: 0, type: 'portraitPrimary' }
|
23
|
+
end
|
20
24
|
has_touch = viewport.has_touch?
|
21
25
|
|
22
26
|
await_all(
|
@@ -25,14 +29,14 @@ class Puppeteer::EmulationManager
|
|
25
29
|
width: width,
|
26
30
|
height: height,
|
27
31
|
deviceScaleFactor: device_scale_factor,
|
28
|
-
|
32
|
+
screenOrientation: screen_orientation,
|
29
33
|
),
|
30
34
|
@client.async_send_message('Emulation.setTouchEmulationEnabled',
|
31
35
|
enabled: has_touch,
|
32
36
|
),
|
33
37
|
)
|
34
38
|
|
35
|
-
reload_needed = @emulating_mobile != mobile || @
|
39
|
+
reload_needed = @emulating_mobile != mobile || @has_touch != has_touch
|
36
40
|
@emulating_mobile = mobile
|
37
41
|
@has_touch = has_touch
|
38
42
|
reload_needed
|
data/lib/puppeteer/events.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'digest/md5'
|
2
2
|
|
3
3
|
module EventsDefinitionUtils
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Digest::MD5.hexdigest(str)
|
8
|
-
end
|
4
|
+
# symbol is used to prevent external parties listening to these events
|
5
|
+
module_function def symbol(str)
|
6
|
+
Digest::MD5.hexdigest(str)
|
9
7
|
end
|
10
8
|
|
11
9
|
refine Hash do
|
@@ -28,14 +26,14 @@ using EventsDefinitionUtils
|
|
28
26
|
module ConnectionEmittedEvents ; end
|
29
27
|
|
30
28
|
{
|
31
|
-
Disconnected:
|
29
|
+
Disconnected: EventsDefinitionUtils.symbol('Connection.Disconnected'),
|
32
30
|
}.define_const_into(ConnectionEmittedEvents)
|
33
31
|
|
34
32
|
# Internal events that the CDPSession class emits.
|
35
33
|
module CDPSessionEmittedEvents ; end
|
36
34
|
|
37
35
|
{
|
38
|
-
Disconnected:
|
36
|
+
Disconnected: EventsDefinitionUtils.symbol('CDPSession.Disconnected'),
|
39
37
|
}.define_const_into(CDPSessionEmittedEvents)
|
40
38
|
|
41
39
|
# All the events a Browser may emit.
|
@@ -82,10 +80,10 @@ module BrowserContextEmittedEvents ; end
|
|
82
80
|
module NetworkManagerEmittedEvents ; end
|
83
81
|
|
84
82
|
{
|
85
|
-
Request:
|
86
|
-
Response:
|
87
|
-
RequestFailed:
|
88
|
-
RequestFinished:
|
83
|
+
Request: EventsDefinitionUtils.symbol('NetworkManager.Request'),
|
84
|
+
Response: EventsDefinitionUtils.symbol('NetworkManager.Response'),
|
85
|
+
RequestFailed: EventsDefinitionUtils.symbol('NetworkManager.RequestFailed'),
|
86
|
+
RequestFinished: EventsDefinitionUtils.symbol('NetworkManager.RequestFinished'),
|
89
87
|
}.define_const_into(NetworkManagerEmittedEvents)
|
90
88
|
|
91
89
|
|
@@ -94,13 +92,13 @@ module NetworkManagerEmittedEvents ; end
|
|
94
92
|
module FrameManagerEmittedEvents ; end
|
95
93
|
|
96
94
|
{
|
97
|
-
FrameAttached:
|
98
|
-
FrameNavigated:
|
99
|
-
FrameDetached:
|
100
|
-
LifecycleEvent:
|
101
|
-
FrameNavigatedWithinDocument:
|
102
|
-
ExecutionContextCreated:
|
103
|
-
ExecutionContextDestroyed:
|
95
|
+
FrameAttached: EventsDefinitionUtils.symbol('FrameManager.FrameAttached'),
|
96
|
+
FrameNavigated: EventsDefinitionUtils.symbol('FrameManager.FrameNavigated'),
|
97
|
+
FrameDetached: EventsDefinitionUtils.symbol('FrameManager.FrameDetached'),
|
98
|
+
LifecycleEvent: EventsDefinitionUtils.symbol('FrameManager.LifecycleEvent'),
|
99
|
+
FrameNavigatedWithinDocument: EventsDefinitionUtils.symbol('FrameManager.FrameNavigatedWithinDocument'),
|
100
|
+
ExecutionContextCreated: EventsDefinitionUtils.symbol('FrameManager.ExecutionContextCreated'),
|
101
|
+
ExecutionContextDestroyed: EventsDefinitionUtils.symbol('FrameManager.ExecutionContextDestroyed'),
|
104
102
|
}.define_const_into(FrameManagerEmittedEvents)
|
105
103
|
|
106
104
|
# All the events that a page instance may emit.
|
data/lib/puppeteer/frame.rb
CHANGED
@@ -35,7 +35,7 @@ class Puppeteer::Frame
|
|
35
35
|
|
36
36
|
# @param timeout [number|nil]
|
37
37
|
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
38
|
-
|
38
|
+
def wait_for_navigation(timeout: nil, wait_until: nil)
|
39
39
|
@frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
|
40
40
|
end
|
41
41
|
|
@@ -159,7 +159,7 @@ class Puppeteer::Keyboard
|
|
159
159
|
'Semicolon': KeyDefinition.new({ 'keyCode': 186, 'code': 'Semicolon', 'shiftKey': ':', 'key': ';' }),
|
160
160
|
'Equal': KeyDefinition.new({ 'keyCode': 187, 'code': 'Equal', 'shiftKey': '+', 'key': '=' }),
|
161
161
|
'NumpadEqual': KeyDefinition.new({ 'keyCode': 187, 'code': 'NumpadEqual', 'key': '=', 'location': 3 }),
|
162
|
-
'Comma': KeyDefinition.new({ 'keyCode': 188, 'code': 'Comma', 'shiftKey': '
|
162
|
+
'Comma': KeyDefinition.new({ 'keyCode': 188, 'code': 'Comma', 'shiftKey': '<', 'key': ',' }),
|
163
163
|
'Minus': KeyDefinition.new({ 'keyCode': 189, 'code': 'Minus', 'shiftKey': '_', 'key': '-' }),
|
164
164
|
'Period': KeyDefinition.new({ 'keyCode': 190, 'code': 'Period', 'shiftKey': '>', 'key': '.' }),
|
165
165
|
'Slash': KeyDefinition.new({ 'keyCode': 191, 'code': 'Slash', 'shiftKey': '?', 'key': '/' }),
|
@@ -263,7 +263,7 @@ class Puppeteer::Keyboard
|
|
263
263
|
'Y': KeyDefinition.new({ 'keyCode': 89, 'key': 'Y', 'code': 'KeyY' }),
|
264
264
|
'Z': KeyDefinition.new({ 'keyCode': 90, 'key': 'Z', 'code': 'KeyZ' }),
|
265
265
|
':': KeyDefinition.new({ 'keyCode': 186, 'key': ':', 'code': 'Semicolon' }),
|
266
|
-
'<': KeyDefinition.new({ 'keyCode': 188, 'key': '
|
266
|
+
'<': KeyDefinition.new({ 'keyCode': 188, 'key': '<', 'code': 'Comma' }),
|
267
267
|
'_': KeyDefinition.new({ 'keyCode': 189, 'key': '_', 'code': 'Minus' }),
|
268
268
|
'>': KeyDefinition.new({ 'keyCode': 190, 'key': '>', 'code': 'Period' }),
|
269
269
|
'?': KeyDefinition.new({ 'keyCode': 191, 'key': '?', 'code': 'Slash' }),
|
data/lib/puppeteer/page.rb
CHANGED
@@ -49,7 +49,7 @@ class Puppeteer::Page
|
|
49
49
|
@client.on_event('Target.attachedToTarget') do |event|
|
50
50
|
if event['targetInfo']['type'] != 'worker'
|
51
51
|
# If we don't detach from service workers, they will never die.
|
52
|
-
|
52
|
+
@client.async_send_message('Target.detachFromTarget', sessionId: event['sessionId'])
|
53
53
|
next
|
54
54
|
end
|
55
55
|
|
@@ -637,7 +637,7 @@ class Puppeteer::Page
|
|
637
637
|
).first
|
638
638
|
end
|
639
639
|
|
640
|
-
|
640
|
+
def wait_for_navigation(timeout: nil, wait_until: nil)
|
641
641
|
main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
|
642
642
|
end
|
643
643
|
|
@@ -683,7 +683,7 @@ class Puppeteer::Page
|
|
683
683
|
end
|
684
684
|
end
|
685
685
|
|
686
|
-
|
686
|
+
def wait_for_request(url: nil, predicate: nil, timeout: nil)
|
687
687
|
if !url && !predicate
|
688
688
|
raise ArgumentError.new('url or predicate must be specified')
|
689
689
|
end
|
@@ -717,7 +717,7 @@ class Puppeteer::Page
|
|
717
717
|
# @param predicate [Proc(Puppeteer::Request -> Boolean)]
|
718
718
|
define_async_method :async_wait_for_request
|
719
719
|
|
720
|
-
|
720
|
+
def wait_for_response(url: nil, predicate: nil, timeout: nil)
|
721
721
|
if !url && !predicate
|
722
722
|
raise ArgumentError.new('url or predicate must be specified')
|
723
723
|
end
|
@@ -794,21 +794,20 @@ class Puppeteer::Page
|
|
794
794
|
@client.send_message('Emulation.setEmulatedMedia', media: media_type_str)
|
795
795
|
end
|
796
796
|
|
797
|
-
#
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
# }
|
797
|
+
# @param features [Array]
|
798
|
+
def emulate_media_features(features)
|
799
|
+
if features.nil?
|
800
|
+
@client.send_message('Emulation.setEmulatedMedia', features: nil)
|
801
|
+
elsif features.is_a?(Array)
|
802
|
+
features.each do |media_feature|
|
803
|
+
name = media_feature[:name]
|
804
|
+
unless /^(?:prefers-(?:color-scheme|reduced-motion)|color-gamut)$/.match?(name)
|
805
|
+
raise ArgumentError.new("Unsupported media feature: #{name}")
|
806
|
+
end
|
807
|
+
end
|
808
|
+
@client.send_message('Emulation.setEmulatedMedia', features: features)
|
809
|
+
end
|
810
|
+
end
|
812
811
|
|
813
812
|
# @param timezone_id [String?]
|
814
813
|
def emulate_timezone(timezone_id)
|
@@ -821,6 +820,23 @@ class Puppeteer::Page
|
|
821
820
|
end
|
822
821
|
end
|
823
822
|
|
823
|
+
VISION_DEFICIENCY_TYPES = %w[
|
824
|
+
none
|
825
|
+
achromatopsia
|
826
|
+
blurredVision
|
827
|
+
deuteranopia
|
828
|
+
protanopia
|
829
|
+
tritanopia
|
830
|
+
].freeze
|
831
|
+
|
832
|
+
def emulate_vision_deficiency(vision_deficiency_type)
|
833
|
+
value = vision_deficiency_type || 'none'
|
834
|
+
unless VISION_DEFICIENCY_TYPES.include?(value)
|
835
|
+
raise ArgumentError.new("Unsupported vision deficiency: #{vision_deficiency_type}")
|
836
|
+
end
|
837
|
+
@client.send_message('Emulation.setEmulatedVisionDeficiency', type: value)
|
838
|
+
end
|
839
|
+
|
824
840
|
# @param is_user_active [Boolean]
|
825
841
|
# @param is_screen_unlocked [Boolean]
|
826
842
|
def emulate_idle_state(is_user_active: nil, is_screen_unlocked: nil)
|
@@ -78,15 +78,15 @@ class Puppeteer::Page
|
|
78
78
|
|
79
79
|
pixels =
|
80
80
|
if parameter.is_a?(Numeric)
|
81
|
-
parameter
|
81
|
+
parameter
|
82
82
|
elsif parameter.is_a?(String)
|
83
83
|
unit = parameter[-2..-1].downcase
|
84
84
|
value =
|
85
85
|
if UNIT_TO_PIXELS.has_key?(unit)
|
86
|
-
parameter[0...-2].
|
86
|
+
parameter[0...-2].to_f
|
87
87
|
else
|
88
88
|
unit = 'px'
|
89
|
-
parameter.
|
89
|
+
parameter.to_f
|
90
90
|
end
|
91
91
|
|
92
92
|
value * UNIT_TO_PIXELS[unit]
|
@@ -94,7 +94,7 @@ class Puppeteer::Page
|
|
94
94
|
raise ArgumentError.new("page.pdf() Cannot handle parameter type: #{parameter.class}")
|
95
95
|
end
|
96
96
|
|
97
|
-
pixels / 96
|
97
|
+
pixels / 96.0
|
98
98
|
end
|
99
99
|
|
100
100
|
private def paper_size
|
data/lib/puppeteer/puppeteer.rb
CHANGED
@@ -8,6 +8,8 @@ class Puppeteer::Puppeteer
|
|
8
8
|
@is_puppeteer_core = is_puppeteer_core
|
9
9
|
end
|
10
10
|
|
11
|
+
class NoViewport ; end
|
12
|
+
|
11
13
|
# @param product [String]
|
12
14
|
# @param executable_path [String]
|
13
15
|
# @param ignore_default_args [Array<String>|nil]
|
@@ -42,7 +44,7 @@ class Puppeteer::Puppeteer
|
|
42
44
|
devtools: nil,
|
43
45
|
headless: nil,
|
44
46
|
ignore_https_errors: nil,
|
45
|
-
default_viewport:
|
47
|
+
default_viewport: NoViewport.new,
|
46
48
|
slow_mo: nil
|
47
49
|
)
|
48
50
|
options = {
|
@@ -63,8 +65,11 @@ class Puppeteer::Puppeteer
|
|
63
65
|
default_viewport: default_viewport,
|
64
66
|
slow_mo: slow_mo,
|
65
67
|
}
|
68
|
+
if default_viewport.is_a?(NoViewport)
|
69
|
+
options.delete(:default_viewport)
|
70
|
+
end
|
66
71
|
|
67
|
-
@product_name
|
72
|
+
@product_name = product
|
68
73
|
browser = launcher.launch(options)
|
69
74
|
if block_given?
|
70
75
|
begin
|
@@ -118,7 +123,7 @@ class Puppeteer::Puppeteer
|
|
118
123
|
end
|
119
124
|
|
120
125
|
private def launcher
|
121
|
-
@launcher
|
126
|
+
@launcher = Puppeteer::Launcher.new(
|
122
127
|
project_root: @project_root,
|
123
128
|
preferred_revision: @preferred_revision,
|
124
129
|
is_puppeteer_core: @is_puppeteer_core,
|
data/lib/puppeteer/version.rb
CHANGED
data/puppeteer-ruby.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
+
spec.required_ruby_version = '>= 2.6'
|
23
24
|
spec.add_dependency 'concurrent-ruby', '~> 1.1.0'
|
24
25
|
spec.add_dependency 'websocket-driver', '>= 0.6.0'
|
25
26
|
spec.add_dependency 'mime-types', '>= 3.0'
|
@@ -31,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
31
32
|
spec.add_development_dependency 'rollbar'
|
32
33
|
spec.add_development_dependency 'rspec', '~> 3.10.0 '
|
33
34
|
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
34
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.17.0'
|
35
36
|
spec.add_development_dependency 'rubocop-rspec'
|
36
37
|
spec.add_development_dependency 'sinatra'
|
37
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.
|
4
|
+
version: 0.34.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-23 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.17.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.17.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rubocop-rspec
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -335,14 +335,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
335
335
|
requirements:
|
336
336
|
- - ">="
|
337
337
|
- !ruby/object:Gem::Version
|
338
|
-
version: '
|
338
|
+
version: '2.6'
|
339
339
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
340
340
|
requirements:
|
341
341
|
- - ">="
|
342
342
|
- !ruby/object:Gem::Version
|
343
343
|
version: '0'
|
344
344
|
requirements: []
|
345
|
-
rubygems_version: 3.
|
345
|
+
rubygems_version: 3.1.6
|
346
346
|
signing_key:
|
347
347
|
specification_version: 4
|
348
348
|
summary: A ruby port of puppeteer
|