puppeteer-ruby 0.0.21 → 0.0.22

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f429910f146a926bd830400269da848120ca070da2a64d5dfec0c9861a6c46f4
4
- data.tar.gz: e0ba66f60e283d7d0cc6263f7750dc7ddc6f9cd17ceaaaf4ae247c524f8986f8
3
+ metadata.gz: 627b2272803511db582250101edac0b5f1f0191abdf86255c6f16d0f088cc82e
4
+ data.tar.gz: 70458a316f8ecce1b784bd84595c3f0fa248c77e671e4458384c494a1471c196
5
5
  SHA512:
6
- metadata.gz: 1251d762934da872f78028c12c33e9e025ab331c3e09abe4bb80191e82fa1d09681c204fd1da8c1b86668cf9f317f9f7030d65c6d4aa078355afe8089ffce4eb
7
- data.tar.gz: 2a28ea494da354c5658c1618806ddb291d53d4a2f2bde0579c5aefc01da523ddc17511cfa5ff6315761c09b7a83b6d9526ff0020cc2275b871788c88a19e70ed
6
+ metadata.gz: 2baf0cb4769fc7100495b3dc590293085e3219c661bd164cdb28f0aad1975f18cba17890029156a08873f879ef370c196c3d995bfd040d073d42d0b49acbeef3
7
+ data.tar.gz: 67a23e46e7d439b76f438c59d062fe5daea0d216469e79ea1b4af2b8d60c4f9070455de22e51b9523fde2a67692919420bce2b05becf948120b71d426c4c560f
@@ -61,7 +61,11 @@ class Puppeteer
61
61
  is_puppeteer_core: true,
62
62
  )
63
63
 
64
- @puppeteer.send(method, *args, **kwargs, &block)
64
+ if kwargs.empty? # for Ruby < 2.7
65
+ @puppeteer.public_send(method, *args, &block)
66
+ else
67
+ @puppeteer.public_send(method, *args, **kwargs, &block)
68
+ end
65
69
  end
66
70
 
67
71
  # @param project_root [String]
@@ -127,7 +131,7 @@ class Puppeteer
127
131
  ignore_https_errors: ignore_https_errors,
128
132
  default_viewport: default_viewport,
129
133
  slow_mo: slow_mo,
130
- }.compact
134
+ }
131
135
 
132
136
  @product_name ||= product
133
137
  browser = launcher.launch(options)
@@ -21,9 +21,18 @@ class Puppeteer::BrowserRunner
21
21
 
22
22
  class BrowserProcess
23
23
  def initialize(env, executable_path, args)
24
+ @spawnargs =
25
+ if args && !args.empty?
26
+ [executable_path] + args
27
+ else
28
+ [executable_path]
29
+ end
30
+
24
31
  stdin, @stdout, @stderr, @thread = Open3.popen3(env, executable_path, *args)
25
32
  stdin.close
26
33
  @pid = @thread.pid
34
+ rescue Errno::ENOENT => err
35
+ raise LaunchError.new(err.message)
27
36
  end
28
37
 
29
38
  def kill
@@ -37,7 +46,13 @@ class Puppeteer::BrowserRunner
37
46
  @thread.join
38
47
  end
39
48
 
40
- attr_reader :stdout, :stderr
49
+ attr_reader :stdout, :stderr, :spawnargs
50
+ end
51
+
52
+ class LaunchError < StandardError
53
+ def initialize(reason)
54
+ super("Failed to launch browser! #{reason}")
55
+ end
41
56
  end
42
57
 
43
58
  # @param {!(Launcher.LaunchOptions)=} options
@@ -123,12 +138,12 @@ class Puppeteer::BrowserRunner
123
138
 
124
139
  # @return {Promise}
125
140
  def kill
126
- unless @closed
127
- @proc.kill
128
- end
129
141
  if @temp_directory
130
142
  FileUtils.rm_rf(@temp_directory)
131
143
  end
144
+ unless @closed
145
+ @proc.kill
146
+ end
132
147
  end
133
148
 
134
149
 
@@ -4,9 +4,13 @@ module Puppeteer::ConcurrentRubyUtils
4
4
  # REMARK: This method doesn't assure the order of calling.
5
5
  # for example, await_all(async1, async2) calls calls2 -> calls1 often.
6
6
  def await_all(*args)
7
- if args.length == 1 && args[0].is_a?(Enumerable)
8
- Concurrent::Promises.zip(*(args[0])).value!
7
+ if args.length == 1 && args.first.is_a?(Enumerable)
8
+ await_all(*args.first)
9
9
  else
10
+ if args.any? { |arg| !arg.is_a?(Concurrent::Promises::Future) }
11
+ raise ArgumentError.new("All argument must be a Future: #{args}")
12
+ end
13
+
10
14
  Concurrent::Promises.zip(*args).value!
11
15
  end
12
16
  end
@@ -15,9 +19,13 @@ module Puppeteer::ConcurrentRubyUtils
15
19
  # REMARK: This method doesn't assure the order of calling.
16
20
  # for example, await_all(async1, async2) calls calls2 -> calls1 often.
17
21
  def await_any(*args)
18
- if args.length == 1 && args[0].is_a?(Enumerable)
19
- Concurrent::Promises.any(*(args[0])).value!
22
+ if args.length == 1 && args.first.is_a?(Enumerable)
23
+ await_any(*args.first)
20
24
  else
