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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1b2bb89d30c93e2f942e9e14b72952f7fbbdcb027c564a9477d920316032d83
4
- data.tar.gz: 716ee3c3cc6d7a7d1086d9dc34b97c879996dfcc18e88744a9a70e8d2292b842
3
+ metadata.gz: 0d7c0b6410629e9119a7f298cc3cecdd6e5640a18fdb944dc53e1b47b4c940b0
4
+ data.tar.gz: 4f9bf8f3e4a21a22cb89fcff1927e420bff86cbdec4a3084dbec32669530f03e
5
5
  SHA512:
6
- metadata.gz: 952bc67ff27947ac127c43316476a9e690f6dfc0cdfaa6dabb5030ddca782f178bb0e9c71c156c6a707979d1322a4d0f24eacf0015e2b92db77d4da31e1ecc7c
7
- data.tar.gz: 58775749a3ef44e2e2ab27fd90fee93ae74b2fa7ecec087bdb8df4bc5ede5e4199f07dd9cff587fd968ea509b03962c43b35e7711307f7b163f59ffceb3b7a07
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.10.0
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
@@ -17,3 +17,5 @@
17
17
  # RubyMine
18
18
  /.idea/
19
19
  /.rakeTasks
20
+
21
+ diff-*.png
data/CHANGELOG.md CHANGED
@@ -1,7 +1,17 @@
1
- ### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.30.0...master)]
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:
@@ -111,7 +111,7 @@ class Puppeteer::BrowserRunner
111
111
  end
112
112
  end
113
113
 
114
- if @launch_options.handle_SIGHUP?
114
+ if @launch_options.handle_SIGHUP? && !Puppeteer.env.windows?
115
115
  trap(:HUP) do
116
116
  close
117
117
  end
@@ -230,144 +230,127 @@ class Puppeteer::DOMWorld
230
230
  end
231
231
  end
232
232
 
233
- # /**
234
- # * @param {!{url?: string, path?: string, content?: string, type?: string}} options
235
- # * @return {!Promise<!Puppeteer.ElementHandle>}
236
- # */
237
- # async addScriptTag(options) {
238
- # const {
239
- # url = null,
240
- # path = null,
241
- # content = null,
242
- # type = ''
243
- # } = options;
244
- # if (url !== null) {
245
- # try {
246
- # const context = await this.executionContext();
247
- # return (await context.evaluateHandle(addScriptUrl, url, type)).asElement();
248
- # } catch (error) {
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
- # * @param {!{url?: string, path?: string, content?: string}} options
306
- # * @return {!Promise<!Puppeteer.ElementHandle>}
307
- # */
308
- # async addStyleTag(options) {
309
- # const {
310
- # url = null,
311
- # path = null,
312
- # content = null
313
- # } = options;
314
- # if (url !== null) {
315
- # try {
316
- # const context = await this.executionContext();
317
- # return (await context.evaluateHandle(addStyleUrl, url)).asElement();
318
- # } catch (error) {
319
- # throw new Error(`Loading style from ${url} failed`);
320
- # }
321
- # }
322
-
323
- # if (path !== null) {
324
- # let contents = await readFileAsync(path, 'utf8');
325
- # contents += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
326
- # const context = await this.executionContext();
327
- # return (await context.evaluateHandle(addStyleContent, contents)).asElement();
328
- # }
329
-
330
- # if (content !== null) {
331
- # const context = await this.executionContext();
332
- # return (await context.evaluateHandle(addStyleContent, content)).asElement();
333
- # }
334
-
335
- # throw new Error('Provide an object with a `url`, `path` or `content` property');
336
-
337
- # /**
338
- # * @param {string} url
339
- # * @return {!Promise<!HTMLElement>}
340
- # */
341
- # async function addStyleUrl(url) {
342
- # const link = document.createElement('link');
343
- # link.rel = 'stylesheet';
344
- # link.href = url;
345
- # const promise = new Promise((res, rej) => {
346
- # link.onload = res;
347
- # link.onerror = rej;
348
- # });
349
- # document.head.appendChild(link);
350
- # await promise;
351
- # return link;
352
- # }
353
-
354
- # /**
355
- # * @param {string} content
356
- # * @return {!Promise<!HTMLElement>}
357
- # */
358
- # async function addStyleContent(content) {
359
- # const style = document.createElement('style');
360
- # style.type = 'text/css';
361
- # style.appendChild(document.createTextNode(content));
362
- # const promise = new Promise((res, rej) => {
363
- # style.onload = res;
364
- # style.onerror = rej;
365
- # });
366
- # document.head.appendChild(style);
367
- # await promise;
368
- # return style;
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
@@ -14,6 +14,10 @@ class Puppeteer::Env
14
14
  def darwin?
