puppeteer-ruby 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/docs/Puppeteer.html +414 -96
  4. data/docs/Puppeteer/AsyncAwaitBehavior.html +1 -1
  5. data/docs/Puppeteer/Browser.html +34 -34
  6. data/docs/Puppeteer/BrowserContext.html +2 -2
  7. data/docs/Puppeteer/BrowserFetcher.html +1 -1
  8. data/docs/Puppeteer/BrowserRunner.html +1 -1
  9. data/docs/Puppeteer/BrowserRunner/BrowserProcess.html +1 -1
  10. data/docs/Puppeteer/CDPSession.html +2 -2
  11. data/docs/Puppeteer/CDPSession/Error.html +1 -1
  12. data/docs/Puppeteer/ConcurrentRubyUtils.html +14 -6
  13. data/docs/Puppeteer/Connection.html +2 -2
  14. data/docs/Puppeteer/Connection/MessageCallback.html +1 -1
  15. data/docs/Puppeteer/Connection/ProtocolError.html +1 -1
  16. data/docs/Puppeteer/Connection/RequestDebugPrinter.html +1 -1
  17. data/docs/Puppeteer/Connection/ResponseDebugPrinter.html +1 -1
  18. data/docs/Puppeteer/ConsoleMessage.html +1 -1
  19. data/docs/Puppeteer/ConsoleMessage/Location.html +1 -1
  20. data/docs/Puppeteer/DOMWorld.html +1 -1
  21. data/docs/Puppeteer/DOMWorld/DetachedError.html +1 -1
  22. data/docs/Puppeteer/DebugPrint.html +1 -1
  23. data/docs/Puppeteer/Device.html +1 -1
  24. data/docs/Puppeteer/Devices.html +1 -1
  25. data/docs/Puppeteer/ElementHandle.html +1 -1
  26. data/docs/Puppeteer/ElementHandle/BoundingBox.html +1 -1
  27. data/docs/Puppeteer/ElementHandle/BoxModel.html +1 -1
  28. data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +1 -1
  29. data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +1 -1
  30. data/docs/Puppeteer/ElementHandle/Point.html +1 -1
  31. data/docs/Puppeteer/ElementHandle/ScrollIntoViewError.html +1 -1
  32. data/docs/Puppeteer/EmulationManager.html +1 -1
  33. data/docs/Puppeteer/EventCallbackable.html +83 -17
  34. data/docs/Puppeteer/EventCallbackable/EventListeners.html +1 -1
  35. data/docs/Puppeteer/ExecutionContext.html +1 -1
  36. data/docs/Puppeteer/ExecutionContext/EvaluationError.html +1 -1
  37. data/docs/Puppeteer/ExecutionContext/JavaScriptExpression.html +1 -1
  38. data/docs/Puppeteer/ExecutionContext/JavaScriptFunction.html +1 -1
  39. data/docs/Puppeteer/FileChooser.html +1 -1
  40. data/docs/Puppeteer/Frame.html +1 -1
  41. data/docs/Puppeteer/FrameManager.html +2 -2
  42. data/docs/Puppeteer/FrameManager/NavigationError.html +1 -1
  43. data/docs/Puppeteer/IfPresent.html +1 -1
  44. data/docs/Puppeteer/JSHandle.html +1 -1
  45. data/docs/Puppeteer/Keyboard.html +1 -1
  46. data/docs/Puppeteer/Keyboard/KeyDefinition.html +1 -1
  47. data/docs/Puppeteer/Keyboard/KeyDescription.html +1 -1
  48. data/docs/Puppeteer/Launcher.html +1 -1
  49. data/docs/Puppeteer/Launcher/Base.html +1 -1
  50. data/docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html +1 -1
  51. data/docs/Puppeteer/Launcher/BrowserOptions.html +1 -1
  52. data/docs/Puppeteer/Launcher/Chrome.html +1 -1
  53. data/docs/Puppeteer/Launcher/Chrome/DefaultArgs.html +1 -1
  54. data/docs/Puppeteer/Launcher/ChromeArgOptions.html +1 -1
  55. data/docs/Puppeteer/Launcher/LaunchOptions.html +1 -1
  56. data/docs/Puppeteer/LifecycleWatcher.html +1 -1
  57. data/docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html +1 -1
  58. data/docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html +1 -1
  59. data/docs/Puppeteer/LifecycleWatcher/TerminatedError.html +1 -1
  60. data/docs/Puppeteer/Mouse.html +1 -1
  61. data/docs/Puppeteer/Mouse/Button.html +1 -1
  62. data/docs/Puppeteer/NetworkManager.html +2 -2
  63. data/docs/Puppeteer/NetworkManager/Credentials.html +1 -1
  64. data/docs/Puppeteer/Page.html +497 -294
  65. data/docs/Puppeteer/Page/FileChooserTimeoutError.html +5 -5
  66. data/docs/Puppeteer/Page/ScreenshotOptions.html +1 -1
  67. data/docs/Puppeteer/Page/ScriptTag.html +24 -24
  68. data/docs/Puppeteer/Page/StyleTag.html +19 -19
  69. data/docs/Puppeteer/Page/TargetCrashedError.html +1 -1
  70. data/docs/Puppeteer/RemoteObject.html +1 -1
  71. data/docs/Puppeteer/Target.html +2 -2
  72. data/docs/Puppeteer/Target/InitializeFailure.html +1 -1
  73. data/docs/Puppeteer/Target/TargetInfo.html +1 -1
  74. data/docs/Puppeteer/TimeoutError.html +1 -1
  75. data/docs/Puppeteer/TimeoutSettings.html +1 -1
  76. data/docs/Puppeteer/TouchScreen.html +1 -1
  77. data/docs/Puppeteer/Viewport.html +1 -1
  78. data/docs/Puppeteer/WaitTask.html +1 -1
  79. data/docs/Puppeteer/WaitTask/TerminatedError.html +1 -1
  80. data/docs/Puppeteer/WaitTask/TimeoutError.html +1 -1
  81. data/docs/Puppeteer/WebSocket.html +1 -1
  82. data/docs/Puppeteer/WebSocket/DriverImpl.html +1 -1
  83. data/docs/Puppeteer/WebSocket/TransportError.html +1 -1
  84. data/docs/Puppeteer/WebSocketTransport.html +9 -9
  85. data/docs/_index.html +1 -1
  86. data/docs/file.README.html +3 -1
  87. data/docs/index.html +3 -1
  88. data/docs/method_list.html +581 -557
  89. data/docs/top-level-namespace.html +1 -1
  90. data/lib/puppeteer.rb +36 -12
  91. data/lib/puppeteer/browser.rb +5 -0
  92. data/lib/puppeteer/concurrent_ruby_utils.rb +6 -2
  93. data/lib/puppeteer/event_callbackable.rb +11 -0
  94. data/lib/puppeteer/launcher.rb +6 -6
  95. data/lib/puppeteer/launcher/chrome.rb +1 -1
  96. data/lib/puppeteer/page.rb +39 -0
  97. data/lib/puppeteer/target.rb +1 -1
  98. data/lib/puppeteer/version.rb +1 -1
  99. data/lib/puppeteer/web_socket_transport.rb +8 -8
  100. data/puppeteer-ruby.png +0 -0
  101. metadata +3 -4
  102. data/Dockerfile +0 -6
  103. data/docker-compose.yml +0 -15
