puppeteer-ruby 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/reviewdog.yml +4 -1
- data/.github/workflows/windows_check.yml +40 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +11 -1
- data/lib/puppeteer/browser_runner.rb +1 -1
- data/lib/puppeteer/dom_world.rb +120 -137
- data/lib/puppeteer/env.rb +4 -0
- data/lib/puppeteer/frame.rb +13 -10
- data/lib/puppeteer/launcher/base.rb +8 -0
- data/lib/puppeteer/page.rb +92 -88
- data/lib/puppeteer/version.rb +1 -1
- data/lib/puppeteer/web_socket.rb +2 -0
- data/lib/puppeteer/web_socket_transport.rb +2 -0
- data/puppeteer-ruby.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d7c0b6410629e9119a7f298cc3cecdd6e5640a18fdb944dc53e1b47b4c940b0
|
4
|
+
data.tar.gz: 4f9bf8f3e4a21a22cb89fcff1927e420bff86cbdec4a3084dbec32669530f03e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a13874bd8b09ea00a33516f1237e3a91fcfa6b18795af251f3568dc421f026821325c2e89d2e2ee8e8211b03ed1700d8ba15c3a2d01e733ffaa378a1f97b02bc
|
7
|
+
data.tar.gz: 3920af1f121788b36e68ee85194da1fe92335abed949610f726d90bd368d492502da10d935087bbadb386eab13f41f259263dd7777eb42d8988fecc3e1fa83da
|
@@ -7,9 +7,12 @@ jobs:
|
|
7
7
|
steps:
|
8
8
|
- name: Check out code
|
9
9
|
uses: actions/checkout@v2
|
10
|
+
- uses: ruby/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: 3.0.0
|
10
13
|
- name: rubocop
|
11
14
|
uses: reviewdog/action-rubocop@v1
|
12
15
|
with:
|
13
16
|
github_token: ${{ secrets.github_token }}
|
14
17
|
reporter: github-pr-review
|
15
|
-
rubocop_version: 1.
|
18
|
+
rubocop_version: 1.11.0
|
@@ -0,0 +1,40 @@
|
|
1
|
+
name: Windows check
|
2
|
+
on: [pull_request]
|
3
|
+
jobs:
|
4
|
+
windows_edge_rspec:
|
5
|
+
name: RSpec on Windows / Edge
|
6
|
+
runs-on: windows-latest
|
7
|
+
steps:
|
8
|
+
- name: Check out code
|
9
|
+
uses: actions/checkout@v2
|
10
|
+
- uses: ruby/setup-ruby@v1
|
11
|
+
with:
|
12
|
+
ruby-version: 3.0.0
|
13
|
+
- name: Install dependencies
|
14
|
+
run: |
|
15
|
+
gem uninstall bundler
|
16
|
+
gem install bundler -v 2.2.3
|
17
|
+
bundle install
|
18
|
+
- uses: browser-actions/setup-edge@latest
|
19
|
+
- name: Check example
|
20
|
+
run: bundle exec rspec spec/integration/example_spec.rb
|
21
|
+
env:
|
22
|
+
PUPPETEER_EXECUTABLE_PATH_RSPEC: 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
|
23
|
+
|
24
|
+
windows_chrome_rspec:
|
25
|
+
name: RSpec on Windows / Chrome
|
26
|
+
runs-on: windows-latest
|
27
|
+
steps:
|
28
|
+
- name: Check out code
|
29
|
+
uses: actions/checkout@v2
|
30
|
+
- uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: 3.0.0
|
33
|
+
- name: Install dependencies
|
34
|
+
run: |
|
35
|
+
gem uninstall bundler
|
36
|
+
gem install bundler -v 2.2.3
|
37
|
+
bundle install
|
38
|
+
- uses: browser-actions/setup-chrome@latest
|
39
|
+
- name: Check example
|
40
|
+
run: bundle exec rspec spec/integration/example_spec.rb
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.
|
1
|
+
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.31.0...master)]
|
2
2
|
|
3
3
|
* xxx
|
4
4
|
|
5
|
+
### 0.31.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.30.0...0.31.0)]
|
6
|
+
|
7
|
+
New features:
|
8
|
+
|
9
|
+
* Now puppeteer-ruby is compatible with Windows
|
10
|
+
|
11
|
+
Bugfix:
|
12
|
+
|
13
|
+
* Fix `Page#add_script_tag` and `Page#add_style_tag` to work
|
14
|
+
|
5
15
|
### 0.30.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.29.0...0.30.0)]
|
6
16
|
|
7
17
|
New features:
|
data/lib/puppeteer/dom_world.rb
CHANGED
@@ -230,144 +230,127 @@ class Puppeteer::DOMWorld
|
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
|
-
#
|
234
|
-
#
|
235
|
-
#
|
236
|
-
#
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
# throw new Error(`Loading script from ${url} failed`);
|
250
|
-
# }
|
251
|
-
# }
|
252
|
-
|
253
|
-
# if (path !== null) {
|
254
|
-
# let contents = await readFileAsync(path, 'utf8');
|
255
|
-
# contents += '//# sourceURL=' + path.replace(/\n/g, '');
|
256
|
-
# const context = await this.executionContext();
|
257
|
-
# return (await context.evaluateHandle(addScriptContent, contents, type)).asElement();
|
258
|
-
# }
|
259
|
-
|
260
|
-
# if (content !== null) {
|
261
|
-
# const context = await this.executionContext();
|
262
|
-
# return (await context.evaluateHandle(addScriptContent, content, type)).asElement();
|
263
|
-
# }
|
264
|
-
|
265
|
-
# throw new Error('Provide an object with a `url`, `path` or `content` property');
|
266
|
-
|
267
|
-
# /**
|
268
|
-
# * @param {string} url
|
269
|
-
# * @param {string} type
|
270
|
-
# * @return {!Promise<!HTMLElement>}
|
271
|
-
# */
|
272
|
-
# async function addScriptUrl(url, type) {
|
273
|
-
# const script = document.createElement('script');
|
274
|
-
# script.src = url;
|
275
|
-
# if (type)
|
276
|
-
# script.type = type;
|
277
|
-
# const promise = new Promise((res, rej) => {
|
278
|
-
# script.onload = res;
|
279
|
-
# script.onerror = rej;
|
280
|
-
# });
|
281
|
-
# document.head.appendChild(script);
|
282
|
-
# await promise;
|
283
|
-
# return script;
|
284
|
-
# }
|
285
|
-
|
286
|
-
# /**
|
287
|
-
# * @param {string} content
|
288
|
-
# * @param {string} type
|
289
|
-
# * @return {!HTMLElement}
|
290
|
-
# */
|
291
|
-
# function addScriptContent(content, type = 'text/javascript') {
|
292
|
-
# const script = document.createElement('script');
|
293
|
-
# script.type = type;
|
294
|
-
# script.text = content;
|
295
|
-
# let error = null;
|
296
|
-
# script.onerror = e => error = e;
|
297
|
-
# document.head.appendChild(script);
|
298
|
-
# if (error)
|
299
|
-
# throw error;
|
300
|
-
# return script;
|
301
|
-
# }
|
302
|
-
# }
|
233
|
+
# @param url [String?]
|
234
|
+
# @param path [String?]
|
235
|
+
# @param content [String?]
|
236
|
+
# @param type [String?]
|
237
|
+
def add_script_tag(url: nil, path: nil, content: nil, type: nil)
|
238
|
+
if url
|
239
|
+
begin
|
240
|
+
return execution_context.
|
241
|
+
evaluate_handle(ADD_SCRIPT_URL, url, type || '').
|
242
|
+
as_element
|
243
|
+
rescue Puppeteer::ExecutionContext::EvaluationError # for Chrome
|
244
|
+
raise "Loading script from #{url} failed"
|
245
|
+
rescue Puppeteer::Connection::ProtocolError # for Firefox
|
246
|
+
raise "Loading script from #{url} failed"
|
247
|
+
end
|
248
|
+
end
|
303
249
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
#
|
353
|
-
|
354
|
-
#
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
250
|
+
if path
|
251
|
+
contents = File.read(path)
|
252
|
+
contents += "//# sourceURL=#{path.gsub(/\n/, '')}"
|
253
|
+
return execution_context.
|
254
|
+
evaluate_handle(ADD_SCRIPT_CONTENT, contents, type || '').
|
255
|
+
as_element
|
256
|
+
end
|
257
|
+
|
258
|
+
if content
|
259
|
+
return execution_context.
|
260
|
+
evaluate_handle(ADD_SCRIPT_CONTENT, content, type || '').
|
261
|
+
as_element
|
262
|
+
end
|
263
|
+
|
264
|
+
raise ArgumentError.new('Provide an object with a `url`, `path` or `content` property')
|
265
|
+
end
|
266
|
+
|
267
|
+
ADD_SCRIPT_URL = <<~JAVASCRIPT
|
268
|
+
async (url, type) => {
|
269
|
+
const script = document.createElement('script');
|
270
|
+
script.src = url;
|
271
|
+
if (type)
|
272
|
+
script.type = type;
|
273
|
+
const promise = new Promise((res, rej) => {
|
274
|
+
script.onload = res;
|
275
|
+
script.onerror = rej;
|
276
|
+
});
|
277
|
+
document.head.appendChild(script);
|
278
|
+
await promise;
|
279
|
+
return script;
|
280
|
+
}
|
281
|
+
JAVASCRIPT
|
282
|
+
|
283
|
+
ADD_SCRIPT_CONTENT = <<~JAVASCRIPT
|
284
|
+
(content, type) => {
|
285
|
+
if (type === undefined) type = 'text/javascript';
|
286
|
+
const script = document.createElement('script');
|
287
|
+
script.type = type;
|
288
|
+
script.text = content;
|
289
|
+
let error = null;
|
290
|
+
script.onerror = e => error = e;
|
291
|
+
document.head.appendChild(script);
|
292
|
+
if (error)
|
293
|
+
throw error;
|
294
|
+
return script;
|
295
|
+
}
|
296
|
+
JAVASCRIPT
|
297
|
+
|
298
|
+
# @param url [String?]
|
299
|
+
# @param path [String?]
|
300
|
+
# @param content [String?]
|
301
|
+
def add_style_tag(url: nil, path: nil, content: nil)
|
302
|
+
if url
|
303
|
+
begin
|
304
|
+
return execution_context.evaluate_handle(ADD_STYLE_URL, url).as_element
|
305
|
+
rescue Puppeteer::ExecutionContext::EvaluationError # for Chrome
|
306
|
+
raise "Loading style from #{url} failed"
|
307
|
+
rescue Puppeteer::Connection::ProtocolError # for Firefox
|
308
|
+
raise "Loading style from #{url} failed"
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
if path
|
313
|
+
contents = File.read(path)
|
314
|
+
contents += "/*# sourceURL=#{path.gsub(/\n/, '')}*/"
|
315
|
+
return execution_context.evaluate_handle(ADD_STYLE_CONTENT, contents).as_element
|
316
|
+
end
|
317
|
+
|
318
|
+
if content
|
319
|
+
return execution_context.evaluate_handle(ADD_STYLE_CONTENT, content).as_element
|
320
|
+
end
|
321
|
+
|
322
|
+
raise ArgumentError.new('Provide an object with a `url`, `path` or `content` property')
|
323
|
+
end
|
324
|
+
|
325
|
+
ADD_STYLE_URL = <<~JAVASCRIPT
|
326
|
+
async (url) => {
|
327
|
+
const link = document.createElement('link');
|
328
|
+
link.rel = 'stylesheet';
|
329
|
+
link.href = url;
|
330
|
+
const promise = new Promise((res, rej) => {
|
331
|
+
link.onload = res;
|
332
|
+
link.onerror = rej;
|
333
|
+
});
|
334
|
+
document.head.appendChild(link);
|
335
|
+
await promise;
|
336
|
+
return link;
|
337
|
+
}
|
338
|
+
JAVASCRIPT
|
339
|
+
|
340
|
+
ADD_STYLE_CONTENT = <<~JAVASCRIPT
|
341
|
+
async (content) => {
|
342
|
+
const style = document.createElement('style');
|
343
|
+
style.type = 'text/css';
|
344
|
+
style.appendChild(document.createTextNode(content));
|
345
|
+
const promise = new Promise((res, rej) => {
|
346
|
+
style.onload = res;
|
347
|
+
style.onerror = rej;
|
348
|
+
});
|
349
|
+
document.head.appendChild(style);
|
350
|
+
await promise;
|
351
|
+
return style;
|
352
|
+
}
|
353
|
+
JAVASCRIPT
|
371
354
|
|
372
355
|
class ElementNotFoundError < StandardError
|
373
356
|
def initialize(selector)
|
data/lib/puppeteer/env.rb
CHANGED
data/lib/puppeteer/frame.rb
CHANGED
@@ -153,16 +153,19 @@ class Puppeteer::Frame
|
|
153
153
|
@detached
|
154
154
|
end
|
155
155
|
|
156
|
-
# @param
|
157
|
-
# @
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
156
|
+
# @param url [String?]
|
157
|
+
# @param path [String?]
|
158
|
+
# @param content [String?]
|
159
|
+
# @param type [String?]
|
160
|
+
def add_script_tag(url: nil, path: nil, content: nil, type: nil)
|
161
|
+
@main_world.add_script_tag(url: url, path: path, content: content, type: type)
|
162
|
+
end
|
163
|
+
|
164
|
+
# @param url [String?]
|
165
|
+
# @param path [String?]
|
166
|
+
# @param content [String?]
|
167
|
+
def add_style_tag(url: nil, path: nil, content: nil)
|
168
|
+
@main_world.add_style_tag(url: url, path: path, content: content)
|
166
169
|
end
|
167
170
|
|
168
171
|
# @param selector [String]
|
@@ -32,6 +32,14 @@ module Puppeteer::Launcher
|
|
32
32
|
when Firefox
|
33
33
|
'/Applications/Firefox Nightly.app/Contents/MacOS/firefox'
|
34
34
|
end
|
35
|
+
elsif Puppeteer.env.windows?
|
36
|
+
case self
|
37
|
+
when Chrome
|
38
|
+
'C:\Program Files\Google\Chrome\Application\chrome.exe'
|
39
|
+
# 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
|
40
|
+
when Firefox
|
41
|
+
'C:\Program Files\Firefox Nightly\firefox.exe'
|
42
|
+
end
|
35
43
|
else
|
36
44
|
case self
|
37
45
|
when Chrome
|
data/lib/puppeteer/page.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'base64'
|
2
|
+
require 'json'
|
2
3
|
require "stringio"
|
3
4
|
|
4
5
|
require_relative './page/pdf_options'
|
@@ -98,7 +99,9 @@ class Puppeteer::Page
|
|
98
99
|
@client.on_event('Page.loadEventFired') do |event|
|
99
100
|
emit_event(PageEmittedEvents::Load)
|
100
101
|
end
|
101
|
-
|
102
|
+
@client.on('Runtime.consoleAPICalled') do |event|
|
103
|
+
handle_console_api(event)
|
104
|
+
end
|
102
105
|
# client.on('Runtime.bindingCalled', event => this._onBindingCalled(event));
|
103
106
|
@client.on_event('Page.javascriptDialogOpening') do |event|
|
104
107
|
handle_dialog_opening(event)
|
@@ -373,37 +376,19 @@ class Puppeteer::Page
|
|
373
376
|
end
|
374
377
|
end
|
375
378
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
@url = url
|
383
|
-
end
|
384
|
-
attr_reader :content, :path, :type, :url
|
385
|
-
end
|
386
|
-
|
387
|
-
# @param style_tag [Puppeteer::Page::ScriptTag]
|
388
|
-
# @return {!Promise<!ElementHandle>}
|
389
|
-
def add_script_tag(script_tag)
|
390
|
-
main_frame.add_script_tag(script_tag)
|
391
|
-
end
|
392
|
-
|
393
|
-
class StyleTag
|
394
|
-
# @param {!{content?: string, path?: string, url?: string}} options
|
395
|
-
def initialize(content: nil, path: nil, url: nil)
|
396
|
-
@content = content
|
397
|
-
@path = path
|
398
|
-
@url = url
|
399
|
-
end
|
400
|
-
attr_reader :content, :path, :url
|
379
|
+
# @param url [String?]
|
380
|
+
# @param path [String?]
|
381
|
+
# @param content [String?]
|
382
|
+
# @param type [String?]
|
383
|
+
def add_script_tag(url: nil, path: nil, content: nil, type: nil)
|
384
|
+
main_frame.add_script_tag(url: url, path: path, content: content, type: type)
|
401
385
|
end
|
402
386
|
|
403
|
-
# @param
|
404
|
-
# @
|
405
|
-
|
406
|
-
|
387
|
+
# @param url [String?]
|
388
|
+
# @param path [String?]
|
389
|
+
# @param content [String?]
|
390
|
+
def add_style_tag(url: nil, path: nil, content: nil)
|
391
|
+
main_frame.add_style_tag(url: url, path: path, content: content)
|
407
392
|
end
|
408
393
|
|
409
394
|
# /**
|
@@ -494,30 +479,31 @@ class Puppeteer::Page
|
|
494
479
|
emit_event(PageEmittedEvents::PageError, err)
|
495
480
|
end
|
496
481
|
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
482
|
+
private def handle_console_api(event)
|
483
|
+
if event['executionContextId'] == 0
|
484
|
+
# DevTools protocol stores the last 1000 console messages. These
|
485
|
+
# messages are always reported even for removed execution contexts. In
|
486
|
+
# this case, they are marked with executionContextId = 0 and are
|
487
|
+
# reported upon enabling Runtime agent.
|
488
|
+
#
|
489
|
+
# Ignore these messages since:
|
490
|
+
# - there's no execution context we can use to operate with message
|
491
|
+
# arguments
|
492
|
+
# - these messages are reported before Puppeteer clients can subscribe
|
493
|
+
# to the 'console'
|
494
|
+
# page event.
|
495
|
+
#
|
496
|
+
# @see https://github.com/puppeteer/puppeteer/issues/3865
|
497
|
+
return
|
498
|
+
end
|
499
|
+
|
500
|
+
context = @frame_manager.execution_context_by_id(event['executionContextId'])
|
501
|
+
values = event['args'].map do |arg|
|
502
|
+
remote_object = Puppeteer::RemoteObject.new(arg)
|
503
|
+
Puppeteer::JSHandle.create(context: context, remote_object: remote_object)
|
504
|
+
end
|
505
|
+
add_console_message(event['type'], values, event['stackTrace'])
|
506
|
+
end
|
521
507
|
|
522
508
|
# /**
|
523
509
|
# * @param {!Protocol.Runtime.bindingCalledPayload} event
|
@@ -570,32 +556,23 @@ class Puppeteer::Page
|
|
570
556
|
# }
|
571
557
|
# }
|
572
558
|
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
# }
|
591
|
-
# const location = stackTrace && stackTrace.callFrames.length ? {
|
592
|
-
# url: stackTrace.callFrames[0].url,
|
593
|
-
# lineNumber: stackTrace.callFrames[0].lineNumber,
|
594
|
-
# columnNumber: stackTrace.callFrames[0].columnNumber,
|
595
|
-
# } : {};
|
596
|
-
# const message = new ConsoleMessage(type, textTokens.join(' '), args, location);
|
597
|
-
# this.emit(PageEmittedEvents::Console, message);
|
598
|
-
# }
|
559
|
+
private def add_console_message(type, args, stack_trace)
|
560
|
+
text_tokens = args.map { |arg| arg.remote_object.value }
|
561
|
+
|
562
|
+
call_frame = stack_trace['callFrames']&.first
|
563
|
+
location =
|
564
|
+
if call_frame
|
565
|
+
Puppeteer::ConsoleMessage::Location.new(
|
566
|
+
url: call_frame['url'],
|
567
|
+
line_number: call_frame['lineNumber'],
|
568
|
+
column_number: call_frame['columnNumber'],
|
569
|
+
)
|
570
|
+
else
|
571
|
+
nil
|
572
|
+
end
|
573
|
+
console_message = Puppeteer::ConsoleMessage.new(type, text_tokens.join(' '), args, location)
|
574
|
+
emit_event(PageEmittedEvents::Console, console_message)
|
575
|
+
end
|
599
576
|
|
600
577
|
private def handle_dialog_opening(event)
|
601
578
|
dialog_type = event['type']
|
@@ -866,14 +843,41 @@ class Puppeteer::Page
|
|
866
843
|
|
867
844
|
define_async_method :async_evaluate
|
868
845
|
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
846
|
+
class JavaScriptFunction
|
847
|
+
def initialize(expression, args)
|
848
|
+
@expression = expression
|
849
|
+
@args = args
|
850
|
+
end
|
851
|
+
|
852
|
+
def source
|
853
|
+
"(#{@expression})(#{arguments})"
|
854
|
+
end
|
855
|
+
|
856
|
+
private def arguments
|
857
|
+
@args.map { |arg| arg.nil? ? nil : JSON.dump(arg) }.join(", ")
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
class JavaScriptExpression
|
862
|
+
def initialize(expression)
|
863
|
+
@expression = expression
|
864
|
+
end
|
865
|
+
|
866
|
+
def source
|
867
|
+
@expression
|
868
|
+
end
|
869
|
+
end
|
870
|
+
|
871
|
+
def evaluate_on_new_document(page_function, *args)
|
872
|
+
source =
|
873
|
+
if ['=>', 'async', 'function'].any? { |keyword| page_function.include?(keyword) }
|
874
|
+
JavaScriptFunction.new(page_function, args).source
|
875
|
+
else
|
876
|
+
JavaScriptExpression.new(page_function).source
|
877
|
+
end
|
878
|
+
|
879
|
+
@client.send_message('Page.addScriptToEvaluateOnNewDocument', source: source)
|
880
|
+
end
|
877
881
|
|
878
882
|
# @param {boolean} enabled
|
879
883
|
def cache_enabled=(enabled)
|
data/lib/puppeteer/version.rb
CHANGED
data/lib/puppeteer/web_socket.rb
CHANGED
data/puppeteer-ruby.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'rake', '~> 13.0.3'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.10.0 '
|
29
29
|
spec.add_development_dependency 'rspec_junit_formatter' # for CircleCI.
|
30
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
30
|
+
spec.add_development_dependency 'rubocop', '~> 1.11.0'
|
31
31
|
spec.add_development_dependency 'rubocop-rspec'
|
32
32
|
spec.add_development_dependency 'sinatra'
|
33
33
|
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.31.0
|
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-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
145
|
+
version: 1.11.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
152
|
+
version: 1.11.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rubocop-rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- ".github/stale.yml"
|
220
220
|
- ".github/workflows/docs.yml"
|
221
221
|
- ".github/workflows/reviewdog.yml"
|
222
|
+
- ".github/workflows/windows_check.yml"
|
222
223
|
- ".gitignore"
|
223
224
|
- ".rspec"
|
224
225
|
- ".rubocop.yml"
|