puppeteer-ruby 0.0.10 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -12
- data/.github/workflows/docs.yml +45 -0
- data/.github/workflows/reviewdog.yml +15 -0
- data/README.md +54 -1
- data/lib/puppeteer.rb +37 -13
- data/lib/puppeteer/browser.rb +39 -26
- data/lib/puppeteer/cdp_session.rb +3 -19
- data/lib/puppeteer/concurrent_ruby_utils.rb +12 -2
- data/lib/puppeteer/connection.rb +16 -16
- data/lib/puppeteer/define_async_method.rb +23 -0
- data/lib/puppeteer/dom_world.rb +58 -71
- data/lib/puppeteer/element_handle.rb +15 -44
- data/lib/puppeteer/emulation_manager.rb +2 -6
- data/lib/puppeteer/event_callbackable.rb +11 -0
- data/lib/puppeteer/execution_context.rb +1 -6
- data/lib/puppeteer/frame.rb +38 -3
- data/lib/puppeteer/frame_manager.rb +7 -25
- data/lib/puppeteer/js_handle.rb +3 -12
- data/lib/puppeteer/keyboard.rb +6 -27
- data/lib/puppeteer/launcher.rb +6 -6
- data/lib/puppeteer/launcher/chrome.rb +10 -8
- data/lib/puppeteer/mouse.rb +8 -33
- data/lib/puppeteer/page.rb +132 -121
- data/lib/puppeteer/page/pdf_options.rb +166 -0
- data/lib/puppeteer/remote_object.rb +2 -5
- data/lib/puppeteer/target.rb +1 -1
- data/lib/puppeteer/touch_screen.rb +2 -7
- data/lib/puppeteer/version.rb +1 -1
- data/lib/puppeteer/wait_task.rb +2 -4
- data/lib/puppeteer/web_socket_transport.rb +8 -8
- data/puppeteer-ruby.gemspec +1 -1
- data/puppeteer-ruby.png +0 -0
- metadata +9 -102
- data/Dockerfile +0 -6
- data/docker-compose.yml +0 -15
- data/docs/Puppeteer.html +0 -2020
- data/docs/Puppeteer/AsyncAwaitBehavior.html +0 -105
- data/docs/Puppeteer/Browser.html +0 -2148
- data/docs/Puppeteer/BrowserContext.html +0 -809
- data/docs/Puppeteer/BrowserFetcher.html +0 -214
- data/docs/Puppeteer/BrowserRunner.html +0 -914
- data/docs/Puppeteer/BrowserRunner/BrowserProcess.html +0 -477
- data/docs/Puppeteer/CDPSession.html +0 -813
- data/docs/Puppeteer/CDPSession/Error.html +0 -124
- data/docs/Puppeteer/ConcurrentRubyUtils.html +0 -430
- data/docs/Puppeteer/Connection.html +0 -960
- data/docs/Puppeteer/Connection/MessageCallback.html +0 -434
- data/docs/Puppeteer/Connection/ProtocolError.html +0 -216
- data/docs/Puppeteer/Connection/RequestDebugPrinter.html +0 -217
- data/docs/Puppeteer/Connection/ResponseDebugPrinter.html +0 -244
- data/docs/Puppeteer/ConsoleMessage.html +0 -565
- data/docs/Puppeteer/ConsoleMessage/Location.html +0 -433
- data/docs/Puppeteer/DOMWorld.html +0 -2219
- data/docs/Puppeteer/DOMWorld/DetachedError.html +0 -124
- data/docs/Puppeteer/DOMWorld/DocumentEvaluationError.html +0 -124
- data/docs/Puppeteer/DebugPrint.html +0 -233
- data/docs/Puppeteer/Device.html +0 -470
- data/docs/Puppeteer/Devices.html +0 -139
- data/docs/Puppeteer/ElementHandle.html +0 -2542
- data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +0 -206
- data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +0 -206
- data/docs/Puppeteer/ElementHandle/Point.html +0 -492
- data/docs/Puppeteer/ElementHandle/ScrollIntoViewError.html +0 -124
- data/docs/Puppeteer/EmulationManager.html +0 -454
- data/docs/Puppeteer/EventCallbackable.html +0 -433
- data/docs/Puppeteer/EventCallbackable/EventListeners.html +0 -435
- data/docs/Puppeteer/ExecutionContext.html +0 -998
- data/docs/Puppeteer/ExecutionContext/EvaluationError.html +0 -124
- data/docs/Puppeteer/ExecutionContext/JavaScriptExpression.html +0 -357
- data/docs/Puppeteer/ExecutionContext/JavaScriptFunction.html +0 -389
- data/docs/Puppeteer/FileChooser.html +0 -455
- data/docs/Puppeteer/Frame.html +0 -3677
- data/docs/Puppeteer/FrameManager.html +0 -2410
- data/docs/Puppeteer/FrameManager/NavigationError.html +0 -124
- data/docs/Puppeteer/IfPresent.html +0 -222
- data/docs/Puppeteer/JSHandle.html +0 -1352
- data/docs/Puppeteer/Keyboard.html +0 -1557
- data/docs/Puppeteer/Keyboard/KeyDefinition.html +0 -831
- data/docs/Puppeteer/Keyboard/KeyDescription.html +0 -603
- data/docs/Puppeteer/Launcher.html +0 -237
- data/docs/Puppeteer/Launcher/Base.html +0 -385
- data/docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html +0 -124
- data/docs/Puppeteer/Launcher/BrowserOptions.html +0 -441
- data/docs/Puppeteer/Launcher/Chrome.html +0 -669
- data/docs/Puppeteer/Launcher/Chrome/DefaultArgs.html +0 -382
- data/docs/Puppeteer/Launcher/ChromeArgOptions.html +0 -531
- data/docs/Puppeteer/Launcher/LaunchOptions.html +0 -893
- data/docs/Puppeteer/LifecycleWatcher.html +0 -834
- data/docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html +0 -363
- data/docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html +0 -206
- data/docs/Puppeteer/LifecycleWatcher/TerminatedError.html +0 -124
- data/docs/Puppeteer/Mouse.html +0 -1105
- data/docs/Puppeteer/Mouse/Button.html +0 -136
- data/docs/Puppeteer/NetworkManager.html +0 -901
- data/docs/Puppeteer/NetworkManager/Credentials.html +0 -385
- data/docs/Puppeteer/Page.html +0 -5970
- data/docs/Puppeteer/Page/FileChooserTimeoutError.html +0 -206
- data/docs/Puppeteer/Page/ScreenshotOptions.html +0 -845
- data/docs/Puppeteer/Page/ScriptTag.html +0 -555
- data/docs/Puppeteer/Page/StyleTag.html +0 -448
- data/docs/Puppeteer/Page/TargetCrashedError.html +0 -124
- data/docs/Puppeteer/RemoteObject.html +0 -1087
- data/docs/Puppeteer/Target.html +0 -1336
- data/docs/Puppeteer/Target/InitializeFailure.html +0 -124
- data/docs/Puppeteer/Target/TargetInfo.html +0 -729
- data/docs/Puppeteer/TimeoutError.html +0 -135
- data/docs/Puppeteer/TimeoutSettings.html +0 -496
- data/docs/Puppeteer/TouchScreen.html +0 -464
- data/docs/Puppeteer/Viewport.html +0 -837
- data/docs/Puppeteer/WaitTask.html +0 -637
- data/docs/Puppeteer/WaitTask/TerminatedError.html +0 -124
- data/docs/Puppeteer/WaitTask/TimeoutError.html +0 -206
- data/docs/Puppeteer/WebSocket.html +0 -673
- data/docs/Puppeteer/WebSocket/DriverImpl.html +0 -412
- data/docs/Puppeteer/WebSocketTransport.html +0 -600
- data/docs/Puppeteer/WebSocktTransportError.html +0 -124
- data/docs/_index.html +0 -823
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.README.html +0 -123
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -123
- data/docs/js/app.js +0 -314
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -4075
- data/docs/top-level-namespace.html +0 -126
- data/lib/puppeteer/async_await_behavior.rb +0 -38
@@ -1,6 +1,6 @@
|
|
1
1
|
class Puppeteer::ExecutionContext
|
2
2
|
include Puppeteer::IfPresent
|
3
|
-
using Puppeteer::
|
3
|
+
using Puppeteer::DefineAsyncMethod
|
4
4
|
|
5
5
|
EVALUATION_SCRIPT_URL = '__puppeteer_evaluation_script__'
|
6
6
|
SOURCE_URL_REGEX = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m
|
@@ -16,11 +16,6 @@ class Puppeteer::ExecutionContext
|
|
16
16
|
|
17
17
|
attr_reader :client, :world
|
18
18
|
|
19
|
-
# only used in DomWorld#delete_context
|
20
|
-
def _context_id
|
21
|
-
@context_id
|
22
|
-
end
|
23
|
-
|
24
19
|
# @return [Puppeteer::Frame]
|
25
20
|
def frame
|
26
21
|
if_present(@world) do |world|
|
data/lib/puppeteer/frame.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Puppeteer::Frame
|
2
|
+
using Puppeteer::DefineAsyncMethod
|
3
|
+
|
2
4
|
# @param {!FrameManager} frameManager
|
3
5
|
# @param {!Puppeteer.CDPSession} client
|
4
6
|
# @param {?Frame} parentFrame
|
@@ -33,10 +35,12 @@ class Puppeteer::Frame
|
|
33
35
|
|
34
36
|
# @param timeout [number|nil]
|
35
37
|
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
36
|
-
def wait_for_navigation(timeout: nil, wait_until: nil)
|
38
|
+
private def wait_for_navigation(timeout: nil, wait_until: nil)
|
37
39
|
@frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
|
38
40
|
end
|
39
41
|
|
42
|
+
define_async_method :async_wait_for_navigation
|
43
|
+
|
40
44
|
def execution_context
|
41
45
|
@main_world.execution_context
|
42
46
|
end
|
@@ -47,12 +51,16 @@ class Puppeteer::Frame
|
|
47
51
|
@main_world.evaluate_handle(page_function, *args)
|
48
52
|
end
|
49
53
|
|
54
|
+
define_async_method :async_evaluate_handle
|
55
|
+
|
50
56
|
# @param {Function|string} pageFunction
|
51
57
|
# @param {!Array<*>} args
|
52
58
|
def evaluate(page_function, *args)
|
53
59
|
@main_world.evaluate(page_function, *args)
|
54
60
|
end
|
55
61
|
|
62
|
+
define_async_method :async_evaluate
|
63
|
+
|
56
64
|
# `$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
57
65
|
# @param {string} selector
|
58
66
|
# @return {!Promise<?Puppeteer.ElementHandle>}
|
@@ -60,6 +68,7 @@ class Puppeteer::Frame
|
|
60
68
|
@main_world.S(selector)
|
61
69
|
end
|
62
70
|
|
71
|
+
define_async_method :async_S
|
63
72
|
|
64
73
|
# `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
65
74
|
# @param {string} expression
|
@@ -68,6 +77,7 @@ class Puppeteer::Frame
|
|
68
77
|
@main_world.Sx(expression)
|
69
78
|
end
|
70
79
|
|
80
|
+
define_async_method :async_Sx
|
71
81
|
|
72
82
|
# `$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
73
83
|
# @param {string} selector
|
@@ -78,6 +88,8 @@ class Puppeteer::Frame
|
|
78
88
|
@main_world.Seval(selector, page_function, *args)
|
79
89
|
end
|
80
90
|
|
91
|
+
define_async_method :async_Seval
|
92
|
+
|
81
93
|
# `$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
82
94
|
# @param {string} selector
|
83
95
|
# @param {Function|string} pageFunction
|
@@ -87,6 +99,8 @@ class Puppeteer::Frame
|
|
87
99
|
@main_world.SSeval(selector, page_function, *args)
|
88
100
|
end
|
89
101
|
|
102
|
+
define_async_method :async_SSeval
|
103
|
+
|
90
104
|
# `$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
91
105
|
# @param {string} selector
|
92
106
|
# @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
|
@@ -94,12 +108,16 @@ class Puppeteer::Frame
|
|
94
108
|
@main_world.SS(selector)
|
95
109
|
end
|
96
110
|
|
111
|
+
define_async_method :async_SS
|
112
|
+
|
113
|
+
# @return [String]
|
97
114
|
def content
|
98
115
|
@secondary_world.content
|
99
116
|
end
|
100
117
|
|
101
|
-
# @param
|
102
|
-
# @param
|
118
|
+
# @param html [String]
|
119
|
+
# @param timeout [Integer]
|
120
|
+
# @param wait_until [String|Array<String>]
|
103
121
|
def set_content(html, timeout: nil, wait_until: nil)
|
104
122
|
@secondary_world.set_content(html, timeout: timeout, wait_until: wait_until)
|
105
123
|
end
|
@@ -151,11 +169,15 @@ class Puppeteer::Frame
|
|
151
169
|
@secondary_world.click(selector, delay: delay, button: button, click_count: click_count)
|
152
170
|
end
|
153
171
|
|
172
|
+
define_async_method :async_click
|
173
|
+
|
154
174
|
# @param {string} selector
|
155
175
|
def focus(selector)
|
156
176
|
@secondary_world.focus(selector)
|
157
177
|
end
|
158
178
|
|
179
|
+
define_async_method :async_focus
|
180
|
+
|
159
181
|
# @param {string} selector
|
160
182
|
def hover(selector)
|
161
183
|
@secondary_world.hover(selector)
|
@@ -168,11 +190,15 @@ class Puppeteer::Frame
|
|
168
190
|
@secondary_world.select(selector, *values)
|
169
191
|
end
|
170
192
|
|
193
|
+
define_async_method :async_select
|
194
|
+
|
171
195
|
# @param {string} selector
|
172
196
|
def tap(selector)
|
173
197
|
@secondary_world.tap(selector)
|
174
198
|
end
|
175
199
|
|
200
|
+
define_async_method :async_tap
|
201
|
+
|
176
202
|
# @param selector [String]
|
177
203
|
# @param text [String]
|
178
204
|
# @param delay [Number]
|
@@ -180,6 +206,8 @@ class Puppeteer::Frame
|
|
180
206
|
@main_world.type_text(selector, text, delay: delay)
|
181
207
|
end
|
182
208
|
|
209
|
+
define_async_method :async_type_text
|
210
|
+
|
183
211
|
# /**
|
184
212
|
# * @param {(string|number|Function)} selectorOrFunctionOrTimeout
|
185
213
|
# * @param {!Object=} options
|
@@ -217,6 +245,8 @@ class Puppeteer::Frame
|
|
217
245
|
result
|
218
246
|
end
|
219
247
|
|
248
|
+
define_async_method :async_wait_for_selector
|
249
|
+
|
220
250
|
# @param xpath [String]
|
221
251
|
# @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
|
222
252
|
# @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
|
@@ -232,6 +262,8 @@ class Puppeteer::Frame
|
|
232
262
|
result
|
233
263
|
end
|
234
264
|
|
265
|
+
define_async_method :async_wait_for_xpath
|
266
|
+
|
235
267
|
# @param {Function|string} pageFunction
|
236
268
|
# @param {!{polling?: string|number, timeout?: number}=} options
|
237
269
|
# @param {!Array<*>} args
|
@@ -240,6 +272,9 @@ class Puppeteer::Frame
|
|
240
272
|
@main_world.wait_for_function(page_function, options, *args)
|
241
273
|
end
|
242
274
|
|
275
|
+
define_async_method :async_wait_for_function
|
276
|
+
|
277
|
+
# @return [String]
|
243
278
|
def title
|
244
279
|
@secondary_world.title
|
245
280
|
end
|
@@ -4,7 +4,7 @@ class Puppeteer::FrameManager
|
|
4
4
|
include Puppeteer::DebugPrint
|
5
5
|
include Puppeteer::IfPresent
|
6
6
|
include Puppeteer::EventCallbackable
|
7
|
-
using Puppeteer::
|
7
|
+
using Puppeteer::DefineAsyncMethod
|
8
8
|
|
9
9
|
UTILITY_WORLD_NAME = '__puppeteer_utility_world__'
|
10
10
|
|
@@ -23,7 +23,6 @@ class Puppeteer::FrameManager
|
|
23
23
|
|
24
24
|
# @type {!Map<number, !ExecutionContext>}
|
25
25
|
@context_id_to_context = {}
|
26
|
-
@context_id_created = {}
|
27
26
|
|
28
27
|
# @type {!Set<string>}
|
29
28
|
@isolated_worlds = Set.new
|
@@ -74,9 +73,7 @@ class Puppeteer::FrameManager
|
|
74
73
|
@network_manager.init
|
75
74
|
end
|
76
75
|
|
77
|
-
|
78
|
-
init
|
79
|
-
end
|
76
|
+
define_async_method :async_init
|
80
77
|
|
81
78
|
attr_reader :network_manager
|
82
79
|
|
@@ -281,7 +278,7 @@ class Puppeteer::FrameManager
|
|
281
278
|
# @param url [String]
|
282
279
|
def handle_frame_navigated_within_document(frame_id, url)
|
283
280
|
frame = @frames[frame_id]
|
284
|
-
return
|
281
|
+
return unless frame
|
285
282
|
frame.navigated_within_document(url)
|
286
283
|
emit_event 'Events.FrameManager.FrameNavigatedWithinDocument', frame
|
287
284
|
emit_event 'Events.FrameManager.FrameNavigated', frame
|
@@ -320,44 +317,29 @@ class Puppeteer::FrameManager
|
|
320
317
|
world.context = context
|
321
318
|
end
|
322
319
|
@context_id_to_context[context_payload['id']] = context
|
323
|
-
@context_id_created[context_payload['id']] = Time.now
|
324
320
|
end
|
325
321
|
|
326
322
|
# @param {number} executionContextId
|
327
323
|
def handle_execution_context_destroyed(execution_context_id)
|
328
324
|
context = @context_id_to_context[execution_context_id]
|
329
|
-
return
|
325
|
+
return unless context
|
330
326
|
@context_id_to_context.delete(execution_context_id)
|
331
|
-
@context_id_created.delete(execution_context_id)
|
332
327
|
if context.world
|
333
328
|
context.world.delete_context(execution_context_id)
|
334
329
|
end
|
335
330
|
end
|
336
331
|
|
337
332
|
def handle_execution_contexts_cleared
|
338
|
-
|
339
|
-
# D, [2020-04-06T01:47:03.101227 #13823] DEBUG -- : RECV << {"method"=>"Runtime.executionContextCreated", "params"=>{"context"=>{"id"=>5, "origin"=>"https://github.com", "name"=>"", "auxData"=>{"isDefault"=>true, "type"=>"default", "frameId"=>"71C347B70848B89DDDEFAA8AB5B0BC92"}}}, "sessionId"=>"53F088EED260C28001D26A019F95D9E3"}
|
340
|
-
# D, [2020-04-06T01:47:03.101439 #13823] DEBUG -- : RECV << {"method"=>"Page.frameNavigated", "params"=>{"frame"=>{"id"=>"71C347B70848B89DDDEFAA8AB5B0BC92", "loaderId"=>"80338225D035AC96BAE8F6D4E81C7D51", "url"=>"https://github.com/search?q=puppeteer", "securityOrigin"=>"https://github.com", "mimeType"=>"text/html"}}, "sessionId"=>"53F088EED260C28001D26A019F95D9E3"}
|
341
|
-
# D, [2020-04-06T01:47:03.101325 #13823] DEBUG -- : RECV << {"method"=>"Target.targetInfoChanged", "params"=>{"targetInfo"=>{"targetId"=>"71C347B70848B89DDDEFAA8AB5B0BC92", "type"=>"page", "title"=>"https://github.com/search?q=puppeteer", "url"=>"https://github.com/search?q=puppeteer", "attached"=>true, "browserContextId"=>"AF37BC660284CE1552B4ECB147BE9305"}}}
|
342
|
-
# D, [2020-04-06T01:47:03.101269 #13823] DEBUG -- : RECV << {"method"=>"Runtime.executionContextsCleared", "params"=>{}, "sessionId"=>"53F088EED260C28001D26A019F95D9E3"}
|
343
|
-
# it unexpectedly clears the created execution context.
|
344
|
-
# To avoid the problem, just skip recent created ids.
|
345
|
-
now = Time.now
|
346
|
-
context_ids_to_skip = @context_id_created.select { |k, v| now - v < 1 }.keys
|
347
|
-
@context_id_to_context.reject { |k, v| context_ids_to_skip.include?(k) }.each do |execution_context_id, context|
|
333
|
+
@context_id_to_context.each do |execution_context_id, context|
|
348
334
|
if context.world
|
349
335
|
context.world.delete_context(execution_context_id)
|
350
336
|
end
|
351
337
|
end
|
352
|
-
@context_id_to_context.
|
338
|
+
@context_id_to_context.clear
|
353
339
|
end
|
354
340
|
|
355
341
|
def execution_context_by_id(context_id)
|
356
|
-
context =
|
357
|
-
if !context
|
358
|
-
raise "INTERNAL ERROR: missing context with id = #{context_id}"
|
359
|
-
end
|
360
|
-
context
|
342
|
+
@context_id_to_context[context_id] or raise "INTERNAL ERROR: missing context with id = #{context_id}"
|
361
343
|
end
|
362
344
|
|
363
345
|
# @param {!Frame} frame
|
data/lib/puppeteer/js_handle.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Puppeteer::JSHandle
|
2
|
-
using Puppeteer::
|
2
|
+
using Puppeteer::DefineAsyncMethod
|
3
3
|
|
4
4
|
# @param context [Puppeteer::ExecutionContext]
|
5
5
|
# @param remote_object [Puppeteer::RemoteObject]
|
@@ -46,11 +46,7 @@ class Puppeteer::JSHandle
|
|
46
46
|
execution_context.evaluate(page_function, self, *args)
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
# @return [Future<Object>]
|
51
|
-
async def async_evaluate(page_function, *args)
|
52
|
-
evaluate(page_function, *args)
|
53
|
-
end
|
49
|
+
define_async_method :async_evaluate
|
54
50
|
|
55
51
|
# @param page_function [String]
|
56
52
|
# @param args {Array<*>}
|
@@ -59,12 +55,7 @@ class Puppeteer::JSHandle
|
|
59
55
|
execution_context.evaluate_handle(page_function, self, *args)
|
60
56
|
end
|
61
57
|
|
62
|
-
|
63
|
-
# @param args {Array<*>}
|
64
|
-
# @return [Future<Puppeteer::JSHandle>]
|
65
|
-
async def async_evaluate_handle(page_function, *args)
|
66
|
-
evaluate_handle(page_function, *args)
|
67
|
-
end
|
58
|
+
define_async_method :async_evaluate_handle
|
68
59
|
|
69
60
|
# /**
|
70
61
|
# * @param {string} propertyName
|
data/lib/puppeteer/keyboard.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative './keyboard/key_description'
|
|
2
2
|
require_relative './keyboard/us_keyboard_layout'
|
3
3
|
|
4
4
|
class Puppeteer::Keyboard
|
5
|
-
using Puppeteer::
|
5
|
+
using Puppeteer::DefineAsyncMethod
|
6
6
|
|
7
7
|
# @param {!Puppeteer.CDPSession} client
|
8
8
|
def initialize(client)
|
@@ -38,12 +38,7 @@ class Puppeteer::Keyboard
|
|
38
38
|
@client.send_message('Input.dispatchKeyEvent', params)
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
# @param text [String]
|
43
|
-
# @return [Future]
|
44
|
-
async def async_down(key, text: nil)
|
45
|
-
down(key, text)
|
46
|
-
end
|
41
|
+
define_async_method :async_down
|
47
42
|
|
48
43
|
# @param {string} key
|
49
44
|
# @return {number}
|
@@ -127,22 +122,14 @@ class Puppeteer::Keyboard
|
|
127
122
|
)
|
128
123
|
end
|
129
124
|
|
130
|
-
|
131
|
-
# @return [Future]
|
132
|
-
async def async_up(key)
|
133
|
-
up(key)
|
134
|
-
end
|
125
|
+
define_async_method :async_up
|
135
126
|
|
136
127
|
# @param char [string]
|
137
128
|
def send_character(char)
|
138
129
|
@client.send_message('Input.insertText', text: char)
|
139
130
|
end
|
140
131
|
|
141
|
-
|
142
|
-
# @return [Future]
|
143
|
-
async def async_send_character(char)
|
144
|
-
send_character(char)
|
145
|
-
end
|
132
|
+
define_async_method :async_send_character
|
146
133
|
|
147
134
|
# @param text [String]
|
148
135
|
# @return [Future]
|
@@ -159,11 +146,7 @@ class Puppeteer::Keyboard
|
|
159
146
|
end
|
160
147
|
end
|
161
148
|
|
162
|
-
|
163
|
-
# @return [Future]
|
164
|
-
async def async_type_text(text, delay: nil)
|
165
|
-
type_text(text, delay)
|
166
|
-
end
|
149
|
+
define_async_method :async_type_text
|
167
150
|
|
168
151
|
# @param key [String]
|
169
152
|
# @return [Future]
|
@@ -175,9 +158,5 @@ class Puppeteer::Keyboard
|
|
175
158
|
up(key)
|
176
159
|
end
|
177
160
|
|
178
|
-
|
179
|
-
# @return [Future]
|
180
|
-
async def async_press(key, delay: nil)
|
181
|
-
press(key, delay: delay)
|
182
|
-
end
|
161
|
+
define_async_method :async_press
|
183
162
|
end
|
data/lib/puppeteer/launcher.rb
CHANGED
@@ -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/
|
7
|
+
# https://github.com/puppeteer/puppeteer/blob/main/src/node/Launcher.ts
|
8
8
|
module Puppeteer::Launcher
|
9
|
-
# @param
|
10
|
-
# @param
|
11
|
-
# @param
|
12
|
-
# @param
|
13
|
-
# @return
|
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/
|
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
|
@@ -139,6 +139,7 @@ module Puppeteer::Launcher
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
# @return [DefaultArgs]
|
142
143
|
def default_args(options = nil)
|
143
144
|
if options.nil?
|
144
145
|
@default_args ||= DefaultArgs.new(@chrome_arg_options)
|
@@ -147,8 +148,7 @@ module Puppeteer::Launcher
|
|
147
148
|
end
|
148
149
|
end
|
149
150
|
|
150
|
-
# @
|
151
|
-
# @return {!Promise<!Browser>}
|
151
|
+
# @return [Puppeteer::Browser]
|
152
152
|
def connect(options = {})
|
153
153
|
@browser_options = BrowserOptions.new(options)
|
154
154
|
browser_ws_endpoint = options[:browser_ws_endpoint]
|
@@ -187,11 +187,13 @@ module Puppeteer::Launcher
|
|
187
187
|
|
188
188
|
# @return [Puppeteer::Connection]
|
189
189
|
private def connect_with_browser_url(browser_url)
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
190
|
+
require 'net/http'
|
191
|
+
uri = URI(browser_url)
|
192
|
+
uri.path = '/json/version'
|
193
|
+
response_body = Net::HTTP.get(uri)
|
194
|
+
json = JSON.parse(response_body)
|
195
|
+
connection_url = json['webSocketDebuggerUrl']
|
196
|
+
connect_with_browser_ws_endpoint(connection_url)
|
195
197
|
end
|
196
198
|
|
197
199
|
# @return [Puppeteer::Connection]
|
data/lib/puppeteer/mouse.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Puppeteer::Mouse
|
2
|
-
using Puppeteer::
|
2
|
+
using Puppeteer::DefineAsyncMethod
|
3
3
|
|
4
4
|
module Button
|
5
5
|
NONE = 'none'
|
@@ -44,13 +44,7 @@ class Puppeteer::Mouse
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
# @param y [number]
|
49
|
-
# @param steps [number]
|
50
|
-
# @return [Future]
|
51
|
-
async def async_move(x, y, steps: nil)
|
52
|
-
move(x, y, steps: steps)
|
53
|
-
end
|
47
|
+
define_async_method :async_move
|
54
48
|
|
55
49
|
# @param x [number]
|
56
50
|
# @param y [number]
|
@@ -61,27 +55,16 @@ class Puppeteer::Mouse
|
|
61
55
|
# D, [2020-04-15T17:09:47.898422 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mouseReleased","button":"left","x":0,"y":0,"modifiers":0,"clickCount":1},"id":24}
|
62
56
|
# D, [2020-04-15T17:09:47.899711 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mousePressed","button":"left","x":0,"y":0,"modifiers":0,"clickCount":1},"id":25}
|
63
57
|
# D, [2020-04-15T17:09:47.900237 #88683] DEBUG -- : SEND >> {"sessionId":"0B09EA5E18DEE403E525B3E7FCD7E225","method":"Input.dispatchMouseEvent","params":{"type":"mouseMoved","button":"left","x":187,"y":283,"modifiers":0},"id":26}
|
64
|
-
# So we execute
|
58
|
+
# So we execute them sequential
|
65
59
|
move(x, y)
|
60
|
+
down(button: button, click_count: click_count)
|
66
61
|
if delay
|
67
|
-
down(button: button, click_count: click_count)
|
68
62
|
sleep(delay / 1000.0)
|
69
|
-
up(button: button, click_count: click_count)
|
70
|
-
else
|
71
|
-
await_all(
|
72
|
-
async_down(button: button, click_count: click_count),
|
73
|
-
async_up(button: button, click_count: click_count),
|
74
|
-
)
|
75
63
|
end
|
64
|
+
up(button: button, click_count: click_count)
|
76
65
|
end
|
77
66
|
|
78
|
-
|
79
|
-
# @param y [number]
|
80
|
-
# @param {!{delay?: number, button?: "left"|"right"|"middle", clickCount?: number}=} options
|
81
|
-
# @return [Future]
|
82
|
-
async def async_click(x, y, delay: nil, button: nil, click_count: nil)
|
83
|
-
click(x, y, delay: delay, button: button, click_count: click_count)
|
84
|
-
end
|
67
|
+
define_async_method :async_click
|
85
68
|
|
86
69
|
# @param {!{button?: "left"|"right"|"middle", clickCount?: number}=} options
|
87
70
|
def down(button: nil, click_count: nil)
|
@@ -96,11 +79,7 @@ class Puppeteer::Mouse
|
|
96
79
|
)
|
97
80
|
end
|
98
81
|
|
99
|
-
|
100
|
-
# @return [Future]
|
101
|
-
async def async_down(button: nil, click_count: nil)
|
102
|
-
down(button: button, click_count: click_count)
|
103
|
-
end
|
82
|
+
define_async_method :async_down
|
104
83
|
|
105
84
|
# @param {!{button?: "left"|"right"|"middle", clickCount?: number}=} options
|
106
85
|
def up(button: nil, click_count: nil)
|
@@ -115,9 +94,5 @@ class Puppeteer::Mouse
|
|
115
94
|
)
|
116
95
|
end
|
117
96
|
|
118
|
-
|
119
|
-
# @return [Future]
|
120
|
-
async def async_up(button: nil, click_count: nil)
|
121
|
-
up(button: button, click_count: click_count)
|
122
|
-
end
|
97
|
+
define_async_method :async_up
|
123
98
|
end
|