15
15
  RUBY_PLATFORM.include?('darwin')
16
16
  end
17
+
18
+ def windows?
19
+ RUBY_PLATFORM =~ /mswin|mingw|cygwin/
20
+ end
17
21
  end
18
22
 
19
23
  class Puppeteer
@@ -153,16 +153,19 @@ class Puppeteer::Frame
153
153
  @detached
154
154
  end
155
155
 
156
- # @param style_tag [Puppeteer::Page::ScriptTag]
157
- # @return {!Promise<!ElementHandle>}
158
- def add_script_tag(script_tag)
159
- @main_world.add_script_tag(script_tag)
160
- end
161
-
162
- # @param style_tag [Puppeteer::Page::StyleTag]
163
- # @return {!Promise<!ElementHandle>}
164
- def add_style_tag(style_tag)
165
- @main_world.add_style_tag(style_tag)
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
@@ -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
- # client.on('Runtime.consoleAPICalled', event => this._onConsoleAPI(event));
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
- class ScriptTag
377
- # @param {!{content?: string, path?: string, type?: string, url?: string}} options
378
- def initialize(content: nil, path: nil, type: nil, url: nil)
379
- @content = content
380
- @path = path
381
- @type = type
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 style_tag [Puppeteer::Page::StyleTag]
404
- # @return {!Promise<!ElementHandle>}
405
- def add_style_tag(style_tag)
406
- main_frame.add_style_tag(style_tag)
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
- # * @param {!Protocol.Runtime.consoleAPICalledPayload} event
499
- # */
500
- # async _onConsoleAPI(event) {
501
- # if (event.executionContextId === 0) {
502
- # // DevTools protocol stores the last 1000 console messages. These
503
- # // messages are always reported even for removed execution contexts. In
504
- # // this case, they are marked with executionContextId = 0 and are
505
- # // reported upon enabling Runtime agent.
506
- # //
507
- # // Ignore these messages since:
508
- # // - there's no execution context we can use to operate with message
509
- # // arguments
510
- # // - these messages are reported before Puppeteer clients can subscribe
511
- # // to the 'console'
512
- # // page event.
513
- # //
514
- # // @see https://github.com/puppeteer/puppeteer/issues/3865
515
- # return;
516
- # }
517
- # const context = this._frameManager.executionContextById(event.executionContextId);
518
- # const values = event.args.map(arg => createJSHandle(context, arg));
519
- # this._addConsoleMessage(event.type, values, event.stackTrace);
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
- # * @param {string} type
575
- # * @param {!Array<!Puppeteer.JSHandle>} args
576
- # * @param {Protocol.Runtime.StackTrace=} stackTrace
577
- # */
578
- # _addConsoleMessage(type, args, stackTrace) {
579
- # if (!this.listenerCount(PageEmittedEvents::Console)) {
580
- # args.forEach(arg => arg.dispose());
581
- # return;
582
- # }
583
- # const textTokens = [];
584
- # for (const arg of args) {
585
- # const remoteObject = arg._remoteObject;
586
- # if (remoteObject.objectId)
587
- # textTokens.push(arg.toString());
588
- # else
589
- # textTokens.push(helper.valueFromRemoteObject(remoteObject));
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
- # * @param {Function|string} pageFunction
871
- # * @param {!Array<*>} args
872
- # */
873
- # async evaluateOnNewDocument(pageFunction, ...args) {
874
- # const source = helper.evaluationString(pageFunction, ...args);
875
- # await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source });
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)
@@ -1,3 +1,3 @@
1
1
  class Puppeteer
2
- VERSION = '0.30.0'
2
+ VERSION = '0.31.0'
3
3
  end
@@ -18,6 +18,8 @@ class Puppeteer::WebSocket
18
18
  @socket.write(data)
19
19
  rescue Errno::EPIPE
20
20
  raise EOFError.new('already closed')
21
+ rescue Errno::ECONNRESET
22
+ raise EOFError.new('closed by remote')
21
23
  end
22
24
 
23
25
  def readpartial(maxlen = 1024)
@@ -37,6 +37,8 @@ class Puppeteer::WebSocketTransport
37
37
 
38
38
  def close
39
39
  @ws.close
40
+ rescue EOFError
41
+ # ignore EOLError. The connection is already closed.
40
42
  end
41
43
 
42
44
  def on_close(&block)
@@ -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.10.0'
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.30.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-02-24 00:00:00.000000000 Z
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.10.0
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.10.0
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"