@@ -116,7 +116,7 @@
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Sat Jun 20 17:15:05 2020 by
119
+ Generated on Tue Jun 23 10:24:58 2020 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.9.24 (ruby-2.6.3).
122
122
  </div>
@@ -63,17 +63,33 @@ class Puppeteer
63
63
  end
64
64
  end
65
65
 
66
- # @param {string} projectRoot
67
- # @param {string} preferredRevision
68
- # @param {boolean} isPuppeteerCore
66
+ # @param project_root [String]
67
+ # @param prefereed_revision [String]
68
+ # @param is_puppeteer_core [String]
69
69
  def initialize(project_root:, preferred_revision:, is_puppeteer_core:)
70
70
  @project_root = project_root
71
71
  @preferred_revision = preferred_revision
72
72
  @is_puppeteer_core = is_puppeteer_core
73
73
  end
74
74
 
75
- # @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions & {product?: string, extraPrefsFirefox?: !object})=} options
76
- # @return {!Promise<!Puppeteer.Browser>}
75
+ # @param product [String]
76
+ # @param executable_path [String]
77
+ # @param ignore_default_args [Array<String>|nil]
78
+ # @param handle_SIGINT [Boolean]
79
+ # @param handle_SIGTERM [Boolean]
80
+ # @param handle_SIGHUP [Boolean]
81
+ # @param timeout [Integer]
82
+ # @param dumpio [Boolean]
83
+ # @param env [Hash]
84
+ # @param pipe [Boolean]
85
+ # @param args [Array<String>]
86
+ # @param user_data_dir [String]
87
+ # @param devtools [Boolean]
88
+ # @param headless [Boolean]
89
+ # @param ignore_https_errors [Boolean]
90
+ # @param default_viewport [Puppeteer::Viewport|nil]
91
+ # @param slow_mo [Integer]
92
+ # @return [Puppeteer::Browser]
77
93
  def launch(
78
94
  product: nil,
79
95
  executable_path: nil,
@@ -125,8 +141,13 @@ class Puppeteer
125
141
  end
126
142
  end
127
143
 
128
- # @param {!(Launcher.BrowserOptions & {browserWSEndpoint?: string, browserURL?: string, transport?: !Puppeteer.ConnectionTransport})} options
129
- # @return {!Promise<!Puppeteer.Browser>}
144
+ # @param browser_ws_endpoint [String]
145
+ # @param browser_url [String]
146
+ # @param transport [Puppeteer::WebSocketTransport]
147
+ # @param ignore_https_errors [Boolean]
148
+ # @param default_viewport [Puppeteer::Viewport|nil]
149
+ # @param slow_mo [Integer]
150
+ # @return [Puppeteer::Browser]
130
151
  def connect(
131
152
  browser_ws_endpoint: nil,
132
153
  browser_url: nil,
@@ -151,7 +172,7 @@ class Puppeteer
151
172
  end
152
173
  end
153
174
 
154
- # @return {string}
175
+ # @return [String]
155
176
  def executable_path
156
177
  launcher.executable_path
157
178
  end
@@ -165,12 +186,12 @@ class Puppeteer
165
186
  )
166
187
  end
167
188
 
168
- # @return {string}
189
+ # @return [String]
169
190
  def product
170
191
  launcher.product
171
192
  end
172
193
 
173
- # @return {Puppeteer::Devices}
194
+ # @return [Puppeteer::Devices]
174
195
  def devices
175
196
  Puppeteer::Devices
176
197
  end
@@ -180,8 +201,11 @@ class Puppeteer
180
201
  # # ???
181
202
  # end
182
203
 
183
- # @param {!Launcher.ChromeArgOptions=} options
184
- # @return {!Array<string>}
204
+ # @param args [Array<String>]
205
+ # @param user_data_dir [String]
206
+ # @param devtools [Boolean]
207
+ # @param headless [Boolean]
208
+ # @return [Array<String>]
185
209
  def default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil)
