puppeteer-ruby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,7 @@ module Puppeteer::Launcher
14
14
  # @return {!Puppeteer.ProductLauncher}
15
15
  module_function def new(project_root:, preferred_revision:, is_puppeteer_core:, product:)
16
16
  if product == 'firefox'
17
- raise NotImplementedError.new("FirefoxLauncher is not implemented yet.")
17
+ raise NotImplementedError.new('FirefoxLauncher is not implemented yet.')
18
18
  end
19
19
 
20
20
  Chrome.new(
@@ -8,7 +8,7 @@ module Puppeteer::Launcher
8
8
  @is_puppeteer_core = is_puppeteer_core
9
9
  end
10
10
 
11
- class ExecutablePathNotFound < StandardError ; end
11
+ class ExecutablePathNotFound < StandardError; end
12
12
 
13
13
  # @returns [String] Chrome Executable file path.
14
14
  # @raise [ExecutablePathNotFound]
@@ -25,7 +25,7 @@ module Puppeteer::Launcher
25
25
  end
26
26
 
27
27
  # temporal logic.
28
- if RUBY_PLATFORM.include?("darwin") # MacOS
28
+ if RUBY_PLATFORM.include?('darwin') # MacOS
29
29
  '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
30
30
  else
31
31
  '/usr/bin/google-chrome'
@@ -24,7 +24,7 @@ module Puppeteer::Launcher
24
24
  #
25
25
  # let temporaryUserDataDir = null;
26
26
 
27
- if chrome_arguments.none?{ |arg| arg.start_with?('--remote-debugging-') }
27
+ if chrome_arguments.none? { |arg| arg.start_with?('--remote-debugging-') }
28
28
  if @launch_options.pipe?
29
29
  chrome_arguments << '--remote-debugging-pipe'
30
30
  else
@@ -33,7 +33,7 @@ module Puppeteer::Launcher
33
33
  end
34
34
 
35
35
  temporary_user_data_dir = nil
36
- if chrome_arguments.none?{ |arg| arg.start_with?('--user-data-dir') }
36
+ if chrome_arguments.none? { |arg| arg.start_with?('--user-data-dir') }
37
37
  temporary_user_data_dir = Dir.mktmpdir('puppeteer_dev_profile-')
38
38
  chrome_arguments << "--user-data-dir=#{temporary_user_data_dir}"
39
39
  end
@@ -48,7 +48,7 @@ module Puppeteer::Launcher
48
48
  dumpio: @launch_options.dumpio?,
49
49
  env: @launch_options.env,
50
50
  pipe: use_pipe,
51
- );
51
+ )
52
52
 
53
53
  begin
54
54
  connection = runner.setup_connection(
@@ -64,7 +64,7 @@ module Puppeteer::Launcher
64
64
  ignore_https_errors: @browser_options.ignore_https_errors?,
65
65
  default_viewport: @browser_options.default_viewport,
66
66
  process: runner.proc,
67
- close_callback: ->{ runner.close },
67
+ close_callback: -> { runner.close },
68
68
  )
69
69
 
70
70
  browser.wait_for_target(predicate: ->(target) { target.type == 'page' })
@@ -115,7 +115,7 @@ module Puppeteer::Launcher
115
115
  chrome_arguments << '--auto-open-devtools-for-tabs'
116
116
  end
117
117
 
118
- if (chrome_arg_options.headless?)
118
+ if chrome_arg_options.headless?
119
119
  chrome_arguments.concat([
120
120
  '--headless',
121
121
  '--hide-scrollbars',
@@ -123,7 +123,7 @@ module Puppeteer::Launcher
123
123
  ])
124
124
  end
125
125
 
126
- if chrome_arg_options.args.all?{ |arg| arg.start_with?('-') }
126
+ if chrome_arg_options.args.all? { |arg| arg.start_with?('-') }
127
127
  chrome_arguments << 'about:blank'
128
128
  end
129
129
 
@@ -50,7 +50,7 @@ class Puppeteer::LifecycleWatcher
50
50
  end
51
51
  end
52
52
 
53
- class TerminatedError < StandardError ; end
53
+ class TerminatedError < StandardError; end
54
54
 
55
55
  # * @param {!Puppeteer.FrameManager} frameManager
56
56
  # * @param {!Puppeteer.Frame} frame
@@ -118,15 +118,13 @@ class Puppeteer::LifecycleWatcher
118
118
 
119
119
  def timeout_or_termination_promise
120
120
  if @timeout > 0
121
- future {
122
- begin
123
- Timeout.timeout(@timeout / 1000.0) do
124
- @termination_promise.value!
125
- end
126
- rescue Timeout::Error
127
- raise Puppeteer::FrameManager::NavigationError.new("Navigation timeout of #{@timeout}ms exceeded")
121
+ future do
122
+ Timeout.timeout(@timeout / 1000.0) do
123
+ @termination_promise.value!
128
124
  end
129
- }
125
+ rescue Timeout::Error
126
+ raise Puppeteer::FrameManager::NavigationError.new("Navigation timeout of #{@timeout}ms exceeded")
127
+ end
130
128
  else
