puppeteer-ruby 0.0.2 → 0.0.3
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 +41 -0
- data/.rubocop.yml +273 -6
- data/README.md +11 -1
- data/Rakefile +1 -1
- data/bin/console +1 -1
- data/lib/puppeteer.rb +2 -2
- data/lib/puppeteer/async_await_behavior.rb +17 -19
- data/lib/puppeteer/browser.rb +5 -5
- data/lib/puppeteer/browser_context.rb +2 -2
- data/lib/puppeteer/browser_runner.rb +22 -3
- data/lib/puppeteer/cdp_session.rb +2 -2
- data/lib/puppeteer/connection.rb +4 -4
- data/lib/puppeteer/debug_print.rb +1 -1
- data/lib/puppeteer/dom_world.rb +19 -3
- data/lib/puppeteer/element_handle.rb +3 -3
- data/lib/puppeteer/emulation_manager.rb +2 -2
- data/lib/puppeteer/errors.rb +2 -2
- data/lib/puppeteer/execution_context.rb +6 -6
- data/lib/puppeteer/frame.rb +2 -2
- data/lib/puppeteer/frame_manager.rb +7 -7
- data/lib/puppeteer/keyboard.rb +1 -1
- data/lib/puppeteer/keyboard/us_keyboard_layout.rb +255 -255
- data/lib/puppeteer/launcher.rb +1 -1
- data/lib/puppeteer/launcher/base.rb +2 -2
- data/lib/puppeteer/launcher/chrome.rb +6 -6
- data/lib/puppeteer/lifecycle_watcher.rb +7 -9
- data/lib/puppeteer/network_manager.rb +1 -1
- data/lib/puppeteer/page.rb +18 -18
- data/lib/puppeteer/remote_object.rb +8 -8
- data/lib/puppeteer/target.rb +2 -2
- data/lib/puppeteer/version.rb +1 -1
- data/lib/puppeteer/wait_task.rb +1 -1
- data/lib/puppeteer/web_socket.rb +3 -0
- data/puppeteer-ruby.gemspec +2 -2
- metadata +4 -4
- data/example.rb +0 -7
data/lib/puppeteer/launcher.rb
CHANGED
@@ -14,7 +14,7 @@ module Puppeteer::Launcher
|
|
14
14
|
# @return {!Puppeteer.ProductLauncher}
|
15
15
|
module_function def new(project_root:, preferred_revision:, is_puppeteer_core:, product:)
|
16
16
|
if product == 'firefox'
|
17
|
-
raise NotImplementedError.new(
|
17
|
+
raise NotImplementedError.new('FirefoxLauncher is not implemented yet.')
|
18
18
|
end
|
19
19
|
|
20
20
|
Chrome.new(
|
@@ -8,7 +8,7 @@ module Puppeteer::Launcher
|
|
8
8
|
@is_puppeteer_core = is_puppeteer_core
|
9
9
|
end
|
10
10
|
|
11
|
-
class ExecutablePathNotFound < StandardError
|
11
|
+
class ExecutablePathNotFound < StandardError; end
|
12
12
|
|
13
13
|
# @returns [String] Chrome Executable file path.
|
14
14
|
# @raise [ExecutablePathNotFound]
|
@@ -25,7 +25,7 @@ module Puppeteer::Launcher
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# temporal logic.
|
28
|
-
if RUBY_PLATFORM.include?(
|
28
|
+
if RUBY_PLATFORM.include?('darwin') # MacOS
|
29
29
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
|
30
30
|
else
|
31
31
|
'/usr/bin/google-chrome'
|
@@ -24,7 +24,7 @@ module Puppeteer::Launcher
|
|
24
24
|
#
|
25
25
|
# let temporaryUserDataDir = null;
|
26
26
|
|
27
|
-
if chrome_arguments.none?{ |arg| arg.start_with?('--remote-debugging-') }
|
27
|
+
if chrome_arguments.none? { |arg| arg.start_with?('--remote-debugging-') }
|
28
28
|
if @launch_options.pipe?
|
29
29
|
chrome_arguments << '--remote-debugging-pipe'
|
30
30
|
else
|
@@ -33,7 +33,7 @@ module Puppeteer::Launcher
|
|
33
33
|
end
|
34
34
|
|
35
35
|
temporary_user_data_dir = nil
|
36
|
-
if chrome_arguments.none?{ |arg| arg.start_with?('--user-data-dir') }
|
36
|
+
if chrome_arguments.none? { |arg| arg.start_with?('--user-data-dir') }
|
37
37
|
temporary_user_data_dir = Dir.mktmpdir('puppeteer_dev_profile-')
|
38
38
|
chrome_arguments << "--user-data-dir=#{temporary_user_data_dir}"
|
39
39
|
end
|
@@ -48,7 +48,7 @@ module Puppeteer::Launcher
|
|
48
48
|
dumpio: @launch_options.dumpio?,
|
49
49
|
env: @launch_options.env,
|
50
50
|
pipe: use_pipe,
|
51
|
-
)
|
51
|
+
)
|
52
52
|
|
53
53
|
begin
|
54
54
|
connection = runner.setup_connection(
|
@@ -64,7 +64,7 @@ module Puppeteer::Launcher
|
|
64
64
|
ignore_https_errors: @browser_options.ignore_https_errors?,
|
65
65
|
default_viewport: @browser_options.default_viewport,
|
66
66
|
process: runner.proc,
|
67
|
-
close_callback: ->{ runner.close },
|
67
|
+
close_callback: -> { runner.close },
|
68
68
|
)
|
69
69
|
|
70
70
|
browser.wait_for_target(predicate: ->(target) { target.type == 'page' })
|
@@ -115,7 +115,7 @@ module Puppeteer::Launcher
|
|
115
115
|
chrome_arguments << '--auto-open-devtools-for-tabs'
|
116
116
|
end
|
117
117
|
|
118
|
-
if
|
118
|
+
if chrome_arg_options.headless?
|
119
119
|
chrome_arguments.concat([
|
120
120
|
'--headless',
|
121
121
|
'--hide-scrollbars',
|
@@ -123,7 +123,7 @@ module Puppeteer::Launcher
|
|
123
123
|
])
|
124
124
|
end
|
125
125
|
|
126
|
-
if chrome_arg_options.args.all?{ |arg| arg.start_with?('-') }
|
126
|
+
if chrome_arg_options.args.all? { |arg| arg.start_with?('-') }
|
127
127
|
chrome_arguments << 'about:blank'
|
128
128
|
end
|
129
129
|
|
@@ -50,7 +50,7 @@ class Puppeteer::LifecycleWatcher
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
class TerminatedError < StandardError
|
53
|
+
class TerminatedError < StandardError; end
|
54
54
|
|
55
55
|
# * @param {!Puppeteer.FrameManager} frameManager
|
56
56
|
# * @param {!Puppeteer.Frame} frame
|
@@ -118,15 +118,13 @@ class Puppeteer::LifecycleWatcher
|
|
118
118
|
|
119
119
|
def timeout_or_termination_promise
|
120
120
|
if @timeout > 0
|
121
|
-
future
|
122
|
-
|
123
|
-
|
124
|
-
@termination_promise.value!
|
125
|
-
end
|
126
|
-
rescue Timeout::Error
|
127
|
-
raise Puppeteer::FrameManager::NavigationError.new("Navigation timeout of #{@timeout}ms exceeded")
|
121
|
+
future do
|
122
|
+
Timeout.timeout(@timeout / 1000.0) do
|
123
|
+
@termination_promise.value!
|
128
124
|
end
|
129
|
-
|
125
|
+
rescue Timeout::Error
|
126
|
+
raise Puppeteer::FrameManager::NavigationError.new("Navigation timeout of #{@timeout}ms exceeded")
|
127
|
+
end
|
130
128
|
else
|
131
129
|
@termination_promise
|
132
130
|
end
|
@@ -107,7 +107,7 @@ class Puppeteer::NetworkManager
|
|
107
107
|
update_protocol_cache_disabled
|
108
108
|
@client.send_message('Fetch.enable',
|
109
109
|
handleAuthRequests: true,
|
110
|
-
patterns: [{urlPattern: '*'}],
|
110
|
+
patterns: [{ urlPattern: '*' }],
|
111
111
|
)
|
112
112
|
else
|
113
113
|
update_protocol_cache_disabled
|
data/lib/puppeteer/page.rb
CHANGED
@@ -34,12 +34,12 @@ class Puppeteer::Page
|
|
34
34
|
@mouse = Puppeteer::Mouse.new(client, @keyboard)
|
35
35
|
@timeout_settings = Puppeteer::TimeoutSettings.new
|
36
36
|
@touchscreen = Puppeteer::TouchScreen.new(client, @keyboard)
|
37
|
-
|
37
|
+
# @accessibility = Accessibility.new(client)
|
38
38
|
@frame_manager = Puppeteer::FrameManager.new(client, self, ignore_https_errors, @timeout_settings)
|
39
39
|
@emulation_manager = Puppeteer::EmulationManager.new(client)
|
40
|
-
|
40
|
+
# @tracing = Tracing.new(client)
|
41
41
|
@page_bindings = {}
|
42
|
-
|
42
|
+
# @coverage = Coverage.new(client)
|
43
43
|
@javascript_enabled = true
|
44
44
|
@screenshot_task_queue = screenshot_task_queue
|
45
45
|
|
@@ -183,21 +183,21 @@ class Puppeteer::Page
|
|
183
183
|
@target.browser_context
|
184
184
|
end
|
185
185
|
|
186
|
-
class TargetCrashedError < StandardError
|
186
|
+
class TargetCrashedError < StandardError; end
|
187
187
|
|
188
188
|
private def handle_target_crashed
|
189
189
|
emit_event 'error', TargetCrashedError.new('Page crashed!')
|
190
190
|
end
|
191
191
|
|
192
192
|
private def handle_log_entry_added(event)
|
193
|
-
entry = event[
|
194
|
-
level = entry[
|
195
|
-
text = entry[
|
196
|
-
source = entry[
|
197
|
-
url = entry[
|
198
|
-
line_number = entry[
|
199
|
-
|
200
|
-
if_present(entry[
|
193
|
+
entry = event['entry']
|
194
|
+
level = entry['level']
|
195
|
+
text = entry['text']
|
196
|
+
source = entry['source']
|
197
|
+
url = entry['url']
|
198
|
+
line_number = entry['lineNumber']
|
199
|
+
|
200
|
+
if_present(entry['args']) do |args|
|
201
201
|
args.map do |arg|
|
202
202
|
Puppeteer::RemoteObject.new(arg).async_release(@client)
|
203
203
|
end
|
@@ -205,7 +205,7 @@ class Puppeteer::Page
|
|
205
205
|
if source != 'worker'
|
206
206
|
console_message_location = Puppeteer::ConsoleMessage::Location.new(
|
207
207
|
url: url, line_number: line_number)
|
208
|
-
emit_event(
|
208
|
+
emit_event('Events.Page.Console',
|
209
209
|
Puppeteer::ConsoleMessage.new(level, text, [], console_message_location))
|
210
210
|
end
|
211
211
|
end
|
@@ -686,7 +686,7 @@ class Puppeteer::Page
|
|
686
686
|
if_present(entries[index]) do |entry|
|
687
687
|
await_all(
|
688
688
|
async_wait_for_navigation(timeout: timeout, wait_until: wait_until),
|
689
|
-
@client.async_send_message('Page.navigateToHistoryEntry', entryId: entry['id'])
|
689
|
+
@client.async_send_message('Page.navigateToHistoryEntry', entryId: entry['id']),
|
690
690
|
)
|
691
691
|
end
|
692
692
|
end
|
@@ -699,9 +699,9 @@ class Puppeteer::Page
|
|
699
699
|
|
700
700
|
# @param {boolean} enabled
|
701
701
|
def javascript_enabled=(enabled)
|
702
|
-
return if
|
702
|
+
return if @javascript_enabled == enabled
|
703
703
|
@javascript_enabled = enabled
|
704
|
-
@client.send_message('Emulation.setScriptExecutionDisabled', value: !enabled)
|
704
|
+
@client.send_message('Emulation.setScriptExecutionDisabled', value: !enabled)
|
705
705
|
end
|
706
706
|
|
707
707
|
# /**
|
@@ -788,7 +788,7 @@ class Puppeteer::Page
|
|
788
788
|
def screenshot(options = {})
|
789
789
|
screenshot_options = ScreenshotOptions.new(options)
|
790
790
|
|
791
|
-
|
791
|
+
# @screenshot_task_queue.post_task(-> { screenshot_task(screenshot_options.type, screenshot_options) })
|
792
792
|
screenshot_task(screenshot_options.type, screenshot_options)
|
793
793
|
end
|
794
794
|
|
@@ -796,7 +796,7 @@ class Puppeteer::Page
|
|
796
796
|
# @param {!ScreenshotOptions=} options
|
797
797
|
# @return {!Promise<!Buffer|!String>}
|
798
798
|
private def screenshot_task(format, screenshot_options)
|
799
|
-
@client.send_message('Target.activateTarget', targetId: @target.target_id)
|
799
|
+
@client.send_message('Target.activateTarget', targetId: @target.target_id)
|
800
800
|
|
801
801
|
clip = if_present(screenshot_options.clip) do |rect|
|
802
802
|
x = rect[:x].round
|
@@ -5,10 +5,10 @@ class Puppeteer::RemoteObject
|
|
5
5
|
|
6
6
|
# @param payload [Hash]
|
7
7
|
def initialize(payload)
|
8
|
-
@object_id = payload[
|
9
|
-
@sub_type = payload[
|
10
|
-
@unserializable_value = payload[
|
11
|
-
@value = payload[
|
8
|
+
@object_id = payload['objectId']
|
9
|
+
@sub_type = payload['subtype']
|
10
|
+
@unserializable_value = payload['unserializableValue']
|
11
|
+
@value = payload['value']
|
12
12
|
end
|
13
13
|
|
14
14
|
attr_reader :sub_type
|
@@ -35,8 +35,8 @@ class Puppeteer::RemoteObject
|
|
35
35
|
'returnByValue': true,
|
36
36
|
'awaitPromise': true,
|
37
37
|
}
|
38
|
-
response = client.send_message(
|
39
|
-
Puppeteer::RemoteObject.new(response[
|
38
|
+
response = client.send_message('Runtime.callFunctionOn', params)
|
39
|
+
Puppeteer::RemoteObject.new(response['result'])
|
40
40
|
else
|
41
41
|
nil
|
42
42
|
end
|
@@ -54,7 +54,7 @@ class Puppeteer::RemoteObject
|
|
54
54
|
|
55
55
|
# used in ElementHandle#content_frame
|
56
56
|
def node_info(client)
|
57
|
-
client.send_message(
|
57
|
+
client.send_message('DOM.describeNode', objectId: @object_id)
|
58
58
|
end
|
59
59
|
|
60
60
|
# helper#valueFromRemoteObject
|
@@ -74,7 +74,7 @@ class Puppeteer::RemoteObject
|
|
74
74
|
# default:
|
75
75
|
# throw new Error('Unsupported unserializable value: ' + remoteObject.unserializableValue);
|
76
76
|
# }
|
77
|
-
raise NotImplementedError.new(
|
77
|
+
raise NotImplementedError.new('unserializable_value is not implemented yet')
|
78
78
|
else
|
79
79
|
@value
|
80
80
|
end
|
data/lib/puppeteer/target.rb
CHANGED
@@ -45,11 +45,11 @@ class Puppeteer::Target
|
|
45
45
|
|
46
46
|
attr_reader :target_id, :initialized_promise
|
47
47
|
|
48
|
-
class InitializeFailure < StandardError
|
48
|
+
class InitializeFailure < StandardError; end
|
49
49
|
|
50
50
|
def handle_initialized(success)
|
51
51
|
unless success
|
52
|
-
@initialized_promise.reject(InitializeFailure.new(
|
52
|
+
@initialized_promise.reject(InitializeFailure.new('Failed to create target for page'))
|
53
53
|
end
|
54
54
|
@on_initialize_succeeded&.call
|
55
55
|
@initialized_promise.fulfill(true)
|
data/lib/puppeteer/version.rb
CHANGED
data/lib/puppeteer/wait_task.rb
CHANGED
data/lib/puppeteer/web_socket.rb
CHANGED
data/puppeteer-ruby.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'concurrent-ruby',
|
21
|
+
spec.add_dependency 'concurrent-ruby', '~> 1.1.0'
|
22
22
|
spec.add_dependency 'websocket-driver', '>= 0.6.0'
|
23
23
|
spec.add_dependency 'mime-types', '>= 3.0'
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
25
|
-
spec.add_development_dependency 'pry'
|
25
|
+
spec.add_development_dependency 'pry-byebug'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
28
28
|
spec.add_development_dependency 'rubocop', '~> 0.80.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppeteer-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.17'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: pry
|
70
|
+
name: pry-byebug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -129,6 +129,7 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".circleci/config.yml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".rspec"
|
134
135
|
- ".rubocop.yml"
|
@@ -140,7 +141,6 @@ files:
|
|
140
141
|
- bin/console
|
141
142
|
- bin/setup
|
142
143
|
- docker-compose.yml
|
143
|
-
- example.rb
|
144
144
|
- lib/puppeteer.rb
|
145
145
|
- lib/puppeteer/async_await_behavior.rb
|
146
146
|
- lib/puppeteer/browser.rb
|