puppeteer-ruby 0.0.17 → 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.
@@ -101,7 +101,9 @@ class Puppeteer::Page
101
101
  end
102
102
  # client.on('Runtime.consoleAPICalled', event => this._onConsoleAPI(event));
103
103
  # client.on('Runtime.bindingCalled', event => this._onBindingCalled(event));
104
- # client.on('Page.javascriptDialogOpening', event => this._onDialog(event));
104
+ @client.on_event 'Page.javascriptDialogOpening' do |event|
105
+ handle_dialog_opening(event)
106
+ end
105
107
  # client.on('Runtime.exceptionThrown', exception => this._handleException(exception.exceptionDetails));
106
108
  # client.on('Inspector.targetCrashed', event => this._onTargetCrashed());
107
109
  # client.on('Performance.metrics', event => this._emitMetrics(event));
@@ -129,7 +131,7 @@ class Puppeteer::Page
129
131
  EVENT_MAPPINGS = {
130
132
  close: 'Events.Page.Close',
131
133
  # console: 'Events.Page.Console',
132
- # dialog: 'Events.Page.Dialog',
134
+ dialog: 'Events.Page.Dialog',
133
135
  domcontentloaded: 'Events.Page.DOMContentLoaded',
134
136
  # error:
135
137
  frameattached: 'Events.Page.FrameAttached',
@@ -266,7 +268,13 @@ class Puppeteer::Page
266
268
  @frame_manager.main_frame
267
269
  end
268
270
 
269
- attr_reader :keyboard, :touch_screen, :coverage, :accessibility
271
+ attr_reader :touch_screen, :coverage, :accessibility
272
+
273
+ def keyboard(&block)
274
+ @keyboard.instance_eval(&block) unless block.nil?
275
+
276
+ @keyboard
277
+ end
270
278
 
271
279
  def frames
272
280
  @frame_manager.frames
@@ -626,20 +634,17 @@ class Puppeteer::Page
626
634
  # this.emit(Events.Page.Console, message);
627
635
  # }
628
636
 
629
- # _onDialog(event) {
630
- # let dialogType = null;
631
- # if (event.type === 'alert')
632
- # dialogType = Dialog.Type.Alert;
633
- # else if (event.type === 'confirm')
634
- # dialogType = Dialog.Type.Confirm;
635
- # else if (event.type === 'prompt')
636
- # dialogType = Dialog.Type.Prompt;
637
- # else if (event.type === 'beforeunload')
638
- # dialogType = Dialog.Type.BeforeUnload;
639
- # assert(dialogType, 'Unknown javascript dialog type: ' + event.type);
640
- # const dialog = new Dialog(this._client, dialogType, event.message, event.defaultPrompt);
641
- # this.emit(Events.Page.Dialog, dialog);
642
- # }
637
+ private def handle_dialog_opening(event)
638
+ dialog_type = event['type']
639
+ unless %w(alert confirm prompt beforeunload).include?(dialog_type)
640
+ raise ArgumentError.new("Unknown javascript dialog type: #{dialog_type}")
641
+ end
642
+ dialog = Puppeteer::Dialog.new(@client,
643
+ type: dialog_type,
644
+ message: event['message'],
645
+ default_value: event['defaultPrompt'])
646
+ emit_event('Events.Page.Dialog', dialog)
647
+ end
643
648
 
644
649
  # @return [String]
645
650
  def url
@@ -934,16 +939,16 @@ class Puppeteer::Page
934
939
  clip = { x: 0, y: 0, width: width, height: height, scale: 1 }
935
940
 
936
941
  screen_orientation =
937
- if @viewport.landscape?
942
+ if @viewport&.landscape?
938
943
  { angle: 90, type: 'landscapePrimary' }
939
944
  else
940
945
  { angle: 0, type: 'portraitPrimary' }
941
946
  end
942
947
  @client.send_message('Emulation.setDeviceMetricsOverride',
943
- mobile: @viewport.mobile?,
948
+ mobile: @viewport&.mobile? || false,
944
949
  width: width,
945
950
  height: height,
946
- deviceScaleFactor: @viewport.device_scale_factor,
951
+ deviceScaleFactor: @viewport&.device_scale_factor || 1,
947
952
  screenOrientation: screen_orientation)
948
953
  end
949
954
 
@@ -1116,6 +1121,11 @@ class Puppeteer::Page
1116
1121
 
1117
1122
  define_async_method :async_wait_for_selector
1118
1123
 
1124
+ # @param milliseconds [Integer] the number of milliseconds to wait.
1125
+ def wait_for_timeout(milliseconds)
1126
+ main_frame.wait_for_timeout(milliseconds)
1127
+ end
1128
+
1119
1129
  # @param xpath [String]
1120
1130
  # @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
1121
1131
  # @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
@@ -1126,12 +1136,13 @@ class Puppeteer::Page
1126
1136
 
1127
1137
  define_async_method :async_wait_for_xpath
1128
1138
 
1129
- # @param {Function|string} pageFunction
1130
- # @param {!{polling?: string|number, timeout?: number}=} options
1131
- # @param {!Array<*>} args
1132
- # @return {!Promise<!Puppeteer.JSHandle>}
1133
- def wait_for_function(page_function, options = {}, *args)
1134
- main_frame.wait_for_function(page_function, options, *args)
1139
+ # @param page_function [String]
1140
+ # @param args [Integer|Array]
1141
+ # @param polling [String]
1142
+ # @param timeout [Integer]
1143
+ # @return [Puppeteer::JSHandle]
1144
+ def wait_for_function(page_function, args: [], polling: nil, timeout: nil)
1145
+ main_frame.wait_for_function(page_function, args: args, polling: polling, timeout: timeout)
1135
1146
  end
1136
1147
 
1137
1148
  define_async_method :async_wait_for_function
@@ -6,6 +6,7 @@ class Puppeteer::RemoteObject
6
6
  # @param payload [Hash]
7
7
  def initialize(payload)
8
8
  @object_id = payload['objectId']
9
+ @type = payload['type']
9
10
  @sub_type = payload['subtype']
10
11
  @unserializable_value = payload['unserializableValue']
11
12
  @value = payload['value']
@@ -42,6 +43,21 @@ class Puppeteer::RemoteObject
42
43
  end
43
44
  end
44
45
 
46
+ # @return [String]
47
+ def type_str
48
+ # used in JSHandle#to_s
49
+ # original logic:
50
+ # if (this._remoteObject.objectId) {
51
+ # const type = this._remoteObject.subtype || this._remoteObject.type;
52
+ # return 'JSHandle@' + type;
53
+ # }
54
+ if @object_id
55
+ @sub_type || @type
56
+ else
57
+ nil
58
+ end
59
+ end
60
+
45
61
  # used in JSHandle#properties
46
62
  def properties(client)
47
63
  # original logic:
@@ -64,7 +80,18 @@ class Puppeteer::RemoteObject
64
80
 
65
81
  # used in ElementHandle#_box_model
66
82
  def box_model(client)
67
- client.send_message('DOM.getBoxModel', objectId: @object_id)
83
+ result = client.send_message('DOM.getBoxModel', objectId: @object_id)
84
+
85
+ # Firefox returns width/height = 0, content/padding/border/margin = [nil, nil, nil, nil, nil, nil, nil, nil]
86
+ # while Chrome throws Error(Could not compute box model)
87
+ model = result['model']
88
+ if model['width'] == 0 && model['height'] == 0 &&
89
+ %w(content padding border margin).all? { |key| model[key].all?(&:nil?) }
90
+
91
+ debug_puts('Could not compute box model in Firefox.')
92
+ return nil
93
+ end
94
+ result
68
95
  rescue => err
69
96
  debug_puts(err)
70
97
  nil
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = '0.0.17'
2
+ VERSION = '0.0.22'
3
3
  end
@@ -25,7 +25,7 @@ class Puppeteer::WaitTask
25
25
  @dom_world = dom_world
26
26
  @polling = polling
27
27
  @timeout = timeout
28
- @predicate_body = predicate_body
28
+ @predicate_body = "return (#{predicate_body})(...args);"
29
29
  @args = args
30
30
  @run_count = 0
31
31
  @dom_world._wait_tasks.add(self)
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rake', '~> 10.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
29
- spec.add_development_dependency 'rubocop', '~> 0.86.0'
29
+ spec.add_development_dependency 'rubocop', '~> 0.90.0'
30
30
  spec.add_development_dependency 'rubocop-rspec'
31
31
  spec.add_development_dependency 'sinatra'
32
32
  spec.add_development_dependency 'yard'
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.17
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-07-28 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
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.86.0
131
+ version: 0.90.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.86.0
138
+ version: 0.90.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -193,11 +193,13 @@ files:
193
193
  - ".rspec"
194
194
  - ".rubocop.yml"
195
195
  - ".travis.yml"
196
+ - Dockerfile
196
197
  - Gemfile
197
198
  - README.md
198
199
  - Rakefile
199
200
  - bin/console
200
201
  - bin/setup
202
+ - docker-compose.yml
201
203
  - lib/puppeteer.rb
202
204
  - lib/puppeteer/browser.rb
203
205
  - lib/puppeteer/browser_context.rb
@@ -211,6 +213,7 @@ files:
211
213
  - lib/puppeteer/define_async_method.rb
212
214
  - lib/puppeteer/device.rb
213
215
  - lib/puppeteer/devices.rb
216
+ - lib/puppeteer/dialog.rb
214
217
  - lib/puppeteer/dom_world.rb
215
218
  - lib/puppeteer/element_handle.rb
216
219
  - lib/puppeteer/element_handle/bounding_box.rb
@@ -234,6 +237,7 @@ files:
234
237
  - lib/puppeteer/launcher/browser_options.rb
235
238
  - lib/puppeteer/launcher/chrome.rb
236
239
  - lib/puppeteer/launcher/chrome_arg_options.rb
240
+ - lib/puppeteer/launcher/firefox.rb
237
241
  - lib/puppeteer/launcher/launch_options.rb
238
242
  - lib/puppeteer/lifecycle_watcher.rb
239
243
  - lib/puppeteer/mouse.rb