131
129
  @termination_promise
132
130
  end
@@ -107,7 +107,7 @@ class Puppeteer::NetworkManager
107
107
  update_protocol_cache_disabled
108
108
  @client.send_message('Fetch.enable',
109
109
  handleAuthRequests: true,
110
- patterns: [{urlPattern: '*'}],
110
+ patterns: [{ urlPattern: '*' }],
111
111
  )
112
112
  else
113
113
  update_protocol_cache_disabled
@@ -34,12 +34,12 @@ class Puppeteer::Page
34
34
  @mouse = Puppeteer::Mouse.new(client, @keyboard)
35
35
  @timeout_settings = Puppeteer::TimeoutSettings.new
36
36
  @touchscreen = Puppeteer::TouchScreen.new(client, @keyboard)
37
- #@accessibility = Accessibility.new(client)
37
+ # @accessibility = Accessibility.new(client)
38
38
  @frame_manager = Puppeteer::FrameManager.new(client, self, ignore_https_errors, @timeout_settings)
39
39
  @emulation_manager = Puppeteer::EmulationManager.new(client)
40
- #@tracing = Tracing.new(client)
40
+ # @tracing = Tracing.new(client)
41
41
  @page_bindings = {}
42
- #@coverage = Coverage.new(client)
42
+ # @coverage = Coverage.new(client)
43
43
  @javascript_enabled = true
44
44
  @screenshot_task_queue = screenshot_task_queue
45
45
 
@@ -183,21 +183,21 @@ class Puppeteer::Page
183
183
  @target.browser_context
184
184
  end
185
185
 
186
- class TargetCrashedError < StandardError ; end
186
+ class TargetCrashedError < StandardError; end
187
187
 
188
188
  private def handle_target_crashed
189
189
  emit_event 'error', TargetCrashedError.new('Page crashed!')
190
190
  end
191
191
 
192
192
  private def handle_log_entry_added(event)
193
- entry = event["entry"]
194
- level = entry["level"]
195
- text = entry["text"]
196
- source = entry["source"]
197
- url = entry["url"]
198
- line_number = entry["lineNumber"]
199
-
200
- if_present(entry["args"]) do |args|
193
+ entry = event['entry']
194
+ level = entry['level']
195
+ text = entry['text']
196
+ source = entry['source']
197
+ url = entry['url']
198
+ line_number = entry['lineNumber']
199
+
200
+ if_present(entry['args']) do |args|
201
201
  args.map do |arg|
202
202
  Puppeteer::RemoteObject.new(arg).async_release(@client)
203
203
  end
@@ -205,7 +205,7 @@ class Puppeteer::Page
205
205
  if source != 'worker'
206
206
  console_message_location = Puppeteer::ConsoleMessage::Location.new(
207
207
  url: url, line_number: line_number)
208
- emit_event("Events.Page.Console",
208
+ emit_event('Events.Page.Console',
209
209
  Puppeteer::ConsoleMessage.new(level, text, [], console_message_location))
210
210
  end
211
211
  end
@@ -686,7 +686,7 @@ class Puppeteer::Page
686
686
  if_present(entries[index]) do |entry|
687
687
  await_all(
688
688
  async_wait_for_navigation(timeout: timeout, wait_until: wait_until),
689
- @client.async_send_message('Page.navigateToHistoryEntry', entryId: entry['id'])
689
+ @client.async_send_message('Page.navigateToHistoryEntry', entryId: entry['id']),
690
690
  )
691
691
  end
692
692
  end
@@ -699,9 +699,9 @@ class Puppeteer::Page
699
699
 
700
700
  # @param {boolean} enabled
701
701
  def javascript_enabled=(enabled)
702
- return if (@javascript_enabled == enabled)
702
+ return if @javascript_enabled == enabled
703
703
  @javascript_enabled = enabled
704
- @client.send_message('Emulation.setScriptExecutionDisabled', value: !enabled);
704
+ @client.send_message('Emulation.setScriptExecutionDisabled', value: !enabled)
705
705
  end
706
706
 
707
707
  # /**
@@ -788,7 +788,7 @@ class Puppeteer::Page
788
788
  def screenshot(options = {})
789
789
  screenshot_options = ScreenshotOptions.new(options)
790
790
 
791
- #@screenshot_task_queue.post_task(-> { screenshot_task(screenshot_options.type, screenshot_options) })
791
+ # @screenshot_task_queue.post_task(-> { screenshot_task(screenshot_options.type, screenshot_options) })
792
792
  screenshot_task(screenshot_options.type, screenshot_options)
793
793
  end
794
794
 
@@ -796,7 +796,7 @@ class Puppeteer::Page
796
796
  # @param {!ScreenshotOptions=} options
797
797
  # @return {!Promise<!Buffer|!String>}
798
798
  private def screenshot_task(format, screenshot_options)
799
- @client.send_message('Target.activateTarget', targetId: @target.target_id);
799
+ @client.send_message('Target.activateTarget', targetId: @target.target_id)
800
800
 
801
801
  clip = if_present(screenshot_options.clip) do |rect|
802
802
  x = rect[:x].round
@@ -5,10 +5,10 @@ class Puppeteer::RemoteObject
5
5
 
6
6
  # @param payload [Hash]
7
7
  def initialize(payload)
8
- @object_id = payload["objectId"]
9
- @sub_type = payload["subtype"]
10
- @unserializable_value = payload["unserializableValue"]
11
- @value = payload["value"]
8
+ @object_id = payload['objectId']
9
+ @sub_type = payload['subtype']
10
+ @unserializable_value = payload['unserializableValue']
11
+ @value = payload['value']
12
12
  end
13
13
 
14
14
  attr_reader :sub_type
@@ -35,8 +35,8 @@ class Puppeteer::RemoteObject
35
35
  'returnByValue': true,
36
36
  'awaitPromise': true,
37
37
  }