186
210
  options = {
187
211
  args: args,
@@ -207,6 +207,11 @@ class Puppeteer::Browser
207
207
  targets.first { |target| target.type == 'browser' }
208
208
  end
209
209
 
210
+ # used only in Target#opener
211
+ private def find_target_by_id(target_id)
212
+ @targets[target_id]
213
+ end
214
+
210
215
  # @param {function(!Target):boolean} predicate
211
216
  # @param {{timeout?: number}=} options
212
217
  # @return {!Promise<!Target>}
@@ -29,8 +29,12 @@ module Puppeteer::ConcurrentRubyUtils
29
29
  Concurrent::Promises.future(&block)
30
30
  end
31
31
 
32
- def resolvable_future
33
- Concurrent::Promises.resolvable_future
32
+ def resolvable_future(&block)
33
+ future = Concurrent::Promises.resolvable_future
34
+ if block
35
+ block.call(future)
36
+ end
37
+ future
34
38
  end
35
39
  end
36
40
 
@@ -39,6 +39,17 @@ module Puppeteer::EventCallbackable
39
39
  end
40
40
  end
41
41
 
42
+ def observe_first(event_name, &block)
43
+ listener_id = add_event_listener(event_name) do |*args, **kwargs|
44
+ if kwargs.empty?
45
+ block.call(*args)
46
+ else
47
+ block.call(*args, **kwargs)
48
+ end
49
+ remove_event_listener(listener_id)
50
+ end
51
+ end
52
+
42
53
  def on_event(event_name, &block)
43
54
  @event_callbackable_handlers ||= {}
44
55
  @event_callbackable_handlers[event_name] = block
@@ -4,13 +4,13 @@ require_relative './launcher/chrome'
4
4
  require_relative './launcher/chrome_arg_options'
5
5
  require_relative './launcher/launch_options'
6
6
 
7
- # https://github.com/puppeteer/puppeteer/blob/master/lib/Launcher.js
7
+ # https://github.com/puppeteer/puppeteer/blob/main/src/node/Launcher.ts
8
8
  module Puppeteer::Launcher
9
- # @param {string} projectRoot
10
- # @param {string} preferredRevision
11
- # @param {boolean} isPuppeteerCore
12
- # @param {string=} product
13
- # @return {!Puppeteer.ProductLauncher}
9
+ # @param project_root [String]
10
+ # @param prefereed_revision [String]
11
+ # @param is_puppeteer_core [String]
12
+ # @param product [String] 'chrome' or 'firefox' (not implemented yet)
13
+ # @return [Puppeteer::Launcher::Chrome]
14
14
  module_function def new(project_root:, preferred_revision:, is_puppeteer_core:, product:)
15
15
  if product == 'firefox'
16
16
  raise NotImplementedError.new('FirefoxLauncher is not implemented yet.')
@@ -1,6 +1,6 @@
1
1
  require 'tmpdir'
2
2
 
3
- # https://github.com/puppeteer/puppeteer/blob/master/lib/Launcher.js
3
+ # https://github.com/puppeteer/puppeteer/blob/main/src/node/Launcher.ts
4
4
  module Puppeteer::Launcher
5
5
  class Chrome < Base
6
6
  # @param {!(Launcher.LaunchOptions & Launcher.ChromeArgOptions & Launcher.BrowserOptions)=} options
@@ -124,6 +124,45 @@ class Puppeteer::Page
124
124
  )
