puppeteer-ruby 0.36.0 → 0.37.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +72 -49
- data/README.md +70 -1
- data/docs/api_coverage.md +39 -34
- data/lib/puppeteer/browser.rb +2 -8
- data/lib/puppeteer/browser_context.rb +1 -0
- data/lib/puppeteer/browser_runner.rb +1 -1
- data/lib/puppeteer/coverage.rb +11 -2
- data/lib/puppeteer/devices.rb +130 -0
- data/lib/puppeteer/dom_world.rb +10 -9
- data/lib/puppeteer/element_handle/offset.rb +28 -0
- data/lib/puppeteer/element_handle/point.rb +11 -0
- data/lib/puppeteer/element_handle.rb +27 -7
- data/lib/puppeteer/executable_path_finder.rb +28 -0
- data/lib/puppeteer/frame.rb +4 -3
- data/lib/puppeteer/frame_manager.rb +2 -2
- data/lib/puppeteer/{request.rb → http_request.rb} +150 -21
- data/lib/puppeteer/{response.rb → http_response.rb} +2 -2
- data/lib/puppeteer/js_coverage.rb +28 -7
- data/lib/puppeteer/launcher/chrome.rb +20 -3
- data/lib/puppeteer/launcher/firefox.rb +10 -3
- data/lib/puppeteer/launcher/launch_options.rb +3 -3
- data/lib/puppeteer/lifecycle_watcher.rb +2 -2
- data/lib/puppeteer/network_manager.rb +17 -7
- data/lib/puppeteer/page/screenshot_options.rb +3 -1
- data/lib/puppeteer/page.rb +30 -42
- data/lib/puppeteer/timeout_helper.rb +22 -0
- data/lib/puppeteer/tracing.rb +6 -1
- data/lib/puppeteer/version.rb +1 -1
- data/lib/puppeteer/wait_task.rb +1 -1
- data/lib/puppeteer/web_socket.rb +1 -0
- data/lib/puppeteer.rb +17 -13
- data/puppeteer-ruby.gemspec +1 -1
- metadata +9 -6
@@ -12,6 +12,14 @@ class Puppeteer::JSCoverage
|
|
12
12
|
attr_reader :url, :ranges, :text
|
13
13
|
end
|
14
14
|
|
15
|
+
class ItemWithRawScriptCoverage < Item
|
16
|
+
def initialize(url:, ranges:, text:, raw_script_coverage:)
|
17
|
+
super(url: url, ranges: ranges, text: text)
|
18
|
+
@raw_script_coverage = raw_script_coverage
|
19
|
+
end
|
20
|
+
attr_reader :raw_script_coverage
|
21
|
+
end
|
22
|
+
|
15
23
|
# @param client [Puppeteer::CDPSession]
|
16
24
|
def initialize(client)
|
17
25
|
@client = client
|
@@ -20,7 +28,10 @@ class Puppeteer::JSCoverage
|
|
20
28
|
@script_sources = {}
|
21
29
|
end
|
22
30
|
|
23
|
-
def start(
|
31
|
+
def start(
|
32
|
+
reset_on_navigation: nil,
|
33
|
+
report_anonymous_scripts: nil,
|
34
|
+
include_raw_script_coverage: nil)
|
24
35
|
raise 'JSCoverage is already enabled' if @enabled
|
25
36
|
|
26
37
|
@reset_on_navigation =
|
@@ -30,6 +41,7 @@ class Puppeteer::JSCoverage
|
|
30
41
|
true
|
31
42
|
end
|
32
43
|
@report_anonymous_scripts = report_anonymous_scripts || false
|
44
|
+
@include_raw_script_coverage = include_raw_script_coverage || false
|
33
45
|
@enabled = true
|
34
46
|
@script_urls.clear
|
35
47
|
@script_sources.clear
|
@@ -43,7 +55,7 @@ class Puppeteer::JSCoverage
|
|
43
55
|
await_all(
|
44
56
|
@client.async_send_message('Profiler.enable'),
|
45
57
|
@client.async_send_message('Profiler.startPreciseCoverage',
|
46
|
-
callCount:
|
58
|
+
callCount: @include_raw_script_coverage,
|
47
59
|
detailed: true,
|
48
60
|
),
|
49
61
|
@client.async_send_message('Debugger.enable'),
|
@@ -107,11 +119,20 @@ class Puppeteer::JSCoverage
|
|
107
119
|
end
|
108
120
|
end
|
109
121
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
122
|
+
if @include_raw_script_coverage
|
123
|
+
coverage << ItemWithRawScriptCoverage.new(
|
124
|
+
url: url,
|
125
|
+
ranges: convert_to_disjoint_ranges(flatten_ranges),
|
126
|
+
text: text,
|
127
|
+
raw_script_coverage: entry,
|
128
|
+
)
|
129
|
+
else
|
130
|
+
coverage << Item.new(
|
131
|
+
url: url,
|
132
|
+
ranges: convert_to_disjoint_ranges(flatten_ranges),
|
133
|
+
text: text,
|
134
|
+
)
|
135
|
+
end
|
115
136
|
end
|
116
137
|
|
117
138
|
coverage
|
@@ -48,7 +48,7 @@ module Puppeteer::Launcher
|
|
48
48
|
if @launch_options.channel
|
49
49
|
executable_path_for_channel(@launch_options.channel.to_s)
|
50
50
|
else
|
51
|
-
@launch_options.executable_path ||
|
51
|
+
@launch_options.executable_path || fallback_executable_path
|
52
52
|
end
|
53
53
|
use_pipe = chrome_arguments.include?('--remote-debugging-pipe')
|
54
54
|
runner = Puppeteer::BrowserRunner.new(chrome_executable, chrome_arguments, temporary_user_data_dir)
|
@@ -216,10 +216,14 @@ module Puppeteer::Launcher
|
|
216
216
|
if channel
|
217
217
|
executable_path_for_channel(channel.to_s)
|
218
218
|
else
|
219
|
-
|
219
|
+
fallback_executable_path
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
+
private def fallback_executable_path
|
224
|
+
executable_path_for_channel('chrome')
|
225
|
+
end
|
226
|
+
|
223
227
|
CHROMIUM_CHANNELS = {
|
224
228
|
windows: {
|
225
229
|
'chrome' => "#{ENV['PROGRAMFILES']}\\Google\\Chrome\\Application\\chrome.exe",
|
@@ -236,7 +240,16 @@ module Puppeteer::Launcher
|
|
236
240
|
'msedge' => '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
237
241
|
},
|
238
242
|
linux: {
|
239
|
-
'chrome' =>
|
243
|
+
'chrome' => -> {
|
244
|
+
Puppeteer::ExecutablePathFinder.new(
|
245
|
+
'google-chrome-stable',
|
246
|
+
'google-chrome',
|
247
|
+
'chrome',
|
248
|
+
'chromium-freeworld',
|
249
|
+
'chromium-browser',
|
250
|
+
'chromium',
|
251
|
+
).find_first
|
252
|
+
},
|
240
253
|
'chrome-beta' => '/opt/google/chrome-beta/chrome',
|
241
254
|
'chrome-dev' => '/opt/google/chrome-unstable/chrome',
|
242
255
|
},
|
@@ -254,6 +267,10 @@ module Puppeteer::Launcher
|
|
254
267
|
end
|
255
268
|
|
256
269
|
chrome_path = chrome_path_map[channel]
|
270
|
+
if chrome_path.is_a?(Proc)
|
271
|
+
chrome_path = chrome_path.call
|
272
|
+
end
|
273
|
+
|
257
274
|
unless chrome_path
|
258
275
|
raise ArgumentError.new("Invalid channel: '#{channel}'. Allowed channel is #{chrome_path_map.keys}")
|
259
276
|
end
|
@@ -42,7 +42,7 @@ module Puppeteer::Launcher
|
|
42
42
|
if @launch_options.channel
|
43
43
|
executable_path_for_channel(@launch_options.channel.to_s)
|
44
44
|
else
|
45
|
-
@launch_options.executable_path ||
|
45
|
+
@launch_options.executable_path || fallback_executable_path
|
46
46
|
end
|
47
47
|
runner = Puppeteer::BrowserRunner.new(firefox_executable, firefox_arguments, temporary_user_data_dir)
|
48
48
|
runner.start(
|
@@ -138,14 +138,18 @@ module Puppeteer::Launcher
|
|
138
138
|
if channel
|
139
139
|
executable_path_for_channel(channel.to_s)
|
140
140
|
else
|
141
|
-
|
141
|
+
fallback_executable_path
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
145
|
+
private def fallback_executable_path
|
146
|
+
executable_path_for_channel('firefox')
|
147
|
+
end
|
148
|
+
|
145
149
|
FIREFOX_EXECUTABLE_PATHS = {
|
146
150
|
windows: "#{ENV['PROGRAMFILES']}\\Firefox Nightly\\firefox.exe",
|
147
151
|
darwin: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox',
|
148
|
-
linux: '
|
152
|
+
linux: -> { Puppeteer::ExecutablePathFinder.new('firefox').find_first },
|
149
153
|
}.freeze
|
150
154
|
|
151
155
|
# @param channel [String]
|
@@ -163,6 +167,9 @@ module Puppeteer::Launcher
|
|
163
167
|
else
|
164
168
|
FIREFOX_EXECUTABLE_PATHS[:linux]
|
165
169
|
end
|
170
|
+
if firefox_path.is_a?(Proc)
|
171
|
+
firefox_path = firefox_path.call
|
172
|
+
end
|
166
173
|
|
167
174
|
unless File.exist?(firefox_path)
|
168
175
|
raise "Nightly version of Firefox is not installed on this system.\nExpected path: #{firefox_path}"
|
@@ -35,9 +35,9 @@ module Puppeteer::Launcher
|
|
35
35
|
@channel = options[:channel]
|
36
36
|
@executable_path = options[:executable_path]
|
37
37
|
@ignore_default_args = options[:ignore_default_args] || false
|
38
|
-
@handle_SIGINT = options
|
39
|
-
@handle_SIGTERM = options
|
40
|
-
@handle_SIGHUP = options
|
38
|
+
@handle_SIGINT = options.fetch(:handle_SIGINT, true)
|
39
|
+
@handle_SIGTERM = options.fetch(:handle_SIGTERM, true)
|
40
|
+
@handle_SIGHUP = options.fetch(:handle_SIGHUP, true)
|
41
41
|
@timeout = options[:timeout] || 30000
|
42
42
|
@dumpio = options[:dumpio] || false
|
43
43
|
@env = options[:env] || ENV
|
@@ -88,7 +88,7 @@ class Puppeteer::LifecycleWatcher
|
|
88
88
|
check_lifecycle_complete
|
89
89
|
end
|
90
90
|
|
91
|
-
# @param [Puppeteer::
|
91
|
+
# @param [Puppeteer::HTTPRequest] request
|
92
92
|
def handle_request(request)
|
93
93
|
return if request.frame != @frame || !request.navigation_request?
|
94
94
|
@navigation_request = request
|
@@ -103,7 +103,7 @@ class Puppeteer::LifecycleWatcher
|
|
103
103
|
check_lifecycle_complete
|
104
104
|
end
|
105
105
|
|
106
|
-
# @return [Puppeteer::
|
106
|
+
# @return [Puppeteer::HTTPResponse]
|
107
107
|
def navigation_response
|
108
108
|
if_present(@navigation_request) do |request|
|
109
109
|
request.response
|
@@ -142,9 +142,14 @@ class Puppeteer::NetworkManager
|
|
142
142
|
end
|
143
143
|
|
144
144
|
# @param user_agent [String]
|
145
|
-
|
146
|
-
|
145
|
+
# @param user_agent_metadata [Hash]
|
146
|
+
def set_user_agent(user_agent, user_agent_metadata = nil)
|
147
|
+
@client.send_message('Network.setUserAgentOverride', {
|
148
|
+
userAgent: user_agent,
|
149
|
+
userAgentMetadata: user_agent_metadata,
|
150
|
+
}.compact)
|
147
151
|
end
|
152
|
+
alias_method :user_agent=, :set_user_agent
|
148
153
|
|
149
154
|
def cache_enabled=(enabled)
|
150
155
|
@user_cache_disabled = !enabled
|
@@ -246,9 +251,14 @@ class Puppeteer::NetworkManager
|
|
246
251
|
end
|
247
252
|
end
|
248
253
|
frame = if_present(event['frameId']) { |frame_id| @frame_manager.frame(frame_id) }
|
249
|
-
request = Puppeteer::
|
254
|
+
request = Puppeteer::HTTPRequest.new(@client, frame, interception_id, @user_request_interception_enabled, event, redirect_chain)
|
250
255
|
@request_id_to_request[event['requestId']] = request
|
251
256
|
emit_event(NetworkManagerEmittedEvents::Request, request)
|
257
|
+
begin
|
258
|
+
request.finalize_interceptions
|
259
|
+
rescue => err
|
260
|
+
debug_puts(err)
|
261
|
+
end
|
252
262
|
end
|
253
263
|
|
254
264
|
private def handle_request_served_from_cache(event)
|
@@ -257,13 +267,13 @@ class Puppeteer::NetworkManager
|
|
257
267
|
end
|
258
268
|
end
|
259
269
|
|
260
|
-
# @param request [Puppeteer::
|
270
|
+
# @param request [Puppeteer::HTTPRequest]
|
261
271
|
# @param response_payload [Hash]
|
262
272
|
private def handle_request_redirect(request, response_payload)
|
263
|
-
response = Puppeteer::
|
273
|
+
response = Puppeteer::HTTPResponse.new(@client, request, response_payload)
|
264
274
|
request.internal.response = response
|
265
275
|
request.internal.redirect_chain << request
|
266
|
-
response.internal.body_loaded_promise.reject(Puppeteer::
|
276
|
+
response.internal.body_loaded_promise.reject(Puppeteer::HTTPResponse::Redirected.new)
|
267
277
|
@request_id_to_request.delete(request.internal.request_id)
|
268
278
|
@attempted_authentications.delete(request.internal.interception_id)
|
269
279
|
emit_event(NetworkManagerEmittedEvents::Response, response)
|
@@ -276,7 +286,7 @@ class Puppeteer::NetworkManager
|
|
276
286
|
# FileUpload sends a response without a matching request.
|
277
287
|
return unless request
|
278
288
|
|
279
|
-
response = Puppeteer::
|
289
|
+
response = Puppeteer::HTTPResponse.new(@client, request, event['response'])
|
280
290
|
request.internal.response = response
|
281
291
|
emit_event(NetworkManagerEmittedEvents::Response, response)
|
282
292
|
end
|
@@ -15,7 +15,7 @@ class Puppeteer::Page
|
|
15
15
|
# @params options [Hash]
|
16
16
|
def initialize(options)
|
17
17
|
if options[:type]
|
18
|
-
unless [:png, :jpeg].include?(options[:type].to_sym)
|
18
|
+
unless [:png, :jpeg, :webp].include?(options[:type].to_sym)
|
19
19
|
raise ArgumentError.new("Unknown options.type value: #{options[:type]}")
|
20
20
|
end
|
21
21
|
@type = options[:type]
|
@@ -25,6 +25,8 @@ class Puppeteer::Page
|
|
25
25
|
@type = 'png'
|
26
26
|
elsif mime_types.include?('image/jpeg')
|
27
27
|
@type = 'jpeg'
|
28
|
+
elsif mime_types.include?('image/webp')
|
29
|
+
@type = 'webp'
|
28
30
|
else
|
29
31
|
raise ArgumentError.new("Unsupported screenshot mime type resolved: #{mime_types}, path: #{options[:path]}")
|
30
32
|
end
|
data/lib/puppeteer/page.rb
CHANGED
@@ -153,6 +153,12 @@ class Puppeteer::Page
|
|
153
153
|
raise ArgumentError.new("Unknown event name: #{event_name}. Known events are #{PageEmittedEvents.values.to_a.join(", ")}")
|
154
154
|
end
|
155
155
|
|
156
|
+
if event_name.to_s == 'request'
|
157
|
+
super('request') do |req|
|
158
|
+
req.enqueue_intercept_action(-> { block.call(req) })
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
156
162
|
super(event_name.to_s, &block)
|
157
163
|
end
|
158
164
|
|
@@ -404,8 +410,9 @@ class Puppeteer::Page
|
|
404
410
|
# @param path [String?]
|
405
411
|
# @param content [String?]
|
406
412
|
# @param type [String?]
|
407
|
-
|
408
|
-
|
413
|
+
# @param id [String?]
|
414
|
+
def add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil)
|
415
|
+
main_frame.add_script_tag(url: url, path: path, content: content, type: type, id: id)
|
409
416
|
end
|
410
417
|
|
411
418
|
# @param url [String?]
|
@@ -460,37 +467,6 @@ class Puppeteer::Page
|
|
460
467
|
|
461
468
|
nil
|
462
469
|
end
|
463
|
-
# /**
|
464
|
-
# * @param {string} name
|
465
|
-
# * @param {Function} puppeteerFunction
|
466
|
-
# */
|
467
|
-
# async exposeFunction(name, puppeteerFunction) {
|
468
|
-
# if (this._pageBindings.has(name))
|
469
|
-
# throw new Error(`Failed to add page binding with name ${name}: window['${name}'] already exists!`);
|
470
|
-
# this._pageBindings.set(name, puppeteerFunction);
|
471
|
-
|
472
|
-
# const expression = helper.evaluationString(addPageBinding, name);
|
473
|
-
# await this._client.send('Runtime.addBinding', {name: name});
|
474
|
-
# await this._client.send('Page.addScriptToEvaluateOnNewDocument', {source: expression});
|
475
|
-
# await Promise.all(this.frames().map(frame => frame.evaluate(expression).catch(debugError)));
|
476
|
-
|
477
|
-
# function addPageBinding(bindingName) {
|
478
|
-
# const binding = window[bindingName];
|
479
|
-
# window[bindingName] = (...args) => {
|
480
|
-
# const me = window[bindingName];
|
481
|
-
# let callbacks = me['callbacks'];
|
482
|
-
# if (!callbacks) {
|
483
|
-
# callbacks = new Map();
|
484
|
-
# me['callbacks'] = callbacks;
|
485
|
-
# }
|
486
|
-
# const seq = (me['lastSeq'] || 0) + 1;
|
487
|
-
# me['lastSeq'] = seq;
|
488
|
-
# const promise = new Promise((resolve, reject) => callbacks.set(seq, {resolve, reject}));
|
489
|
-
# binding(JSON.stringify({name: bindingName, seq, args}));
|
490
|
-
# return promise;
|
491
|
-
# };
|
492
|
-
# }
|
493
|
-
# }
|
494
470
|
|
495
471
|
# @param username [String?]
|
496
472
|
# @param password [String?]
|
@@ -504,9 +480,11 @@ class Puppeteer::Page
|
|
504
480
|
end
|
505
481
|
|
506
482
|
# @param user_agent [String]
|
507
|
-
|
508
|
-
|
483
|
+
# @param user_agent_metadata [Hash]
|
484
|
+
def set_user_agent(user_agent, user_agent_metadata = nil)
|
485
|
+
@frame_manager.network_manager.set_user_agent(user_agent, user_agent_metadata)
|
509
486
|
end
|
487
|
+
alias_method :user_agent=, :set_user_agent
|
510
488
|
|
511
489
|
def metrics
|
512
490
|
response = @client.send_message('Performance.getMetrics')
|
@@ -666,7 +644,7 @@ class Puppeteer::Page
|
|
666
644
|
|
667
645
|
# @param timeout [number|nil]
|
668
646
|
# @param wait_until [string|nil] 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'
|
669
|
-
# @return [Puppeteer::
|
647
|
+
# @return [Puppeteer::HTTPResponse]
|
670
648
|
def reload(timeout: nil, wait_until: nil)
|
671
649
|
wait_for_navigation(timeout: timeout, wait_until: wait_until) do
|
672
650
|
@client.send_message('Page.reload')
|
@@ -696,11 +674,12 @@ class Puppeteer::Page
|
|
696
674
|
@wait_for_network_manager_event_listener_ids[event_name] =
|
697
675
|
@frame_manager.network_manager.add_event_listener(event_name) do |event_target|
|
698
676
|
if predicate.call(event_target)
|
699
|
-
promise.fulfill(
|
677
|
+
promise.fulfill(event_target)
|
700
678
|
end
|
701
679
|
end
|
702
680
|
|
703
681
|
begin
|
682
|
+
# Timeout.timeout(0) means "no limit" for timeout.
|
704
683
|
Timeout.timeout(option_timeout / 1000.0) do
|
705
684
|
await_any(promise, session_close_promise)
|
706
685
|
end
|
@@ -750,7 +729,7 @@ class Puppeteer::Page
|
|
750
729
|
# wait_for_request(predicate: -> (req){ req.url.start_with?('https://example.com/search') })
|
751
730
|
#
|
752
731
|
# @param url [String]
|
753
|
-
# @param predicate [Proc(Puppeteer::
|
732
|
+
# @param predicate [Proc(Puppeteer::HTTPRequest -> Boolean)]
|
754
733
|
define_async_method :async_wait_for_request
|
755
734
|
|
756
735
|
def wait_for_response(url: nil, predicate: nil, timeout: nil)
|
@@ -776,7 +755,7 @@ class Puppeteer::Page
|
|
776
755
|
# @!method async_wait_for_response(url: nil, predicate: nil, timeout: nil)
|
777
756
|
#
|
778
757
|
# @param url [String]
|
779
|
-
# @param predicate [Proc(Puppeteer::
|
758
|
+
# @param predicate [Proc(Puppeteer::HTTPRequest -> Boolean)]
|
780
759
|
define_async_method :async_wait_for_response
|
781
760
|
|
782
761
|
# @param timeout [number|nil]
|
@@ -965,7 +944,7 @@ class Puppeteer::Page
|
|
965
944
|
main_frame.title
|
966
945
|
end
|
967
946
|
|
968
|
-
# @param type [String] "png"|"jpeg"
|
947
|
+
# @param type [String] "png"|"jpeg"|"webp"
|
969
948
|
# @param path [String]
|
970
949
|
# @param full_page [Boolean]
|
971
950
|
# @param clip [Hash]
|
@@ -1059,11 +1038,20 @@ class Puppeteer::Page
|
|
1059
1038
|
|
1060
1039
|
# @return [Enumerable<String>]
|
1061
1040
|
def create_pdf_stream(options = {})
|
1041
|
+
timeout_helper = Puppeteer::TimeoutHelper.new('Page.printToPDF',
|
1042
|
+
timeout_ms: options[:timeout],
|
1043
|
+
default_timeout_ms: 30000)
|
1062
1044
|
pdf_options = PDFOptions.new(options)
|
1063
1045
|
omit_background = options[:omit_background]
|
1064
1046
|
set_transparent_background_color if omit_background
|
1065
|
-
result =
|
1066
|
-
|
1047
|
+
result =
|
1048
|
+
begin
|
1049
|
+
timeout_helper.with_timeout do
|
1050
|
+
@client.send_message('Page.printToPDF', pdf_options.page_print_args)
|
1051
|
+
end
|
1052
|
+
ensure
|
1053
|
+
reset_default_background_color if omit_background
|
1054
|
+
end
|
1067
1055
|
|
1068
1056
|
Puppeteer::ProtocolStreamReader.new(
|
1069
1057
|
client: @client,
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
|
3
|
+
class Puppeteer::TimeoutHelper
|
4
|
+
# @param timeout_ms [String|Integer|nil]
|
5
|
+
# @param default_timeout_ms [Integer]
|
6
|
+
def initialize(task_name, timeout_ms:, default_timeout_ms:)
|
7
|
+
@task_name = task_name
|
8
|
+
@timeout_ms = (timeout_ms || default_timeout_ms).to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_timeout(&block)
|
12
|
+
if @timeout_ms > 0
|
13
|
+
begin
|
14
|
+
Timeout.timeout(@timeout_ms / 1000.0, &block)
|
15
|
+
rescue Timeout::Error
|
16
|
+
raise Puppeteer::TimeoutError.new("waiting for #{@task_name} failed: timeout #{@timeout_ms}ms exceeded")
|
17
|
+
end
|
18
|
+
else
|
19
|
+
block.call
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/puppeteer/tracing.rb
CHANGED
@@ -27,11 +27,16 @@ class Puppeteer::Tracing
|
|
27
27
|
option_categories << 'disabled-by-default-devtools.screenshot'
|
28
28
|
end
|
29
29
|
|
30
|
+
ex_cat = option_categories.select { |cat| cat.start_with?('-') }.map { |cat| cat[1..-1] }
|
31
|
+
in_cat = option_categories.reject { |cat| cat.start_with?('-') }
|
30
32
|
@path = path
|
31
33
|
@recording = true
|
32
34
|
@client.send_message('Tracing.start',
|
33
35
|
transferMode: 'ReturnAsStream',
|
34
|
-
|
36
|
+
traceConfig: {
|
37
|
+
excludedCategories: ex_cat,
|
38
|
+
includedCategories: in_cat,
|
39
|
+
},
|
35
40
|
)
|
36
41
|
end
|
37
42
|
|
data/lib/puppeteer/version.rb
CHANGED
data/lib/puppeteer/wait_task.rb
CHANGED
@@ -37,7 +37,7 @@ class Puppeteer::WaitTask
|
|
37
37
|
|
38
38
|
# Since page navigation requires us to re-install the pageScript, we should track
|
39
39
|
# timeout on our end.
|
40
|
-
if timeout
|
40
|
+
if timeout && timeout > 0
|
41
41
|
timeout_error = TimeoutError.new(title: title, timeout: timeout)
|
42
42
|
Concurrent::Promises.schedule(timeout / 1000.0) { terminate(timeout_error) unless @timeout_cleared }
|
43
43
|
end
|
data/lib/puppeteer/web_socket.rb
CHANGED
@@ -55,6 +55,7 @@ class Puppeteer::WebSocket
|
|
55
55
|
def initialize(url:, max_payload_size:)
|
56
56
|
@impl = DriverImpl.new(url)
|
57
57
|
@driver = ::WebSocket::Driver.client(@impl, max_length: max_payload_size)
|
58
|
+
@driver.set_header('User-Agent', "Puppeteer #{Puppeteer::VERSION}")
|
58
59
|
|
59
60
|
setup
|
60
61
|
@driver.start
|
data/lib/puppeteer.rb
CHANGED
@@ -33,10 +33,13 @@ require 'puppeteer/dialog'
|
|
33
33
|
require 'puppeteer/dom_world'
|
34
34
|
require 'puppeteer/emulation_manager'
|
35
35
|
require 'puppeteer/exception_details'
|
36
|
+
require 'puppeteer/executable_path_finder'
|
36
37
|
require 'puppeteer/execution_context'
|
37
38
|
require 'puppeteer/file_chooser'
|
38
39
|
require 'puppeteer/frame'
|
39
40
|
require 'puppeteer/frame_manager'
|
41
|
+
require 'puppeteer/http_request'
|
42
|
+
require 'puppeteer/http_response'
|
40
43
|
require 'puppeteer/js_coverage'
|
41
44
|
require 'puppeteer/js_handle'
|
42
45
|
require 'puppeteer/keyboard'
|
@@ -50,10 +53,9 @@ require 'puppeteer/protocol_stream_reader'
|
|
50
53
|
require 'puppeteer/puppeteer'
|
51
54
|
require 'puppeteer/query_handler_manager'
|
52
55
|
require 'puppeteer/remote_object'
|
53
|
-
require 'puppeteer/request'
|
54
|
-
require 'puppeteer/response'
|
55
56
|
require 'puppeteer/target'
|
56
57
|
require 'puppeteer/tracing'
|
58
|
+
require 'puppeteer/timeout_helper'
|
57
59
|
require 'puppeteer/timeout_settings'
|
58
60
|
require 'puppeteer/touch_screen'
|
59
61
|
require 'puppeteer/version'
|
@@ -66,17 +68,19 @@ require 'puppeteer/element_handle'
|
|
66
68
|
|
67
69
|
# ref: https://github.com/puppeteer/puppeteer/blob/master/lib/Puppeteer.js
|
68
70
|
module Puppeteer
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
@puppeteer ||= ::Puppeteer::Puppeteer.new(
|
72
|
+
project_root: __dir__,
|
73
|
+
preferred_revision: '706915',
|
74
|
+
is_puppeteer_core: true,
|
75
|
+
).tap do |instance|
|
76
|
+
instance.public_methods(false).each do |method_name|
|
77
|
+
define_singleton_method(method_name) do |*args, **kwargs, &block|
|
78
|
+
if kwargs.empty? # for Ruby < 2.7
|
79
|
+
@puppeteer.public_send(method_name, *args, &block)
|
80
|
+
else
|
81
|
+
@puppeteer.public_send(method_name, *args, **kwargs, &block)
|
82
|
+
end
|
83
|
+
end
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
data/puppeteer-ruby.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'rollbar'
|
33
33
|
spec.add_development_dependency 'rspec', '~> 3.10.0 '
|
34
34
|
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
35
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.23.0'
|
36
36
|
spec.add_development_dependency 'rubocop-rspec'
|
37
37
|
spec.add_development_dependency 'sinatra'
|
38
38
|
spec.add_development_dependency 'webrick'
|
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.
|
4
|
+
version: 0.37.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.
|
173
|
+
version: 1.23.0
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.
|
180
|
+
version: 1.23.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rubocop-rspec
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,6 +274,7 @@ files:
|
|
274
274
|
- lib/puppeteer/element_handle.rb
|
275
275
|
- lib/puppeteer/element_handle/bounding_box.rb
|
276
276
|
- lib/puppeteer/element_handle/box_model.rb
|
277
|
+
- lib/puppeteer/element_handle/offset.rb
|
277
278
|
- lib/puppeteer/element_handle/point.rb
|
278
279
|
- lib/puppeteer/emulation_manager.rb
|
279
280
|
- lib/puppeteer/env.rb
|
@@ -281,11 +282,14 @@ files:
|
|
281
282
|
- lib/puppeteer/event_callbackable.rb
|
282
283
|
- lib/puppeteer/events.rb
|
283
284
|
- lib/puppeteer/exception_details.rb
|
285
|
+
- lib/puppeteer/executable_path_finder.rb
|
284
286
|
- lib/puppeteer/execution_context.rb
|
285
287
|
- lib/puppeteer/file_chooser.rb
|
286
288
|
- lib/puppeteer/frame.rb
|
287
289
|
- lib/puppeteer/frame_manager.rb
|
288
290
|
- lib/puppeteer/geolocation.rb
|
291
|
+
- lib/puppeteer/http_request.rb
|
292
|
+
- lib/puppeteer/http_response.rb
|
289
293
|
- lib/puppeteer/if_present.rb
|
290
294
|
- lib/puppeteer/js_coverage.rb
|
291
295
|
- lib/puppeteer/js_handle.rb
|
@@ -312,9 +316,8 @@ files:
|
|
312
316
|
- lib/puppeteer/puppeteer.rb
|
313
317
|
- lib/puppeteer/query_handler_manager.rb
|
314
318
|
- lib/puppeteer/remote_object.rb
|
315
|
-
- lib/puppeteer/request.rb
|
316
|
-
- lib/puppeteer/response.rb
|
317
319
|
- lib/puppeteer/target.rb
|
320
|
+
- lib/puppeteer/timeout_helper.rb
|
318
321
|
- lib/puppeteer/timeout_settings.rb
|
319
322
|
- lib/puppeteer/touch_screen.rb
|
320
323
|
- lib/puppeteer/tracing.rb
|