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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c8324de827decfcd0aa132c6bf7e3cf65e451631269038f27062f2970eb8f45
4
- data.tar.gz: 70d4558f1dcf29f4c9454d6c33f36e59ab53d8c700adc6852b8c449ab7d1a10c
3
+ metadata.gz: ec9dc0a222f1d9ab65c345585296fdecfb855b2e4b9f28784e9a8563910ca590
4
+ data.tar.gz: 7073166d8410e4e3817dfd7cb410a4e260c3b9308031d31f79aa05206a19ebc4
5
5
  SHA512:
6
- metadata.gz: 6759482be60145918aae8475427bbf9ea2e0548cc2cd6a812fd0b9e943c24542f82cfb9ffbc6910a050cbd6d532b2b1177a5f80688bb3c73650837b900f52ccb
7
- data.tar.gz: 181663e004ab1a0ce377e6b3215d1468a4823db3beb86478fd3c213d70f14a6ae8e1aea3191b9c04d8e28a5600a05decb2f21661578be380efde57a5bc0d7000
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.2...master)]
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
- * ~~emulateMediaFeatures~~
84
+ * emulateMediaFeatures => `#emulate_media_features`
85
85
  * emulateMediaType => `#emulate_media_type`
86
86
  * ~~emulateNetworkConditions~~
87
87
  * emulateTimezone => `#emulate_timezone`
88
- * ~~emulateVisionDeficiency~~
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
- # /** @type {Protocol.Emulation.ScreenOrientation} */
19
- # const screenOrientation = viewport.isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
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
- # screenOrientation: screen_orientation,
32
+ screenOrientation: screen_orientation,
29
33
  ),
30
34
  @client.async_send_message('Emulation.setTouchEmulationEnabled',
31
35
  enabled: has_touch,
@@ -1,11 +1,9 @@
1
1
  require 'digest/md5'
2
2
 
3
3
  module EventsDefinitionUtils
4
- refine Kernel do
5
- # Symbol is used to prevent external parties listening to these events
6
- def Symbol(str)
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: Symbol('Connection.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: Symbol('CDPSession.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: Symbol('NetworkManager.Request'),
86
- Response: Symbol('NetworkManager.Response'),
87
- RequestFailed: Symbol('NetworkManager.RequestFailed'),
88
- RequestFinished: Symbol('NetworkManager.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: Symbol('FrameManager.FrameAttached'),
98
- FrameNavigated: Symbol('FrameManager.FrameNavigated'),
99
- FrameDetached: Symbol('FrameManager.FrameDetached'),
100
- LifecycleEvent: Symbol('FrameManager.LifecycleEvent'),
101
- FrameNavigatedWithinDocument: Symbol('FrameManager.FrameNavigatedWithinDocument'),
102
- ExecutionContextCreated: Symbol('FrameManager.ExecutionContextCreated'),
103
- ExecutionContextDestroyed: Symbol('FrameManager.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.
@@ -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
- await @client.send_message('Target.detachFromTarget', sessionId: event['sessionId'])
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
- # * @param {?Array<MediaFeature>} features
799
- # */
800
- # async emulateMediaFeatures(features) {
801
- # if (features === null)
802
- # await this._client.send('Emulation.setEmulatedMedia', {features: null});
803
- # if (Array.isArray(features)) {
804
- # features.every(mediaFeature => {
805
- # const name = mediaFeature.name;
806
- # assert(/^prefers-(?:color-scheme|reduced-motion)$/.test(name), 'Unsupported media feature: ' + name);
807
- # return true;
808
- # });
809
- # await this._client.send('Emulation.setEmulatedMedia', {features: features});
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)
@@ -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: nil,
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 ||= product
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 ||= Puppeteer::Launcher.new(
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,
@@ -1,3 +1,3 @@
1
1
  module Puppeteer
2
- VERSION = '0.32.2'
2
+ VERSION = '0.32.3'
3
3
  end
@@ -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.12.0'
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.2
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-04-12 00:00:00.000000000 Z
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.12.0
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.12.0
180
+ version: 1.15.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubocop-rspec
183
183
  requirement: !ruby/object:Gem::Requirement