125
125
  end
126
126
 
127
+ EVENT_MAPPINGS = {
128
+ close: 'Events.Page.Close',
129
+ # console: 'Events.Page.Console',
130
+ # dialog: 'Events.Page.Dialog',
131
+ domcontentloaded: 'Events.Page.DOMContentLoaded',
132
+ # error:
133
+ frameattached: 'Events.Page.FrameAttached',
134
+ framedetached: 'Events.Page.FrameDetached',
135
+ framenavigated: 'Events.Page.FrameNavigated',
136
+ load: 'Events.Page.Load',
137
+ # metrics: 'Events.Page.Metrics',
138
+ # pageerror: 'Events.Page.PageError',
139
+ popup: 'Events.Page.Popup',
140
+ request: 'Events.Page.Request',
141
+ requestfailed: 'Events.Page.RequestFailed',
142
+ requestfinished: 'Events.Page.RequestFinished',
143
+ response: 'Events.Page.Response',
144
+ # workercreated: 'Events.Page.WorkerCreated',
145
+ # workerdestroyed: 'Events.Page.WorkerDestroyed',
146
+ }
147
+
148
+ # @param event_name [Symbol]
149
+ def on(event_name, &block)
150
+ unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
151
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
152
+ end
153
+
154
+ add_event_listener(EVENT_MAPPINGS[event_name.to_sym], &block)
155
+ end
156
+
157
+ # @param event_name [Symbol]
158
+ def once(event_name, &block)
159
+ unless EVENT_MAPPINGS.has_key?(event_name.to_sym)
160
+ raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{EVENT_MAPPINGS.keys.join(", ")}")
161
+ end
162
+
163
+ observe_first(EVENT_MAPPINGS[event_name.to_sym], &block)
164
+ end
165
+
127
166
  def handle_file_chooser(event)
