puppeteer-ruby 0.0.12 → 0.0.17
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 +2 -14
- data/.github/workflows/docs.yml +45 -0
- data/.github/workflows/reviewdog.yml +15 -0
- data/README.md +52 -1
- data/lib/puppeteer.rb +10 -2
- data/lib/puppeteer/browser.rb +53 -34
- data/lib/puppeteer/browser_context.rb +35 -5
- data/lib/puppeteer/cdp_session.rb +3 -19
- data/lib/puppeteer/concurrent_ruby_utils.rb +6 -0
- data/lib/puppeteer/connection.rb +9 -16
- data/lib/puppeteer/debug_print.rb +1 -1
- data/lib/puppeteer/define_async_method.rb +23 -0
- data/lib/puppeteer/dom_world.rb +67 -78
- data/lib/puppeteer/element_handle.rb +19 -47
- data/lib/puppeteer/emulation_manager.rb +2 -6
- data/lib/puppeteer/env.rb +18 -0
- data/lib/puppeteer/execution_context.rb +1 -6
- data/lib/puppeteer/frame.rb +34 -39
- data/lib/puppeteer/frame_manager.rb +7 -25
- data/lib/puppeteer/js_handle.rb +3 -12
- data/lib/puppeteer/keyboard.rb +9 -29
- data/lib/puppeteer/launcher/chrome.rb +9 -7
- data/lib/puppeteer/mouse.rb +20 -24
- data/lib/puppeteer/network_manager.rb +163 -5
- data/lib/puppeteer/page.rb +213 -179
- data/lib/puppeteer/page/pdf_options.rb +166 -0
- data/lib/puppeteer/remote_object.rb +2 -5
- data/lib/puppeteer/request.rb +330 -0
- data/lib/puppeteer/response.rb +113 -0
- 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.rb +7 -0
- data/puppeteer-ruby.gemspec +2 -1
- metadata +25 -103
- data/docs/Puppeteer.html +0 -2338
- data/docs/Puppeteer/AsyncAwaitBehavior.html +0 -105
- data/docs/Puppeteer/Browser.html +0 -2258
- 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 -438
- data/docs/Puppeteer/Connection.html +0 -964
- 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/BoundingBox.html +0 -507
- data/docs/Puppeteer/ElementHandle/BoxModel.html +0 -404
- 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 -499
- 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 -3813
- 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 -1095
- 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 -6173
- 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/WebSocket/TransportError.html +0 -124
- data/docs/Puppeteer/WebSocketTransport.html +0 -600
- data/docs/Puppeteer/WebSocktTransportError.html +0 -124
- data/docs/_index.html +0 -816
- 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 -125
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -125
- 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 -4115
- data/docs/top-level-namespace.html +0 -126
- data/lib/puppeteer/async_await_behavior.rb +0 -38
@@ -1,7 +1,7 @@
|
|
1
1
|
class Puppeteer::CDPSession
|
2
2
|
include Puppeteer::DebugPrint
|
3
3
|
include Puppeteer::EventCallbackable
|
4
|
-
using Puppeteer::
|
4
|
+
using Puppeteer::DefineAsyncMethod
|
5
5
|
|
6
6
|
class Error < StandardError; end
|
7
7
|
|
@@ -13,7 +13,6 @@ class Puppeteer::CDPSession
|
|
13
13
|
@connection = connection
|
14
14
|
@target_type = target_type
|
15
15
|
@session_id = session_id
|
16
|
-
@pending_messages = {}
|
17
16
|
end
|
18
17
|
|
19
18
|
attr_reader :connection
|
@@ -35,12 +34,7 @@ class Puppeteer::CDPSession
|
|
35
34
|
id = @connection.raw_send(message: { sessionId: @session_id, method: method, params: params })
|
36
35
|
promise = resolvable_future
|
37
36
|
callback = Puppeteer::Connection::MessageCallback.new(method: method, promise: promise)
|
38
|
-
|
39
|
-
debug_puts "Pending message (id: #{id}) is handled"
|
40
|
-
callback_with_message(callback, pending_message)
|
41
|
-
else
|
42
|
-
@callbacks[id] = callback
|
43
|
-
end
|
37
|
+
@callbacks[id] = callback
|
44
38
|
promise
|
45
39
|
end
|
46
40
|
|
@@ -50,17 +44,7 @@ class Puppeteer::CDPSession
|
|
50
44
|
if callback = @callbacks.delete(message['id'])
|
51
45
|
callback_with_message(callback, message)
|
52
46
|
else
|
53
|
-
|
54
|
-
|
55
|
-
# RECV is often notified before SEND.
|
56
|
-
# Wait about 10 frames before throwing an error.
|
57
|
-
message_id = message['id']
|
58
|
-
@pending_messages[message_id] = message
|
59
|
-
Concurrent::Promises.schedule(0.16, message_id) do |id|
|
60
|
-
if @pending_messages.delete(id)
|
61
|
-
raise Error.new("unknown id: #{id}")
|
62
|
-
end
|
63
|
-
end
|
47
|
+
raise Error.new("unknown id: #{id}")
|
64
48
|
end
|
65
49
|
else
|
66
50
|
emit_event message['method'], message['params']
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# utility methods for Concurrent::Promises.
|
2
2
|
module Puppeteer::ConcurrentRubyUtils
|
3
|
+
# wait for all promises.
|
4
|
+
# REMARK: This method doesn't assure the order of calling.
|
5
|
+
# for example, await_all(async1, async2) calls calls2 -> calls1 often.
|
3
6
|
def await_all(*args)
|
4
7
|
if args.length == 1 && args[0].is_a?(Enumerable)
|
5
8
|
Concurrent::Promises.zip(*(args[0])).value!
|
@@ -8,6 +11,9 @@ module Puppeteer::ConcurrentRubyUtils
|
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
14
|
+
# wait for first promises.
|
15
|
+
# REMARK: This method doesn't assure the order of calling.
|
16
|
+
# for example, await_all(async1, async2) calls calls2 -> calls1 often.
|
11
17
|
def await_any(*args)
|
12
18
|
if args.length == 1 && args[0].is_a?(Enumerable)
|
13
19
|
Concurrent::Promises.any(*(args[0])).value!
|
data/lib/puppeteer/connection.rb
CHANGED
@@ -3,7 +3,7 @@ require 'json'
|
|
3
3
|
class Puppeteer::Connection
|
4
4
|
include Puppeteer::DebugPrint
|
5
5
|
include Puppeteer::EventCallbackable
|
6
|
-
using Puppeteer::
|
6
|
+
using Puppeteer::DefineAsyncMethod
|
7
7
|
|
8
8
|
class ProtocolError < StandardError
|
9
9
|
def initialize(method:, error_message:, error_data: nil)
|
@@ -49,13 +49,18 @@ class Puppeteer::Connection
|
|
49
49
|
async_handle_message(message)
|
50
50
|
end
|
51
51
|
@transport.on_close do |reason, code|
|
52
|
-
handle_close
|
52
|
+
handle_close
|
53
53
|
end
|
54
54
|
|
55
55
|
@sessions = {}
|
56
56
|
@closed = false
|
57
57
|
end
|
58
58
|
|
59
|
+
# used only in Browser#connected?
|
60
|
+
def closed?
|
61
|
+
@closed
|
62
|
+
end
|
63
|
+
|
59
64
|
private def sleep_before_handling_message(message)
|
60
65
|
# Puppeteer doesn't handle any Network monitoring responses.
|
61
66
|
# So we don't have to sleep.
|
@@ -210,9 +215,7 @@ class Puppeteer::Connection
|
|
210
215
|
end
|
211
216
|
end
|
212
217
|
|
213
|
-
private
|
214
|
-
handle_message(message)
|
215
|
-
end
|
218
|
+
private define_async_method :async_handle_message
|
216
219
|
|
217
220
|
private def handle_close
|
218
221
|
return if @closed
|
@@ -251,16 +254,6 @@ class Puppeteer::Connection
|
|
251
254
|
def create_session(target_info)
|
252
255
|
result = send_message('Target.attachToTarget', targetId: target_info.target_id, flatten: true)
|
253
256
|
session_id = result['sessionId']
|
254
|
-
|
255
|
-
# Target.attachedToTarget is often notified after the result of Target.attachToTarget.
|
256
|
-
# D, [2020-04-04T23:04:30.736311 #91875] DEBUG -- : RECV << {"id"=>2, "result"=>{"sessionId"=>"DA002F8A95B04710502CB40D8430B95A"}}
|
257
|
-
# D, [2020-04-04T23:04:30.736649 #91875] DEBUG -- : RECV << {"method"=>"Target.attachedToTarget", "params"=>{"sessionId"=>"DA002F8A95B04710502CB40D8430B95A", "targetInfo"=>{"targetId"=>"EBAB949A7DE63F12CB94268AD3A9976B", "type"=>"page", "title"=>"about:blank", "url"=>"about:blank", "attached"=>true, "browserContextId"=>"46D23767E9B79DD9E589101121F6DADD"}, "waitingForDebugger"=>false}}
|
258
|
-
# So we have to wait for "Target.attachedToTarget" a bit.
|
259
|
-
20.times do
|
260
|
-
if @sessions[session_id]
|
261
|
-
return @sessions[session_id]
|
262
|
-
end
|
263
|
-
sleep 0.1
|
264
|
-
end
|
257
|
+
@sessions[session_id]
|
265
258
|
end
|
266
259
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Puppeteer::DefineAsyncMethod
|
2
|
+
refine Class do
|
3
|
+
def define_async_method(async_method_name)
|
4
|
+
unless async_method_name.to_s.start_with?('async_')
|
5
|
+
raise ArgumentError.new('async method name should start with "async_"')
|
6
|
+
end
|
7
|
+
|
8
|
+
if method_defined?(async_method_name) || private_method_defined?(async_method_name)
|
9
|
+
raise ArgumentError.new("#{async_method_name} is already defined")
|
10
|
+
end
|
11
|
+
|
12
|
+
original_method = instance_method(async_method_name[6..-1])
|
13
|
+
define_method(async_method_name) do |*args|
|
14
|
+
Concurrent::Promises.future do
|
15
|
+
original_method.bind(self).call(*args)
|
16
|
+
rescue => err
|
17
|
+
Logger.new(STDERR).warn(err)
|
18
|
+
raise err
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/puppeteer/dom_world.rb
CHANGED
@@ -2,7 +2,7 @@ require 'thread'
|
|
2
2
|
|
3
3
|
# https://github.com/puppeteer/puppeteer/blob/master/src/DOMWorld.js
|
4
4
|
class Puppeteer::DOMWorld
|
5
|
-
using Puppeteer::
|
5
|
+
using Puppeteer::DefineAsyncMethod
|
6
6
|
|
7
7
|
# @param {!Puppeteer.FrameManager} frameManager
|
8
8
|
# @param {!Puppeteer.Frame} frame
|
@@ -12,7 +12,6 @@ class Puppeteer::DOMWorld
|
|
12
12
|
@frame = frame
|
13
13
|
@timeout_settings = timeout_settings
|
14
14
|
@context_promise = resolvable_future
|
15
|
-
@pending_destroy = []
|
16
15
|
@wait_tasks = Set.new
|
17
16
|
@detached = false
|
18
17
|
end
|
@@ -24,22 +23,12 @@ class Puppeteer::DOMWorld
|
|
24
23
|
@wait_tasks
|
25
24
|
end
|
26
25
|
|
27
|
-
# @param
|
26
|
+
# @param context [Puppeteer::ExecutionContext]
|
28
27
|
def context=(context)
|
29
|
-
# D, [2020-04-12T22:45:03.938754 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextCreated", "params"=>{"context"=>{"id"=>3, "origin"=>"https://github.com", "name"=>"", "auxData"=>{"isDefault"=>true, "type"=>"default", "frameId"=>"3AD7F1E82BCBA88BFE31D03BC49FF6CB"}}}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"}
|
30
|
-
# D, [2020-04-12T22:45:03.938856 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextCreated", "params"=>{"context"=>{"id"=>4, "origin"=>"://", "name"=>"__puppeteer_utility_world__", "auxData"=>{"isDefault"=>false, "type"=>"isolated", "frameId"=>"3AD7F1E82BCBA88BFE31D03BC49FF6CB"}}}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"}
|
31
|
-
# D, [2020-04-12T22:45:03.938960 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextDestroyed", "params"=>{"executionContextId"=>1}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"}
|
32
|
-
# D, [2020-04-12T22:45:03.939110 #46154] DEBUG -- : RECV << {"method"=>"Page.frameNavigated", "params"=>{"frame"=>{"id"=>"3AD7F1E82BCBA88BFE31D03BC49FF6CB", "loaderId"=>"301B349884E582986C502CBE020966DF", "url"=>"https://github.com/", "securityOrigin"=>"https://github.com", "mimeType"=>"text/html"}}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"}
|
33
|
-
# D, [2020-04-12T22:45:03.939793 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextDestroyed", "params"=>{"executionContextId"=>2}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"}
|
34
|
-
# executionContextDestroyed is often notified after executionContextCreated.
|
35
|
-
|
36
28
|
if context
|
37
|
-
|
38
|
-
@
|
39
|
-
@document = nil
|
40
|
-
@context_promise = resolvable_future
|
29
|
+
unless @context_promise.resolved?
|
30
|
+
@context_promise.fulfill(context)
|
41
31
|
end
|
42
|
-
@context_promise.fulfill(context)
|
43
32
|
@wait_tasks.each(&:async_rerun)
|
44
33
|
else
|
45
34
|
raise ArgumentError.new("context should now be nil. Use #delete_context for clearing document.")
|
@@ -47,12 +36,8 @@ class Puppeteer::DOMWorld
|
|
47
36
|
end
|
48
37
|
|
49
38
|
def delete_context(execution_context_id)
|
50
|
-
|
51
|
-
|
52
|
-
else
|
53
|
-
@document = nil
|
54
|
-
@context_promise = resolvable_future
|
55
|
-
end
|
39
|
+
@document = nil
|
40
|
+
@context_promise = resolvable_future
|
56
41
|
end
|
57
42
|
|
58
43
|
def has_context?
|
@@ -147,45 +132,48 @@ class Puppeteer::DOMWorld
|
|
147
132
|
document.SS(selector)
|
148
133
|
end
|
149
134
|
|
150
|
-
#
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
135
|
+
# @return [String]
|
136
|
+
def content
|
137
|
+
evaluate <<-JAVASCRIPT
|
138
|
+
() => {
|
139
|
+
let retVal = '';
|
140
|
+
if (document.doctype)
|
141
|
+
retVal = new XMLSerializer().serializeToString(document.doctype);
|
142
|
+
if (document.documentElement)
|
143
|
+
retVal += document.documentElement.outerHTML;
|
144
|
+
return retVal;
|
145
|
+
}
|
146
|
+
JAVASCRIPT
|
147
|
+
end
|
163
148
|
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
149
|
+
# @param html [String]
|
150
|
+
# @param timeout [Integer]
|
151
|
+
# @param wait_until [String|Array<String>]
|
152
|
+
def set_content(html, timeout: nil, wait_until: nil)
|
153
|
+
option_wait_until = [wait_until || 'load'].flatten
|
154
|
+
option_timeout = @timeout_settings.navigation_timeout
|
155
|
+
|
156
|
+
# We rely upon the fact that document.open() will reset frame lifecycle with "init"
|
157
|
+
# lifecycle event. @see https://crrev.com/608658
|
158
|
+
js = <<-JAVASCRIPT
|
159
|
+
(html) => {
|
160
|
+
document.open();
|
161
|
+
document.write(html);
|
162
|
+
document.close();
|
163
|
+
}
|
164
|
+
JAVASCRIPT
|
165
|
+
evaluate(js, html)
|
166
|
+
|
167
|
+
watcher = Puppeteer::LifecycleWatcher.new(@frame_manager, @frame, option_wait_until, option_timeout)
|
168
|
+
begin
|
169
|
+
await_any(
|
170
|
+
watcher.timeout_or_termination_promise,
|
171
|
+
watcher.lifecycle_promise,
|
172
|
+
)
|
173
|
+
ensure
|
174
|
+
watcher.dispose
|
175
|
+
end
|
176
|
+
end
|
189
177
|
|
190
178
|
# /**
|
191
179
|
# * @param {!{url?: string, path?: string, content?: string, type?: string}} options
|
@@ -326,25 +314,28 @@ class Puppeteer::DOMWorld
|
|
326
314
|
# }
|
327
315
|
# }
|
328
316
|
|
317
|
+
class ElementNotFoundError < StandardError
|
318
|
+
def initialize(selector)
|
319
|
+
super("No node found for selector: #{selector}")
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
329
323
|
# @param selector [String]
|
330
324
|
# @param delay [Number]
|
331
325
|
# @param button [String] "left"|"right"|"middle"
|
332
326
|
# @param click_count [Number]
|
333
327
|
def click(selector, delay: nil, button: nil, click_count: nil)
|
334
|
-
handle = S(selector)
|
328
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
335
329
|
handle.click(delay: delay, button: button, click_count: click_count)
|
336
330
|
handle.dispose
|
337
331
|
end
|
338
332
|
|
339
|
-
#
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
# await handle.focus();
|
346
|
-
# await handle.dispose();
|
347
|
-
# }
|
333
|
+
# @param selector [String]
|
334
|
+
def focus(selector)
|
335
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
336
|
+
handle.focus
|
337
|
+
handle.dispose
|
338
|
+
end
|
348
339
|
|
349
340
|
# /**
|
350
341
|
# * @param {string} selector
|
@@ -359,7 +350,7 @@ class Puppeteer::DOMWorld
|
|
359
350
|
# @param selector [String]
|
360
351
|
# @return [Array<String>]
|
361
352
|
def select(selector, *values)
|
362
|
-
handle = S(selector)
|
353
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
363
354
|
result = handle.select(*values)
|
364
355
|
handle.dispose
|
365
356
|
|
@@ -368,7 +359,7 @@ class Puppeteer::DOMWorld
|
|
368
359
|
|
369
360
|
# @param selector [String]
|
370
361
|
def tap(selector)
|
371
|
-
handle = S(selector)
|
362
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
372
363
|
handle.tap
|
373
364
|
handle.dispose
|
374
365
|
end
|
@@ -377,7 +368,7 @@ class Puppeteer::DOMWorld
|
|
377
368
|
# @param text [String]
|
378
369
|
# @param delay [Number]
|
379
370
|
def type_text(selector, text, delay: nil)
|
380
|
-
handle = S(selector)
|
371
|
+
handle = S(selector) or raise ElementNotFoundError.new(selector)
|
381
372
|
handle.type_text(text, delay: delay)
|
382
373
|
handle.dispose
|
383
374
|
end
|
@@ -411,12 +402,10 @@ class Puppeteer::DOMWorld
|
|
411
402
|
# return new WaitTask(this, pageFunction, 'function', polling, timeout, ...args).promise;
|
412
403
|
# }
|
413
404
|
|
414
|
-
#
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
# return this.evaluate(() => document.title);
|
419
|
-
# }
|
405
|
+
# @return [String]
|
406
|
+
def title
|
407
|
+
evaluate('() => document.title')
|
408
|
+
end
|
420
409
|
|
421
410
|
# @param selector_or_xpath [String]
|
422
411
|
# @param is_xpath [Boolean]
|
@@ -4,7 +4,7 @@ require_relative './element_handle/point'
|
|
4
4
|
|
5
5
|
class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
6
6
|
include Puppeteer::IfPresent
|
7
|
-
using Puppeteer::
|
7
|
+
using Puppeteer::DefineAsyncMethod
|
8
8
|
|
9
9
|
# @param context [Puppeteer::ExecutionContext]
|
10
10
|
# @param client [Puppeteer::CDPSession]
|
@@ -23,7 +23,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def content_frame
|
26
|
-
node_info = @remote_object.node_info
|
26
|
+
node_info = @remote_object.node_info(@client)
|
27
27
|
frame_id = node_info['node']['frameId']
|
28
28
|
if frame_id.is_a?(String)
|
29
29
|
@frame_manager.frame(frame_id)
|
@@ -105,11 +105,11 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
def hover
|
109
|
+
scroll_into_view_if_needed
|
110
|
+
point = clickable_point
|
111
|
+
@page.mouse.move(point.x, point.y)
|
112
|
+
end
|
113
113
|
|
114
114
|
# @param delay [Number]
|
115
115
|
# @param button [String] "left"|"right"|"middle"
|
@@ -120,12 +120,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
120
120
|
@page.mouse.click(point.x, point.y, delay: delay, button: button, click_count: click_count)
|
121
121
|
end
|
122
122
|
|
123
|
-
|
124
|
-
# @param button [String] "left"|"right"|"middle"
|
125
|
-
# @param click_count [Number]
|
126
|
-
async def async_click(delay: nil, button: nil, click_count: nil)
|
127
|
-
click(delay: delay, button: button, click_count: click_count)
|
128
|
-
end
|
123
|
+
define_async_method :async_click
|
129
124
|
|
130
125
|
# @return [Array<String>]
|
131
126
|
def select(*values)
|
@@ -195,17 +190,13 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
195
190
|
@page.touchscreen.tap(point.x, point.y)
|
196
191
|
end
|
197
192
|
|
198
|
-
|
199
|
-
tap
|
200
|
-
end
|
193
|
+
define_async_method :async_tap
|
201
194
|
|
202
195
|
def focus
|
203
196
|
evaluate('element => element.focus()')
|
204
197
|
end
|
205
198
|
|
206
|
-
|
207
|
-
focus
|
208
|
-
end
|
199
|
+
define_async_method :async_focus
|
209
200
|
|
210
201
|
# @param text [String]
|
211
202
|
# @param delay [number|nil]
|
@@ -214,26 +205,17 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
214
205
|
@page.keyboard.type_text(text, delay: delay)
|
215
206
|
end
|
216
207
|
|
217
|
-
|
218
|
-
# @param delay [number|nil]
|
219
|
-
# @return [Future]
|
220
|
-
async def async_type_text(text, delay: nil)
|
221
|
-
type_text(text, delay: delay)
|
222
|
-
end
|
208
|
+
define_async_method :async_type_text
|
223
209
|
|
224
210
|
# @param key [String]
|
211
|
+
# @param text [String]
|
225
212
|
# @param delay [number|nil]
|
226
|
-
def press(key, delay: nil)
|
213
|
+
def press(key, delay: nil, text: nil)
|
227
214
|
focus
|
228
|
-
@page.keyboard.press(key, delay: delay)
|
215
|
+
@page.keyboard.press(key, delay: delay, text: text)
|
229
216
|
end
|
230
217
|
|
231
|
-
|
232
|
-
# @param delay [number|nil]
|
233
|
-
# @return [Future]
|
234
|
-
async def async_press(key, delay: nil)
|
235
|
-
press(key, delay: delay)
|
236
|
-
end
|
218
|
+
define_async_method :async_press
|
237
219
|
|
238
220
|
# @return [BoundingBox|nil]
|
239
221
|
def bounding_box
|
@@ -356,13 +338,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
356
338
|
result
|
357
339
|
end
|
358
340
|
|
359
|
-
|
360
|
-
# @param selector [String]
|
361
|
-
# @param page_function [String]
|
362
|
-
# @return [Object]
|
363
|
-
async def async_Seval(selector, page_function, *args)
|
364
|
-
Seval(selector, page_function, *args)
|
365
|
-
end
|
341
|
+
define_async_method :async_Seval
|
366
342
|
|
367
343
|
# `$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
368
344
|
# @param selector [String]
|
@@ -379,13 +355,7 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
379
355
|
result
|
380
356
|
end
|
381
357
|
|
382
|
-
|
383
|
-
# @param selector [String]
|
384
|
-
# @param page_function [String]
|
385
|
-
# @return [Object]
|
386
|
-
async def async_SSeval(selector, page_function, *args)
|
387
|
-
SSeval(selector, page_function, *args)
|
388
|
-
end
|
358
|
+
define_async_method :async_SSeval
|
389
359
|
|
390
360
|
# `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
391
361
|
# @param expression [String]
|
@@ -408,6 +378,8 @@ class Puppeteer::ElementHandle < Puppeteer::JSHandle
|
|
408
378
|
properties.values.map(&:as_element).compact
|
409
379
|
end
|
410
380
|
|
381
|
+
define_async_method :async_Sx
|
382
|
+
|
411
383
|
# /**
|
412
384
|
# * @returns {!Promise<boolean>}
|
413
385
|
# */
|