38
- response = client.send_message("Runtime.callFunctionOn", params)
39
- Puppeteer::RemoteObject.new(response["result"])
38
+ response = client.send_message('Runtime.callFunctionOn', params)
39
+ Puppeteer::RemoteObject.new(response['result'])
40
40
  else
41
41
  nil
42
42
  end
@@ -54,7 +54,7 @@ class Puppeteer::RemoteObject
54
54
 
55
55
  # used in ElementHandle#content_frame
56
56
  def node_info(client)
57
- client.send_message("DOM.describeNode", objectId: @object_id)
57
+ client.send_message('DOM.describeNode', objectId: @object_id)
58
58
  end
59
59
 
60
60
  # helper#valueFromRemoteObject
@@ -74,7 +74,7 @@ class Puppeteer::RemoteObject
74
74
  # default:
75
75
  # throw new Error('Unsupported unserializable value: ' + remoteObject.unserializableValue);
76
76
  # }
77
- raise NotImplementedError.new("unserializable_value is not implemented yet")
77
+ raise NotImplementedError.new('unserializable_value is not implemented yet')
78
78
  else
79
79
  @value
80
80
  end
@@ -45,11 +45,11 @@ class Puppeteer::Target
45
45
 
46
46
  attr_reader :target_id, :initialized_promise
47
47
 
48
- class InitializeFailure < StandardError ; end
48
+ class InitializeFailure < StandardError; end
49
49
 
50
50
  def handle_initialized(success)
51
51
  unless success
52
- @initialized_promise.reject(InitializeFailure.new("Failed to create target for page"))
52
+ @initialized_promise.reject(InitializeFailure.new('Failed to create target for page'))
53
53
  end
54
54
  @on_initialize_succeeded&.call
55
55
  @initialized_promise.fulfill(true)
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class Puppeteer::WaitTask
2
- class TerminatedError < StandardError ; end
2
+ class TerminatedError < StandardError; end
3
3
 
4
4
  def initialize
5
5
  end
@@ -37,6 +37,9 @@ class Puppeteer::WebSocket
37
37
 
38
38
  Thread.new do
39
39
  wait_for_data until @ready_state >= STATE_CLOSING
40
+ rescue EOFError
41
+ # Google Chrome was gone.
42
+ # We have nothing todo. Just finish polling.
40
43
  end
41
44
  end
42
45
 
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'concurrent-ruby', "~> 1.1.0"
21
+ spec.add_dependency 'concurrent-ruby', '~> 1.1.0'
22
22
  spec.add_dependency 'websocket-driver', '>= 0.6.0'
23
23
  spec.add_dependency 'mime-types', '>= 3.0'
24
24
  spec.add_development_dependency 'bundler', '~> 1.17'
25
- spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'pry-byebug'
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'rubocop', '~> 0.80.0'
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-05 00:00:00.000000000 Z
11
+ date: 2020-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.17'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: pry-byebug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -129,6 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".circleci/config.yml"
132
133
  - ".gitignore"
133
134
  - ".rspec"
134
135
  - ".rubocop.yml"
@@ -140,7 +141,6 @@ files:
140
141
  - bin/console
141
142
  - bin/setup
142
143
  - docker-compose.yml
143
- - example.rb
144
144
  - lib/puppeteer.rb
145
145
  - lib/puppeteer/async_await_behavior.rb
146
146
  - lib/puppeteer/browser.rb
data/example.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'puppeteer';
2
-
3
- Puppeteer.launch(headless: false) do |browser|
4
- page = browser.pages.first || browser.new_page
5
- page.goto("https://github.com/YusukeIwaki")
6
- page.screenshot(path: "YusukeIwaki.png")
7
- end