128
167
  return if @file_chooser_interceptors.empty?
129
168
 
@@ -135,7 +135,7 @@ class Puppeteer::Target
135
135
  def opener
136
136
  opener_id = @target_info.opener_id
137
137
  return nil if opener_id.nil?
138
- browser.targets[opener_id]
138
+ browser.send(:find_target_by_id, opener_id)
139
139
  end
140
140
 
141
141
  # @param {!Protocol.Target.TargetInfo} targetInfo
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -6,14 +6,14 @@ class Puppeteer::WebSocketTransport
6
6
  url: url,
7
7
  max_payload_size: 256 * 1024 * 1024, # 256MB
8
8
  )
9
- promise = resolvable_future
10
- ws.on_open do
11
- promise.fulfill(Puppeteer::WebSocketTransport.new(ws))
12
- end
13
- ws.on_error do |error_message|
14
- promise.reject(Puppeteer::WebSocket::TransportError.new(error_message))
15
- end
16
- promise.value!
9
+ (resolvable_future do |future|
10
+ ws.on_open do
11
+ future.fulfill(Puppeteer::WebSocketTransport.new(ws))
12
+ end
13
+ ws.on_error do |error_message|
14
+ future.reject(Puppeteer::WebSocket::TransportError.new(error_message))
15
+ end
16
+ end).value!
17
17
  end
18
18
 
19
19
  # @param {!WebSocket::Driver} web_socket
Binary file
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.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-20 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -177,13 +177,11 @@ files:
177
177
  - ".rspec"
178
178
  - ".rubocop.yml"
179
179
  - ".travis.yml"
180
- - Dockerfile
181
180
  - Gemfile
182
181
  - README.md
183
182
  - Rakefile
184
183
  - bin/console
185
184
  - bin/setup
186
- - docker-compose.yml
187
185
  - docs/Puppeteer.html
188
186
  - docs/Puppeteer/AsyncAwaitBehavior.html
189
187
  - docs/Puppeteer/Browser.html
@@ -333,6 +331,7 @@ files:
333
331
  - lib/puppeteer/web_socket.rb
334
332
  - lib/puppeteer/web_socket_transport.rb
335
333
  - puppeteer-ruby.gemspec
334
+ - puppeteer-ruby.png
336
335
  homepage: https://github.com/YusukeIwaki/puppeteer-ruby
337
336
  licenses: []
338
337
  metadata: {}
data/Dockerfile DELETED
@@ -1,6 +0,0 @@
1
- FROM ruby:2.6.5
2
-
3
- RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
4
- && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
5
- && apt-get update && apt-get install -y google-chrome-stable --no-install-recommends \
6
- && rm -rf /var/lib/apt/lists/*
@@ -1,15 +0,0 @@
1
- version: "3"
2
- services:
3
- dev:
4
- image: ruby-with-chrome:2.6
5
- build:
6
- context: .
7
- dockerfile: Dockerfile
8
- volumes:
9
- - .:/usr/src/app
10
- - bundler-cache:/usr/local/bundle
11
- working_dir: /usr/src/app
12
-
13
- volumes:
14
- bundler-cache:
15
- driver: local