puppeteer-ruby 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +71 -0
- data/.github/stale.yml +16 -0
- data/.gitignore +19 -0
- data/.rspec +3 -0
- data/.rubocop.yml +302 -0
- data/.travis.yml +7 -0
- data/Dockerfile +6 -0
- data/Gemfile +6 -0
- data/README.md +54 -0
- data/Rakefile +1 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +15 -0
- data/docs/Puppeteer.html +2020 -0
- data/docs/Puppeteer/AsyncAwaitBehavior.html +105 -0
- data/docs/Puppeteer/Browser.html +2148 -0
- data/docs/Puppeteer/BrowserContext.html +809 -0
- data/docs/Puppeteer/BrowserFetcher.html +214 -0
- data/docs/Puppeteer/BrowserRunner.html +914 -0
- data/docs/Puppeteer/BrowserRunner/BrowserProcess.html +477 -0
- data/docs/Puppeteer/CDPSession.html +813 -0
- data/docs/Puppeteer/CDPSession/Error.html +124 -0
- data/docs/Puppeteer/ConcurrentRubyUtils.html +430 -0
- data/docs/Puppeteer/Connection.html +960 -0
- data/docs/Puppeteer/Connection/MessageCallback.html +434 -0
- data/docs/Puppeteer/Connection/ProtocolError.html +216 -0
- data/docs/Puppeteer/Connection/RequestDebugPrinter.html +217 -0
- data/docs/Puppeteer/Connection/ResponseDebugPrinter.html +244 -0
- data/docs/Puppeteer/ConsoleMessage.html +565 -0
- data/docs/Puppeteer/ConsoleMessage/Location.html +433 -0
- data/docs/Puppeteer/DOMWorld.html +2219 -0
- data/docs/Puppeteer/DOMWorld/DetachedError.html +124 -0
- data/docs/Puppeteer/DOMWorld/DocumentEvaluationError.html +124 -0
- data/docs/Puppeteer/DebugPrint.html +233 -0
- data/docs/Puppeteer/Device.html +470 -0
- data/docs/Puppeteer/Devices.html +139 -0
- data/docs/Puppeteer/ElementHandle.html +2542 -0
- data/docs/Puppeteer/ElementHandle/ElementNotFoundError.html +206 -0
- data/docs/Puppeteer/ElementHandle/ElementNotVisibleError.html +206 -0
- data/docs/Puppeteer/ElementHandle/Point.html +492 -0
- data/docs/Puppeteer/ElementHandle/ScrollIntoViewError.html +124 -0
- data/docs/Puppeteer/EmulationManager.html +454 -0
- data/docs/Puppeteer/EventCallbackable.html +433 -0
- data/docs/Puppeteer/EventCallbackable/EventListeners.html +435 -0
- data/docs/Puppeteer/ExecutionContext.html +998 -0
- data/docs/Puppeteer/ExecutionContext/EvaluationError.html +124 -0
- data/docs/Puppeteer/ExecutionContext/JavaScriptExpression.html +357 -0
- data/docs/Puppeteer/ExecutionContext/JavaScriptFunction.html +389 -0
- data/docs/Puppeteer/FileChooser.html +455 -0
- data/docs/Puppeteer/Frame.html +3677 -0
- data/docs/Puppeteer/FrameManager.html +2410 -0
- data/docs/Puppeteer/FrameManager/NavigationError.html +124 -0
- data/docs/Puppeteer/IfPresent.html +222 -0
- data/docs/Puppeteer/JSHandle.html +1352 -0
- data/docs/Puppeteer/Keyboard.html +1557 -0
- data/docs/Puppeteer/Keyboard/KeyDefinition.html +831 -0
- data/docs/Puppeteer/Keyboard/KeyDescription.html +603 -0
- data/docs/Puppeteer/Launcher.html +237 -0
- data/docs/Puppeteer/Launcher/Base.html +385 -0
- data/docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html +124 -0
- data/docs/Puppeteer/Launcher/BrowserOptions.html +441 -0
- data/docs/Puppeteer/Launcher/Chrome.html +669 -0
- data/docs/Puppeteer/Launcher/Chrome/DefaultArgs.html +382 -0
- data/docs/Puppeteer/Launcher/ChromeArgOptions.html +531 -0
- data/docs/Puppeteer/Launcher/LaunchOptions.html +893 -0
- data/docs/Puppeteer/LifecycleWatcher.html +834 -0
- data/docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html +363 -0
- data/docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html +206 -0
- data/docs/Puppeteer/LifecycleWatcher/TerminatedError.html +124 -0
- data/docs/Puppeteer/Mouse.html +1105 -0
- data/docs/Puppeteer/Mouse/Button.html +136 -0
- data/docs/Puppeteer/NetworkManager.html +901 -0
- data/docs/Puppeteer/NetworkManager/Credentials.html +385 -0
- data/docs/Puppeteer/Page.html +5970 -0
- data/docs/Puppeteer/Page/FileChooserTimeoutError.html +206 -0
- data/docs/Puppeteer/Page/ScreenshotOptions.html +845 -0
- data/docs/Puppeteer/Page/ScriptTag.html +555 -0
- data/docs/Puppeteer/Page/StyleTag.html +448 -0
- data/docs/Puppeteer/Page/TargetCrashedError.html +124 -0
- data/docs/Puppeteer/RemoteObject.html +1087 -0
- data/docs/Puppeteer/Target.html +1336 -0
- data/docs/Puppeteer/Target/InitializeFailure.html +124 -0
- data/docs/Puppeteer/Target/TargetInfo.html +729 -0
- data/docs/Puppeteer/TimeoutError.html +135 -0
- data/docs/Puppeteer/TimeoutSettings.html +496 -0
- data/docs/Puppeteer/TouchScreen.html +464 -0
- data/docs/Puppeteer/Viewport.html +837 -0
- data/docs/Puppeteer/WaitTask.html +637 -0
- data/docs/Puppeteer/WaitTask/TerminatedError.html +124 -0
- data/docs/Puppeteer/WaitTask/TimeoutError.html +206 -0
- data/docs/Puppeteer/WebSocket.html +673 -0
- data/docs/Puppeteer/WebSocket/DriverImpl.html +412 -0
- data/docs/Puppeteer/WebSocketTransport.html +600 -0
- data/docs/Puppeteer/WebSocktTransportError.html +124 -0
- data/docs/_index.html +823 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.README.html +123 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +123 -0
- data/docs/js/app.js +314 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +4075 -0
- data/docs/top-level-namespace.html +126 -0
- data/lib/puppeteer.rb +200 -0
- data/lib/puppeteer/async_await_behavior.rb +38 -0
- data/lib/puppeteer/browser.rb +259 -0
- data/lib/puppeteer/browser_context.rb +90 -0
- data/lib/puppeteer/browser_fetcher.rb +6 -0
- data/lib/puppeteer/browser_runner.rb +161 -0
- data/lib/puppeteer/cdp_session.rb +100 -0
- data/lib/puppeteer/concurrent_ruby_utils.rb +37 -0
- data/lib/puppeteer/connection.rb +254 -0
- data/lib/puppeteer/console_message.rb +24 -0
- data/lib/puppeteer/debug_print.rb +20 -0
- data/lib/puppeteer/device.rb +12 -0
- data/lib/puppeteer/devices.rb +885 -0
- data/lib/puppeteer/dom_world.rb +484 -0
- data/lib/puppeteer/element_handle.rb +433 -0
- 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 +46 -0
- data/lib/puppeteer/errors.rb +2 -0
- data/lib/puppeteer/event_callbackable.rb +88 -0
- data/lib/puppeteer/execution_context.rb +254 -0
- data/lib/puppeteer/file_chooser.rb +29 -0
- data/lib/puppeteer/frame.rb +286 -0
- data/lib/puppeteer/frame_manager.rb +378 -0
- data/lib/puppeteer/if_present.rb +18 -0
- data/lib/puppeteer/js_handle.rb +142 -0
- data/lib/puppeteer/keyboard.rb +183 -0
- data/lib/puppeteer/keyboard/key_description.rb +19 -0
- data/lib/puppeteer/keyboard/us_keyboard_layout.rb +283 -0
- data/lib/puppeteer/launcher.rb +25 -0
- data/lib/puppeteer/launcher/base.rb +48 -0
- data/lib/puppeteer/launcher/browser_options.rb +41 -0
- data/lib/puppeteer/launcher/chrome.rb +211 -0
- data/lib/puppeteer/launcher/chrome_arg_options.rb +49 -0
- data/lib/puppeteer/launcher/launch_options.rb +68 -0
- data/lib/puppeteer/lifecycle_watcher.rb +171 -0
- data/lib/puppeteer/mouse.rb +123 -0
- data/lib/puppeteer/network_manager.rb +122 -0
- data/lib/puppeteer/page.rb +1065 -0
- data/lib/puppeteer/page/screenshot_options.rb +78 -0
- data/lib/puppeteer/remote_object.rb +143 -0
- data/lib/puppeteer/target.rb +150 -0
- data/lib/puppeteer/timeout_settings.rb +15 -0
- data/lib/puppeteer/touch_screen.rb +43 -0
- data/lib/puppeteer/version.rb +3 -0
- data/lib/puppeteer/viewport.rb +54 -0
- data/lib/puppeteer/wait_task.rb +188 -0
- data/lib/puppeteer/web_socket.rb +122 -0
- data/lib/puppeteer/web_socket_transport.rb +49 -0
- data/puppeteer-ruby.gemspec +32 -0
- metadata +355 -0
@@ -0,0 +1,188 @@
|
|
1
|
+
class Puppeteer::WaitTask
|
2
|
+
using Puppeteer::AsyncAwaitBehavior
|
3
|
+
|
4
|
+
class TerminatedError < StandardError; end
|
5
|
+
|
6
|
+
class TimeoutError < StandardError
|
7
|
+
def initialize(title:, timeout:)
|
8
|
+
super("waiting for #{title} failed: timeout #{timeout}ms exceeded")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(dom_world:, predicate_body:, title:, polling:, timeout:, args: [])
|
13
|
+
if polling.is_a?(String)
|
14
|
+
if polling != 'raf' && polling != 'mutation'
|
15
|
+
raise ArgumentError.new("Unknown polling option: #{polling}")
|
16
|
+
end
|
17
|
+
elsif polling.is_a?(Numeric)
|
18
|
+
unless polling.positive?
|
19
|
+
raise ArgumentError.new("Cannot poll with non-positive interval: #{polling}")
|
20
|
+
end
|
21
|
+
else
|
22
|
+
raise ArgumentError.new("Unknown polling options: #{polling}")
|
23
|
+
end
|
24
|
+
|
25
|
+
@dom_world = dom_world
|
26
|
+
@polling = polling
|
27
|
+
@timeout = timeout
|
28
|
+
@predicate_body = predicate_body
|
29
|
+
@args = args
|
30
|
+
@run_count = 0
|
31
|
+
@dom_world._wait_tasks.add(self)
|
32
|
+
@promise = resolvable_future
|
33
|
+
|
34
|
+
# Since page navigation requires us to re-install the pageScript, we should track
|
35
|
+
# timeout on our end.
|
36
|
+
if timeout
|
37
|
+
timeout_error = TimeoutError.new(title: title, timeout: timeout)
|
38
|
+
Concurrent::Promises.schedule(timeout / 1000.0) { terminate(timeout_error) unless @timeout_cleared }
|
39
|
+
end
|
40
|
+
async_rerun
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Puppeteer::JSHandle]
|
44
|
+
def await_promise
|
45
|
+
@promise.value!
|
46
|
+
end
|
47
|
+
|
48
|
+
def terminate(error)
|
49
|
+
@terminated = true
|
50
|
+
@promise.reject(error)
|
51
|
+
cleanup
|
52
|
+
end
|
53
|
+
|
54
|
+
def rerun
|
55
|
+
run_count = (@run_count += 1)
|
56
|
+
begin
|
57
|
+
success = @dom_world.execution_context.evaluate_handle(
|
58
|
+
WAIT_FOR_PREDICATE_PAGE_FUNCTION,
|
59
|
+
@predicate_body,
|
60
|
+
@polling,
|
61
|
+
@timeout,
|
62
|
+
*@args,
|
63
|
+
)
|
64
|
+
rescue => err
|
65
|
+
error = err
|
66
|
+
end
|
67
|
+
|
68
|
+
if @terminated || run_count != @run_count
|
69
|
+
if success
|
70
|
+
success.dispose
|
71
|
+
end
|
72
|
+
return
|
73
|
+
end
|
74
|
+
|
75
|
+
# Ignore timeouts in pageScript - we track timeouts ourselves.
|
76
|
+
# If the frame's execution context has already changed, `frame.evaluate` will
|
77
|
+
# throw an error - ignore this predicate run altogether.
|
78
|
+
if !error && (@dom_world.evaluate("s => !s", success) rescue true)
|
79
|
+
success.dispose
|
80
|
+
return
|
81
|
+
end
|
82
|
+
|
83
|
+
# When the page is navigated, the promise is rejected.
|
84
|
+
# We will try again in the new execution context.
|
85
|
+
if error && error.message.include?('Execution context was destroyed')
|
86
|
+
return
|
87
|
+
end
|
88
|
+
|
89
|
+
# We could have tried to evaluate in a context which was already
|
90
|
+
# destroyed.
|
91
|
+
if error && error.message.include?('Cannot find context with specified id')
|
92
|
+
return
|
93
|
+
end
|
94
|
+
|
95
|
+
if error
|
96
|
+
@promise.reject(error)
|
97
|
+
else
|
98
|
+
@promise.fulfill(success)
|
99
|
+
end
|
100
|
+
|
101
|
+
cleanup
|
102
|
+
end
|
103
|
+
|
104
|
+
private def cleanup
|
105
|
+
@timeout_cleared = true
|
106
|
+
@dom_world._wait_tasks.delete(self)
|
107
|
+
end
|
108
|
+
|
109
|
+
private async def async_rerun
|
110
|
+
rerun
|
111
|
+
end
|
112
|
+
|
113
|
+
WAIT_FOR_PREDICATE_PAGE_FUNCTION = <<~JAVASCRIPT
|
114
|
+
async function _(predicateBody, polling, timeout, ...args) {
|
115
|
+
const predicate = new Function('...args', predicateBody);
|
116
|
+
let timedOut = false;
|
117
|
+
if (timeout)
|
118
|
+
setTimeout(() => (timedOut = true), timeout);
|
119
|
+
if (polling === 'raf')
|
120
|
+
return await pollRaf();
|
121
|
+
if (polling === 'mutation')
|
122
|
+
return await pollMutation();
|
123
|
+
if (typeof polling === 'number')
|
124
|
+
return await pollInterval(polling);
|
125
|
+
/**
|
126
|
+
* @return {!Promise<*>}
|
127
|
+
*/
|
128
|
+
function pollMutation() {
|
129
|
+
const success = predicate(...args);
|
130
|
+
if (success)
|
131
|
+
return Promise.resolve(success);
|
132
|
+
let fulfill;
|
133
|
+
const result = new Promise((x) => (fulfill = x));
|
134
|
+
const observer = new MutationObserver(() => {
|
135
|
+
if (timedOut) {
|
136
|
+
observer.disconnect();
|
137
|
+
fulfill();
|
138
|
+
}
|
139
|
+
const success = predicate(...args);
|
140
|
+
if (success) {
|
141
|
+
observer.disconnect();
|
142
|
+
fulfill(success);
|
143
|
+
}
|
144
|
+
});
|
145
|
+
observer.observe(document, {
|
146
|
+
childList: true,
|
147
|
+
subtree: true,
|
148
|
+
attributes: true,
|
149
|
+
});
|
150
|
+
return result;
|
151
|
+
}
|
152
|
+
function pollRaf() {
|
153
|
+
let fulfill;
|
154
|
+
const result = new Promise((x) => (fulfill = x));
|
155
|
+
onRaf();
|
156
|
+
return result;
|
157
|
+
function onRaf() {
|
158
|
+
if (timedOut) {
|
159
|
+
fulfill();
|
160
|
+
return;
|
161
|
+
}
|
162
|
+
const success = predicate(...args);
|
163
|
+
if (success)
|
164
|
+
fulfill(success);
|
165
|
+
else
|
166
|
+
requestAnimationFrame(onRaf);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
function pollInterval(pollInterval) {
|
170
|
+
let fulfill;
|
171
|
+
const result = new Promise((x) => (fulfill = x));
|
172
|
+
onTimeout();
|
173
|
+
return result;
|
174
|
+
function onTimeout() {
|
175
|
+
if (timedOut) {
|
176
|
+
fulfill();
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
const success = predicate(...args);
|
180
|
+
if (success)
|
181
|
+
fulfill(success);
|
182
|
+
else
|
183
|
+
setTimeout(onTimeout, pollInterval);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
JAVASCRIPT
|
188
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'websocket/driver'
|
3
|
+
|
4
|
+
# ref: https://github.com/rails/rails/blob/master/actioncable/lib/action_cable/connection/client_socket.rb
|
5
|
+
# ref: https://github.com/cavalle/chrome_remote/blob/master/lib/chrome_remote/web_socket_client.rb
|
6
|
+
class Puppeteer::WebSocket
|
7
|
+
class DriverImpl # providing #url, #write(string)
|
8
|
+
def initialize(url)
|
9
|
+
@url = url
|
10
|
+
|
11
|
+
endpoint = URI.parse(url)
|
12
|
+
@socket = TCPSocket.new(endpoint.host, endpoint.port)
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :url
|
16
|
+
|
17
|
+
def write(data)
|
18
|
+
@socket.write(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def readpartial(maxlen = 1024)
|
22
|
+
@socket.readpartial(maxlen)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
STATE_CONNECTING = 0
|
27
|
+
STATE_OPENED = 1
|
28
|
+
STATE_CLOSING = 2
|
29
|
+
STATE_CLOSED = 3
|
30
|
+
|
31
|
+
def initialize(url:, max_payload_size:)
|
32
|
+
@impl = DriverImpl.new(url)
|
33
|
+
@driver = ::WebSocket::Driver.client(@impl, max_length: max_payload_size)
|
34
|
+
|
35
|
+
setup
|
36
|
+
@driver.start
|
37
|
+
|
38
|
+
Thread.new do
|
39
|
+
wait_for_data until @ready_state >= STATE_CLOSING
|
40
|
+
rescue EOFError
|
41
|
+
# Google Chrome was gone.
|
42
|
+
# We have nothing todo. Just finish polling.
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class TransportError < StandardError; end
|
47
|
+
|
48
|
+
private def setup
|
49
|
+
@ready_state = STATE_CONNECTING
|
50
|
+
@driver.on(:open) do
|
51
|
+
@ready_state = STATE_OPENED
|
52
|
+
handle_on_open
|
53
|
+
end
|
54
|
+
@driver.on(:close) do |event|
|
55
|
+
@ready_state = STATE_CLOSED
|
56
|
+
handle_on_close(reason: event.reason, code: event.code)
|
57
|
+
end
|
58
|
+
@driver.on(:error) do |event|
|
59
|
+
if !handle_on_error(error_message: event.message)
|
60
|
+
raise TransportError.new(event.message)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
@driver.on(:message) do |event|
|
64
|
+
handle_on_message(event.data)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private def wait_for_data
|
69
|
+
@driver.parse(@impl.readpartial)
|
70
|
+
end
|
71
|
+
|
72
|
+
# @param message [String]
|
73
|
+
def send_text(message)
|
74
|
+
return if @ready_state >= STATE_CLOSING
|
75
|
+
@driver.text(message)
|
76
|
+
end
|
77
|
+
|
78
|
+
def close(code: 1000, reason: "")
|
79
|
+
return if @ready_state >= STATE_CLOSING
|
80
|
+
@ready_state = STATE_CLOSING
|
81
|
+
@driver.close(reason, code)
|
82
|
+
end
|
83
|
+
|
84
|
+
def on_open(&block)
|
85
|
+
@on_open = block
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param block [Proc(reason: String, code: Numeric)]
|
89
|
+
def on_close(&block)
|
90
|
+
@on_close = block
|
91
|
+
end
|
92
|
+
|
93
|
+
# @param block [Proc(error_message: String)]
|
94
|
+
def on_error(&block)
|
95
|
+
@on_error = block
|
96
|
+
end
|
97
|
+
|
98
|
+
def on_message(&block)
|
99
|
+
@on_message = block
|
100
|
+
end
|
101
|
+
|
102
|
+
private def handle_on_open
|
103
|
+
@on_open&.call
|
104
|
+
end
|
105
|
+
|
106
|
+
private def handle_on_close(reason:, code:)
|
107
|
+
@on_close&.call(reason, code)
|
108
|
+
end
|
109
|
+
|
110
|
+
private def handle_on_error(error_message:)
|
111
|
+
return false if @on_error.nil?
|
112
|
+
|
113
|
+
@on_error.call(error_message)
|
114
|
+
true
|
115
|
+
end
|
116
|
+
|
117
|
+
private def handle_on_message(data)
|
118
|
+
return if @ready_state != STATE_OPENED
|
119
|
+
|
120
|
+
@on_message&.call(data)
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Puppeteer::WebSocketTransport
|
2
|
+
# @param {string} url
|
3
|
+
# @return [Puppeteer::WebSocketTransport]
|
4
|
+
def self.create(url)
|
5
|
+
ws = Puppeteer::WebSocket.new(
|
6
|
+
url: url,
|
7
|
+
max_payload_size: 256 * 1024 * 1024, # 256MB
|
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!
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param {!WebSocket::Driver} web_socket
|
20
|
+
def initialize(web_socket)
|
21
|
+
@ws = web_socket
|
22
|
+
@ws.on_message do |data|
|
23
|
+
@on_message&.call(data)
|
24
|
+
end
|
25
|
+
@ws.on_close do |reason, code|
|
26
|
+
@on_close&.call(reason, code)
|
27
|
+
end
|
28
|
+
@ws.on_error do |error|
|
29
|
+
# Silently ignore all errors - we don't know what to do with them.
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param message [String]
|
34
|
+
def send_text(message)
|
35
|
+
@ws.send_text(message)
|
36
|
+
end
|
37
|
+
|
38
|
+
def close
|
39
|
+
@ws.close
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_close(&block)
|
43
|
+
@on_close = block
|
44
|
+
end
|
45
|
+
|
46
|
+
def on_message(&block)
|
47
|
+
@on_message = block
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'puppeteer/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'puppeteer-ruby'
|
7
|
+
spec.version = Puppeteer::VERSION
|
8
|
+
spec.authors = ['YusukeIwaki']
|
9
|
+
spec.email = ['q7w8e9w8q7w8e9@yahoo.co.jp']
|
10
|
+
|
11
|
+
spec.summary = 'A ruby port of puppeteer'
|
12
|
+
spec.homepage = 'https://github.com/YusukeIwaki/puppeteer-ruby'
|
13
|
+
|
14
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
15
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
end
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'concurrent-ruby', '~> 1.1.0'
|
22
|
+
spec.add_dependency 'websocket-driver', '>= 0.6.0'
|
23
|
+
spec.add_dependency 'mime-types', '>= 3.0'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
25
|
+
spec.add_development_dependency 'pry-byebug'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
|
+
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.82.0'
|
30
|
+
spec.add_development_dependency 'rubocop-rspec'
|
31
|
+
spec.add_development_dependency 'yard'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,355 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppeteer-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- YusukeIwaki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: concurrent-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: websocket-driver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.6.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mime-types
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec_junit_formatter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.82.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.82.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- q7w8e9w8q7w8e9@yahoo.co.jp
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".circleci/config.yml"
|
175
|
+
- ".github/stale.yml"
|
176
|
+
- ".gitignore"
|
177
|
+
- ".rspec"
|
178
|
+
- ".rubocop.yml"
|
179
|
+
- ".travis.yml"
|
180
|
+
- Dockerfile
|
181
|
+
- Gemfile
|
182
|
+
- README.md
|
183
|
+
- Rakefile
|
184
|
+
- bin/console
|
185
|
+
- bin/setup
|
186
|
+
- docker-compose.yml
|
187
|
+
- docs/Puppeteer.html
|
188
|
+
- docs/Puppeteer/AsyncAwaitBehavior.html
|
189
|
+
- docs/Puppeteer/Browser.html
|
190
|
+
- docs/Puppeteer/BrowserContext.html
|
191
|
+
- docs/Puppeteer/BrowserFetcher.html
|
192
|
+
- docs/Puppeteer/BrowserRunner.html
|
193
|
+
- docs/Puppeteer/BrowserRunner/BrowserProcess.html
|
194
|
+
- docs/Puppeteer/CDPSession.html
|
195
|
+
- docs/Puppeteer/CDPSession/Error.html
|
196
|
+
- docs/Puppeteer/ConcurrentRubyUtils.html
|
197
|
+
- docs/Puppeteer/Connection.html
|
198
|
+
- docs/Puppeteer/Connection/MessageCallback.html
|
199
|
+
- docs/Puppeteer/Connection/ProtocolError.html
|
200
|
+
- docs/Puppeteer/Connection/RequestDebugPrinter.html
|
201
|
+
- docs/Puppeteer/Connection/ResponseDebugPrinter.html
|
202
|
+
- docs/Puppeteer/ConsoleMessage.html
|
203
|
+
- docs/Puppeteer/ConsoleMessage/Location.html
|
204
|
+
- docs/Puppeteer/DOMWorld.html
|
205
|
+
- docs/Puppeteer/DOMWorld/DetachedError.html
|
206
|
+
- docs/Puppeteer/DOMWorld/DocumentEvaluationError.html
|
207
|
+
- docs/Puppeteer/DebugPrint.html
|
208
|
+
- docs/Puppeteer/Device.html
|
209
|
+
- docs/Puppeteer/Devices.html
|
210
|
+
- docs/Puppeteer/ElementHandle.html
|
211
|
+
- docs/Puppeteer/ElementHandle/ElementNotFoundError.html
|
212
|
+
- docs/Puppeteer/ElementHandle/ElementNotVisibleError.html
|
213
|
+
- docs/Puppeteer/ElementHandle/Point.html
|
214
|
+
- docs/Puppeteer/ElementHandle/ScrollIntoViewError.html
|
215
|
+
- docs/Puppeteer/EmulationManager.html
|
216
|
+
- docs/Puppeteer/EventCallbackable.html
|
217
|
+
- docs/Puppeteer/EventCallbackable/EventListeners.html
|
218
|
+
- docs/Puppeteer/ExecutionContext.html
|
219
|
+
- docs/Puppeteer/ExecutionContext/EvaluationError.html
|
220
|
+
- docs/Puppeteer/ExecutionContext/JavaScriptExpression.html
|
221
|
+
- docs/Puppeteer/ExecutionContext/JavaScriptFunction.html
|
222
|
+
- docs/Puppeteer/FileChooser.html
|
223
|
+
- docs/Puppeteer/Frame.html
|
224
|
+
- docs/Puppeteer/FrameManager.html
|
225
|
+
- docs/Puppeteer/FrameManager/NavigationError.html
|
226
|
+
- docs/Puppeteer/IfPresent.html
|
227
|
+
- docs/Puppeteer/JSHandle.html
|
228
|
+
- docs/Puppeteer/Keyboard.html
|
229
|
+
- docs/Puppeteer/Keyboard/KeyDefinition.html
|
230
|
+
- docs/Puppeteer/Keyboard/KeyDescription.html
|
231
|
+
- docs/Puppeteer/Launcher.html
|
232
|
+
- docs/Puppeteer/Launcher/Base.html
|
233
|
+
- docs/Puppeteer/Launcher/Base/ExecutablePathNotFound.html
|
234
|
+
- docs/Puppeteer/Launcher/BrowserOptions.html
|
235
|
+
- docs/Puppeteer/Launcher/Chrome.html
|
236
|
+
- docs/Puppeteer/Launcher/Chrome/DefaultArgs.html
|
237
|
+
- docs/Puppeteer/Launcher/ChromeArgOptions.html
|
238
|
+
- docs/Puppeteer/Launcher/LaunchOptions.html
|
239
|
+
- docs/Puppeteer/LifecycleWatcher.html
|
240
|
+
- docs/Puppeteer/LifecycleWatcher/ExpectedLifecycle.html
|
241
|
+
- docs/Puppeteer/LifecycleWatcher/FrameDetachedError.html
|
242
|
+
- docs/Puppeteer/LifecycleWatcher/TerminatedError.html
|
243
|
+
- docs/Puppeteer/Mouse.html
|
244
|
+
- docs/Puppeteer/Mouse/Button.html
|
245
|
+
- docs/Puppeteer/NetworkManager.html
|
246
|
+
- docs/Puppeteer/NetworkManager/Credentials.html
|
247
|
+
- docs/Puppeteer/Page.html
|
248
|
+
- docs/Puppeteer/Page/FileChooserTimeoutError.html
|
249
|
+
- docs/Puppeteer/Page/ScreenshotOptions.html
|
250
|
+
- docs/Puppeteer/Page/ScriptTag.html
|
251
|
+
- docs/Puppeteer/Page/StyleTag.html
|
252
|
+
- docs/Puppeteer/Page/TargetCrashedError.html
|
253
|
+
- docs/Puppeteer/RemoteObject.html
|
254
|
+
- docs/Puppeteer/Target.html
|
255
|
+
- docs/Puppeteer/Target/InitializeFailure.html
|
256
|
+
- docs/Puppeteer/Target/TargetInfo.html
|
257
|
+
- docs/Puppeteer/TimeoutError.html
|
258
|
+
- docs/Puppeteer/TimeoutSettings.html
|
259
|
+
- docs/Puppeteer/TouchScreen.html
|
260
|
+
- docs/Puppeteer/Viewport.html
|
261
|
+
- docs/Puppeteer/WaitTask.html
|
262
|
+
- docs/Puppeteer/WaitTask/TerminatedError.html
|
263
|
+
- docs/Puppeteer/WaitTask/TimeoutError.html
|
264
|
+
- docs/Puppeteer/WebSocket.html
|
265
|
+
- docs/Puppeteer/WebSocket/DriverImpl.html
|
266
|
+
- docs/Puppeteer/WebSocketTransport.html
|
267
|
+
- docs/Puppeteer/WebSocktTransportError.html
|
268
|
+
- docs/_index.html
|
269
|
+
- docs/class_list.html
|
270
|
+
- docs/css/common.css
|
271
|
+
- docs/css/full_list.css
|
272
|
+
- docs/css/style.css
|
273
|
+
- docs/file.README.html
|
274
|
+
- docs/file_list.html
|
275
|
+
- docs/frames.html
|
276
|
+
- docs/index.html
|
277
|
+
- docs/js/app.js
|
278
|
+
- docs/js/full_list.js
|
279
|
+
- docs/js/jquery.js
|
280
|
+
- docs/method_list.html
|
281
|
+
- docs/top-level-namespace.html
|
282
|
+
- lib/puppeteer.rb
|
283
|
+
- lib/puppeteer/async_await_behavior.rb
|
284
|
+
- lib/puppeteer/browser.rb
|
285
|
+
- lib/puppeteer/browser_context.rb
|
286
|
+
- lib/puppeteer/browser_fetcher.rb
|
287
|
+
- lib/puppeteer/browser_runner.rb
|
288
|
+
- lib/puppeteer/cdp_session.rb
|
289
|
+
- lib/puppeteer/concurrent_ruby_utils.rb
|
290
|
+
- lib/puppeteer/connection.rb
|
291
|
+
- lib/puppeteer/console_message.rb
|
292
|
+
- lib/puppeteer/debug_print.rb
|
293
|
+
- lib/puppeteer/device.rb
|
294
|
+
- lib/puppeteer/devices.rb
|
295
|
+
- lib/puppeteer/dom_world.rb
|
296
|
+
- lib/puppeteer/element_handle.rb
|
297
|
+
- lib/puppeteer/element_handle/bounding_box.rb
|
298
|
+
- lib/puppeteer/element_handle/box_model.rb
|
299
|
+
- lib/puppeteer/element_handle/point.rb
|
300
|
+
- lib/puppeteer/emulation_manager.rb
|
301
|
+
- lib/puppeteer/errors.rb
|
302
|
+
- lib/puppeteer/event_callbackable.rb
|
303
|
+
- lib/puppeteer/execution_context.rb
|
304
|
+
- lib/puppeteer/file_chooser.rb
|
305
|
+
- lib/puppeteer/frame.rb
|
306
|
+
- lib/puppeteer/frame_manager.rb
|
307
|
+
- lib/puppeteer/if_present.rb
|
308
|
+
- lib/puppeteer/js_handle.rb
|
309
|
+
- lib/puppeteer/keyboard.rb
|
310
|
+
- lib/puppeteer/keyboard/key_description.rb
|
311
|
+
- lib/puppeteer/keyboard/us_keyboard_layout.rb
|
312
|
+
- lib/puppeteer/launcher.rb
|
313
|
+
- lib/puppeteer/launcher/base.rb
|
314
|
+
- lib/puppeteer/launcher/browser_options.rb
|
315
|
+
- lib/puppeteer/launcher/chrome.rb
|
316
|
+
- lib/puppeteer/launcher/chrome_arg_options.rb
|
317
|
+
- lib/puppeteer/launcher/launch_options.rb
|
318
|
+
- lib/puppeteer/lifecycle_watcher.rb
|
319
|
+
- lib/puppeteer/mouse.rb
|
320
|
+
- lib/puppeteer/network_manager.rb
|
321
|
+
- lib/puppeteer/page.rb
|
322
|
+
- lib/puppeteer/page/screenshot_options.rb
|
323
|
+
- lib/puppeteer/remote_object.rb
|
324
|
+
- lib/puppeteer/target.rb
|
325
|
+
- lib/puppeteer/timeout_settings.rb
|
326
|
+
- lib/puppeteer/touch_screen.rb
|
327
|
+
- lib/puppeteer/version.rb
|
328
|
+
- lib/puppeteer/viewport.rb
|
329
|
+
- lib/puppeteer/wait_task.rb
|
330
|
+
- lib/puppeteer/web_socket.rb
|
331
|
+
- lib/puppeteer/web_socket_transport.rb
|
332
|
+
- puppeteer-ruby.gemspec
|
333
|
+
homepage: https://github.com/YusukeIwaki/puppeteer-ruby
|
334
|
+
licenses: []
|
335
|
+
metadata: {}
|
336
|
+
post_install_message:
|
337
|
+
rdoc_options: []
|
338
|
+
require_paths:
|
339
|
+
- lib
|
340
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
341
|
+
requirements:
|
342
|
+
- - ">="
|
343
|
+
- !ruby/object:Gem::Version
|
344
|
+
version: '0'
|
345
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
346
|
+
requirements:
|
347
|
+
- - ">="
|
348
|
+
- !ruby/object:Gem::Version
|
349
|
+
version: '0'
|
350
|
+
requirements: []
|
351
|
+
rubygems_version: 3.0.3
|
352
|
+
signing_key:
|
353
|
+
specification_version: 4
|
354
|
+
summary: A ruby port of puppeteer
|
355
|
+
test_files: []
|