25
+ if args.any? { |arg| !arg.is_a?(Concurrent::Promises::Future) }
26
+ raise ArgumentError.new("All argument must be a Future: #{args}")
27
+ end
28
+
21
29
  Concurrent::Promises.any(*args).value!
22
30
  end
23
31
  end
@@ -32,7 +40,12 @@ module Puppeteer::ConcurrentRubyUtils
32
40
  end
33
41
 
34
42
  def future(&block)
35
- Concurrent::Promises.future(&block)
43
+ Concurrent::Promises.future do
44
+ block.call
45
+ rescue => err
46
+ Logger.new($stderr).warn(err)
47
+ raise err
48
+ end
36
49
  end
37
50
 
38
51
  def resolvable_future(&block)
@@ -23,7 +23,6 @@ module Puppeteer::Launcher
23
23
  preferred_revision: preferred_revision,
24
24
  is_puppeteer_core: is_puppeteer_core,
25
25
  )
26
- raise NotImplementedError.new('FirefoxLauncher is not implemented yet.')
27
26
  end
28
27
 
29
28
  Chrome.new(
@@ -28,7 +28,8 @@ module Puppeteer::Launcher
28
28
  # @property {number=} slowMo
29
29
  def initialize(options)
30
30
  @ignore_https_errors = options[:ignore_https_errors] || false
31
- @default_viewport = options[:default_viewport] || Puppeteer::Viewport.new(width: 800, height: 600)
31
+ # `default_viewport: nil` must be respected here.
32
+ @default_viewport = options.key?(:default_viewport) ? options[:default_viewport] : Puppeteer::Viewport.new(width: 800, height: 600)
32
33
  @slow_mo = options[:slow_mo] || 0
33
34
  end
34
35
 
@@ -12,9 +12,9 @@ module Puppeteer::Launcher
12
12
 
13
13
  chrome_arguments =
14
14
  if !@launch_options.ignore_default_args
15
- default_args.to_a
15
+ default_args(options).to_a
16
16
  elsif @launch_options.ignore_default_args.is_a?(Enumerable)
17
- default_args.reject do |arg|
17
+ default_args(options).reject do |arg|
18
18
  @launch_options.ignore_default_args.include?(arg)
19
19
  end.to_a
20
20
  else
@@ -141,11 +141,7 @@ module Puppeteer::Launcher
141
141
 
142
142
  # @return [DefaultArgs]
143
143
  def default_args(options = nil)
144
- if options.nil?
145
- @default_args ||= DefaultArgs.new(@chrome_arg_options)
146
- else
147
- DefaultArgs.new(ChromeArgOptions.new(options))
148
- end
144
+ DefaultArgs.new(ChromeArgOptions.new(options || {}))
149
145
  end
150
146
 
151
147
  # @return [Puppeteer::Browser]
@@ -206,7 +202,7 @@ module Puppeteer::Launcher
206
202
  resolve_executable_path
207
203
  end
208
204
 
209
- private def product
205
+ def product
210
206
  'chrome'
211
207
  end
212
208
  end
@@ -12,9 +12,9 @@ module Puppeteer::Launcher
12
12
 
13
13
  firefox_arguments =
14
14
  if !@launch_options.ignore_default_args
15
- default_args.to_a
15
+ default_args(options).to_a
16
16
  elsif @launch_options.ignore_default_args.is_a?(Enumerable)
17
- default_args.reject do |arg|
17
+ default_args(options).reject do |arg|
18
18
  @launch_options.ignore_default_args.include?(arg)
19
19
  end.to_a
20
20
  else
@@ -127,7 +127,7 @@ module Puppeteer::Launcher
127
127
  resolve_executable_path
128
128
  end
129
129
 
130
- private def product
130
+ def product
131
131
  'firefox'
132
132
  end
133
133
 
@@ -173,11 +173,7 @@ module Puppeteer::Launcher
173
173
 
174
174
  # @return [DefaultArgs]
175
175
  def default_args(options = nil)
176
- if options.nil?
177
- @default_args ||= DefaultArgs.new(@chrome_arg_options)
178
- else
179
- DefaultArgs.new(ChromeArgOptions.new(options))
180
- end
176
+ DefaultArgs.new(ChromeArgOptions.new(options || {}))
181
177
  end
182
178
 
183
179
  private def create_profile(extra_prefs = {})
@@ -939,16 +939,16 @@ class Puppeteer::Page
939
939
  clip = { x: 0, y: 0, width: width, height: height, scale: 1 }
940
940
 
941
941
  screen_orientation =
942
- if @viewport.landscape?
942
+ if @viewport&.landscape?
943
943
  { angle: 90, type: 'landscapePrimary' }
944
944
  else
945
945
  { angle: 0, type: 'portraitPrimary' }
946
946
  end
947
947
  @client.send_message('Emulation.setDeviceMetricsOverride',
948
- mobile: @viewport.mobile?,
948
+ mobile: @viewport&.mobile? || false,
949
949
  width: width,
950
950
  height: height,
951
- deviceScaleFactor: @viewport.device_scale_factor,
951
+ deviceScaleFactor: @viewport&.device_scale_factor || 1,
952
952
  screenOrientation: screen_orientation)
953
953
  end
954
954
 
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = '0.0.21'
2
+ VERSION = '0.0.22'
3
3
  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.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-26 00:00:00.000000000 Z
11
+ date: 2020-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby