puppeteer-ruby 0.32.2 → 0.32.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/docs/api_coverage.md +2 -2
- data/lib/puppeteer/browser_runner.rb +4 -0
- data/lib/puppeteer/emulation_manager.rb +7 -3
- data/lib/puppeteer/events.rb +16 -18
- data/lib/puppeteer/page.rb +32 -16
- data/lib/puppeteer/puppeteer.rb +8 -3
- 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: ec9dc0a222f1d9ab65c345585296fdecfb855b2e4b9f28784e9a8563910ca590
|
4
|
+
data.tar.gz: 7073166d8410e4e3817dfd7cb410a4e260c3b9308031d31f79aa05206a19ebc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd566d6c348d2d15170a59a530ea6a1f5fc4e82180af93e6944f142ed60720dab181f97641d4419e4da92823efbc1a8e72ecbe83c42a5bae1328aac0ea35597e
|
7
|
+
data.tar.gz: 2575db60f2f6f7cfc75a60bf04fa9e55b370000ea8d0371eb32d3178ac1a5ae21803c51e83165c0ea3881576848c97775ba06c505501c90e5b66adf6c3275039
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.
|
1
|
+
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.3...master)]
|
2
2
|
|
3
3
|
* xxx
|
4
4
|
|
5
|
+
### 0.32.3 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.2...0.32.3)]
|
6
|
+
|
7
|
+
Bugfix:
|
8
|
+
|
9
|
+
* Fix puppeteer-ruby to work on Rails in development mode.
|
10
|
+
|
11
|
+
|
5
12
|
### 0.32.2 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.32.1...0.32.2)]
|
6
13
|
|
7
14
|
Bugfix:
|
data/docs/api_coverage.md
CHANGED
@@ -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`
|
@@ -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
|
@@ -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,7 +29,7 @@ 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,
|
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/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
|
|
@@ -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)
|
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
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'rollbar'
|
32
32
|
spec.add_development_dependency 'rspec', '~> 3.10.0 '
|
33
33
|
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
34
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 1.15.0'
|
35
35
|
spec.add_development_dependency 'rubocop-rspec'
|
36
36
|
spec.add_development_dependency 'sinatra'
|
37
37
|
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.32.
|
4
|
+
version: 0.32.3
|
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-05-31 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.15.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.15.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rubocop-rspec
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|