puppeteer-ruby 0.0.9 → 0.0.14
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 +40 -27
- 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 +17 -33
- data/lib/puppeteer/element_handle.rb +80 -151
- data/lib/puppeteer/element_handle/bounding_box.rb +12 -0
- data/lib/puppeteer/element_handle/box_model.rb +19 -0
- data/lib/puppeteer/element_handle/point.rb +26 -0
- data/lib/puppeteer/emulation_manager.rb +2 -6
- data/lib/puppeteer/errors.rb +1 -3
- data/lib/puppeteer/event_callbackable.rb +11 -0
- data/lib/puppeteer/execution_context.rb +1 -6
- data/lib/puppeteer/frame.rb +34 -1
- 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 +82 -67
- data/lib/puppeteer/remote_object.rb +11 -5
- data/lib/puppeteer/target.rb +10 -13
- data/lib/puppeteer/touch_screen.rb +2 -7
- data/lib/puppeteer/version.rb +1 -1
- data/lib/puppeteer/viewport.rb +18 -0
- data/lib/puppeteer/wait_task.rb +2 -4
- data/lib/puppeteer/web_socket.rb +3 -1
- data/lib/puppeteer/web_socket_transport.rb +8 -8
- data/puppeteer-ruby.gemspec +1 -1
- data/puppeteer-ruby.png +0 -0
- metadata +11 -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 -2224
- data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +0 -206
- data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +0 -206
- data/docs/Puppeteer/ElementHandle/Point.html +0 -481
- 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 -1016
- data/docs/Puppeteer/Target.html +0 -1314
- 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 -757
- 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 -809
- 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 -3971
- data/docs/top-level-namespace.html +0 -126
- data/lib/puppeteer/async_await_behavior.rb +0 -38
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
|
data/lib/puppeteer/page.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative './page/screenshot_options'
|
|
5
5
|
class Puppeteer::Page
|
6
6
|
include Puppeteer::EventCallbackable
|
7
7
|
include Puppeteer::IfPresent
|
8
|
-
using Puppeteer::
|
8
|
+
using Puppeteer::DefineAsyncMethod
|
9
9
|
|
10
10
|
# @param {!Puppeteer.CDPSession} client
|
11
11
|
# @param {!Puppeteer.Target} target
|
@@ -109,7 +109,7 @@ class Puppeteer::Page
|
|
109
109
|
@client.on_event 'Page.fileChooserOpened' do |event|
|
110
110
|
handle_file_chooser(event)
|
111
111
|
end
|
112
|
-
@target.
|
112
|
+
@target.is_closed_promise.then do
|
113
113
|
emit_event 'Events.Page.Close'
|
114
114
|
@closed = true
|
115
115
|
end
|
@@ -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
|
|
@@ -166,12 +205,7 @@ class Puppeteer::Page
|
|
166
205
|
end
|
167
206
|
end
|
168
207
|
|
169
|
-
|
170
|
-
# @return [Future<Puppeteer::FileChooser>]
|
171
|
-
async def async_wait_for_file_chooser(timeout: nil)
|
172
|
-
wait_for_file_chooser(timeout: timeout)
|
173
|
-
end
|
174
|
-
|
208
|
+
define_async_method :async_wait_for_file_chooser
|
175
209
|
|
176
210
|
# /**
|
177
211
|
# * @param {!{longitude: number, latitude: number, accuracy: (number|undefined)}} options
|
@@ -266,6 +300,8 @@ class Puppeteer::Page
|
|
266
300
|
main_frame.S(selector)
|
267
301
|
end
|
268
302
|
|
303
|
+
define_async_method :async_S
|
304
|
+
|
269
305
|
# `$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
270
306
|
# @param {string} selector
|
271
307
|
# @return {!Promise<!Array<!Puppeteer.ElementHandle>>}
|
@@ -273,6 +309,8 @@ class Puppeteer::Page
|
|
273
309
|
main_frame.SS(selector)
|
274
310
|
end
|
275
311
|
|
312
|
+
define_async_method :async_SS
|
313
|
+
|
276
314
|
# @param {Function|string} pageFunction
|
277
315
|
# @param {!Array<*>} args
|
278
316
|
# @return {!Promise<!Puppeteer.JSHandle>}
|
@@ -281,6 +319,8 @@ class Puppeteer::Page
|
|
281
319
|
context.evaluate_handle(page_function, *args)
|
282
320
|
end
|
283
321
|
|
322
|
+
define_async_method :async_evaluate_handle
|
323
|
+
|
284
324
|
# @param {!Puppeteer.JSHandle} prototypeHandle
|
285
325
|
# @return {!Promise<!Puppeteer.JSHandle>}
|
286
326
|
def query_objects(prototype_handle)
|
@@ -296,13 +336,7 @@ class Puppeteer::Page
|
|
296
336
|
main_frame.Seval(selector, page_function, *args)
|
297
337
|
end
|
298
338
|
|
299
|
-
|
300
|
-
# @param selector [String]
|
301
|
-
# @param page_function [String]
|
302
|
-
# @return [Future]
|
303
|
-
async def async_Seval(selector, page_function, *args)
|
304
|
-
Seval(selector, page_function, *args)
|
305
|
-
end
|
339
|
+
define_async_method :async_Seval
|
306
340
|
|
307
341
|
# `$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
308
342
|
# @param selector [String]
|
@@ -312,13 +346,7 @@ class Puppeteer::Page
|
|
312
346
|
main_frame.SSeval(selector, page_function, *args)
|
313
347
|
end
|
314
348
|
|
315
|
-
|
316
|
-
# @param selector [String]
|
317
|
-
# @param page_function [String]
|
318
|
-
# @return [Future]
|
319
|
-
async def async_SSeval(selector, page_function, *args)
|
320
|
-
SSeval(selector, page_function, *args)
|
321
|
-
end
|
349
|
+
define_async_method :async_SSeval
|
322
350
|
|
323
351
|
# `$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
|
324
352
|
# @param {string} expression
|
@@ -327,6 +355,8 @@ class Puppeteer::Page
|
|
327
355
|
main_frame.Sx(expression)
|
328
356
|
end
|
329
357
|
|
358
|
+
define_async_method :async_Sx
|
359
|
+
|
330
360
|
# /**
|
331
361
|
# * @param {!Array<string>} urls
|
332
362
|
# * @return {!Promise<!Array<Network.Cookie>>}
|
@@ -651,15 +681,10 @@ class Puppeteer::Page
|
|
651
681
|
# @param timeout [number|nil]
|
652
682
|
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
653
683
|
private def wait_for_navigation(timeout: nil, wait_until: nil)
|
654
|
-
main_frame.wait_for_navigation
|
684
|
+
main_frame.send(:wait_for_navigation, timeout: timeout, wait_until: wait_until)
|
655
685
|
end
|
656
686
|
|
657
|
-
|
658
|
-
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
659
|
-
# @return [Future]
|
660
|
-
async def async_wait_for_navigation(timeout: nil, wait_until: nil)
|
661
|
-
wait_for_navigation(timeout: timeout, wait_until: wait_until)
|
662
|
-
end
|
687
|
+
define_async_method :async_wait_for_navigation
|
663
688
|
|
664
689
|
# /**
|
665
690
|
# * @param {(string|Function)} urlOrPredicate
|
@@ -792,6 +817,8 @@ class Puppeteer::Page
|
|
792
817
|
main_frame.evaluate(page_function, *args)
|
793
818
|
end
|
794
819
|
|
820
|
+
define_async_method :async_evaluate
|
821
|
+
|
795
822
|
# /**
|
796
823
|
# * @param {Function|string} pageFunction
|
797
824
|
# * @param {!Array<*>} args
|
@@ -806,9 +833,9 @@ class Puppeteer::Page
|
|
806
833
|
@frame_manager.network_manager.cache_enabled = enabled
|
807
834
|
end
|
808
835
|
|
809
|
-
# @return
|
836
|
+
# @return [String]
|
810
837
|
def title
|
811
|
-
|
838
|
+
main_frame.title
|
812
839
|
end
|
813
840
|
|
814
841
|
# /**
|
@@ -943,16 +970,18 @@ class Puppeteer::Page
|
|
943
970
|
# return await helper.readProtocolStream(this._client, result.stream, path);
|
944
971
|
# }
|
945
972
|
|
946
|
-
# @param
|
947
|
-
def close
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
973
|
+
# @param run_before_unload [Boolean]
|
974
|
+
def close(run_before_unload: false)
|
975
|
+
unless @client.connection
|
976
|
+
raise 'Protocol error: Connection closed. Most likely the page has been closed.'
|
977
|
+
end
|
978
|
+
|
979
|
+
if run_before_unload
|
980
|
+
@client.send_message('Page.close')
|
981
|
+
else
|
982
|
+
@client.connection.send_message('Target.closeTarget', targetId: @target.target_id)
|
983
|
+
await @target.is_closed_promise
|
984
|
+
end
|
956
985
|
end
|
957
986
|
|
958
987
|
# @return [boolean]
|
@@ -970,20 +999,15 @@ class Puppeteer::Page
|
|
970
999
|
main_frame.click(selector, delay: delay, button: button, click_count: click_count)
|
971
1000
|
end
|
972
1001
|
|
973
|
-
|
974
|
-
# @param delay [Number]
|
975
|
-
# @param button [String] "left"|"right"|"middle"
|
976
|
-
# @param click_count [Number]
|
977
|
-
# @return [Future]
|
978
|
-
async def async_click(selector, delay: nil, button: nil, click_count: nil)
|
979
|
-
click(selector, delay: delay, button: button, click_count: click_count)
|
980
|
-
end
|
1002
|
+
define_async_method :async_click
|
981
1003
|
|
982
1004
|
# @param {string} selector
|
983
1005
|
def focus(selector)
|
984
1006
|
main_frame.focus(selector)
|
985
1007
|
end
|
986
1008
|
|
1009
|
+
define_async_method :async_focus
|
1010
|
+
|
987
1011
|
# @param {string} selector
|
988
1012
|
def hover(selector)
|
989
1013
|
main_frame.hover(selector)
|
@@ -996,15 +1020,14 @@ class Puppeteer::Page
|
|
996
1020
|
main_frame.select(selector, *values)
|
997
1021
|
end
|
998
1022
|
|
1023
|
+
define_async_method :async_select
|
1024
|
+
|
999
1025
|
# @param selector [String]
|
1000
1026
|
def tap(selector)
|
1001
1027
|
main_frame.tap(selector)
|
1002
1028
|
end
|
1003
1029
|
|
1004
|
-
|
1005
|
-
async def async_tap(selector)
|
1006
|
-
tap(selector)
|
1007
|
-
end
|
1030
|
+
define_async_method :async_tap
|
1008
1031
|
|
1009
1032
|
# @param selector [String]
|
1010
1033
|
# @param text [String]
|
@@ -1013,6 +1036,8 @@ class Puppeteer::Page
|
|
1013
1036
|
main_frame.type_text(selector, text, delay: delay)
|
1014
1037
|
end
|
1015
1038
|
|
1039
|
+
define_async_method :async_type_text
|
1040
|
+
|
1016
1041
|
# /**
|
1017
1042
|
# * @param {(string|number|Function)} selectorOrFunctionOrTimeout
|
1018
1043
|
# * @param {!{visible?: boolean, hidden?: boolean, timeout?: number, polling?: string|number}=} options
|
@@ -1031,13 +1056,7 @@ class Puppeteer::Page
|
|
1031
1056
|
main_frame.wait_for_selector(selector, visible: visible, hidden: hidden, timeout: timeout)
|
1032
1057
|
end
|
1033
1058
|
|
1034
|
-
|
1035
|
-
# @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
|
1036
|
-
# @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
|
1037
|
-
# @param timeout [Integer]
|
1038
|
-
async def async_wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil)
|
1039
|
-
wait_for_selector(selector, visible: visible, hidden: hidden, timeout: timeout)
|
1040
|
-
end
|
1059
|
+
define_async_method :async_wait_for_selector
|
1041
1060
|
|
1042
1061
|
# @param xpath [String]
|
1043
1062
|
# @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
|
@@ -1047,13 +1066,7 @@ class Puppeteer::Page
|
|
1047
1066
|
main_frame.wait_for_xpath(xpath, visible: visible, hidden: hidden, timeout: timeout)
|
1048
1067
|
end
|
1049
1068
|
|
1050
|
-
|
1051
|
-
# @param visible [Boolean] Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.
|
1052
|
-
# @param hidden [Boolean] Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.
|
1053
|
-
# @param timeout [Integer]
|
1054
|
-
async def async_wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil)
|
1055
|
-
wait_for_xpath(xpath, visible: visible, hidden: hidden, timeout: timeout)
|
1056
|
-
end
|
1069
|
+
define_async_method :async_wait_for_xpath
|
1057
1070
|
|
1058
1071
|
# @param {Function|string} pageFunction
|
1059
1072
|
# @param {!{polling?: string|number, timeout?: number}=} options
|
@@ -1062,4 +1075,6 @@ class Puppeteer::Page
|
|
1062
1075
|
def wait_for_function(page_function, options = {}, *args)
|
1063
1076
|
main_frame.wait_for_function(page_function, options, *args)
|
1064
1077
|
end
|
1078
|
+
|
1079
|
+
define_async_method :async_wait_for_function
|
1065
1080
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# providing #valueFromRemoteObject, #releaseObject
|
2
2
|
class Puppeteer::RemoteObject
|
3
3
|
include Puppeteer::DebugPrint
|
4
|
-
using Puppeteer::
|
4
|
+
using Puppeteer::DefineAsyncMethod
|
5
5
|
|
6
6
|
# @param payload [Hash]
|
7
7
|
def initialize(payload)
|
@@ -62,6 +62,15 @@ class Puppeteer::RemoteObject
|
|
62
62
|
client.send_message('DOM.getContentQuads', objectId: @object_id)
|
63
63
|
end
|
64
64
|
|
65
|
+
# used in ElementHandle#_box_model
|
66
|
+
def box_model(client)
|
67
|
+
client.send_message('DOM.getBoxModel', objectId: @object_id)
|
68
|
+
rescue => err
|
69
|
+
debug_puts(err)
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
|
73
|
+
|
65
74
|
# helper#valueFromRemoteObject
|
66
75
|
def value
|
67
76
|
if @unserializable_value
|
@@ -102,10 +111,7 @@ class Puppeteer::RemoteObject
|
|
102
111
|
nil
|
103
112
|
end
|
104
113
|
|
105
|
-
|
106
|
-
async def async_release(client)
|
107
|
-
release(client)
|
108
|
-
end
|
114
|
+
define_async_method :async_release
|
109
115
|
|
110
116
|
def converted_arg
|
111
117
|
# ported logic from ExecutionContext#convertArgument
|