puppeteer-ruby 0.34.0 → 0.34.1
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/CHANGELOG.md +7 -1
- data/docs/api_coverage.md +1 -1
- data/lib/puppeteer/page.rb +29 -3
- data/lib/puppeteer/page/pdf_options.rb +0 -10
- data/lib/puppeteer/protocol_stream_reader.rb +5 -16
- data/lib/puppeteer/tracing.rb +18 -1
- data/lib/puppeteer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 759579a77012a03fa74915957ff0c3ed656ea4cdcc280b2f24fede885d01f361
|
4
|
+
data.tar.gz: 390f5ef626fb791dc9744cfe59a977fcd3a9d45c16d32aec60247a652ef73712
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa0d6262ed3953a9b15efc2fdad2be48cd6b22cba0f1b89d7c93b0b9cbd52413705f60fe334cbb57b5f6eabffbb599b98db520859bd1239406def453ca314228
|
7
|
+
data.tar.gz: 84632098cf49cf5201528e2ac620321b83210bfb4f0a5bd6fae48a86fb5009a8c4e791b666eaf82b110eb4fc55a569723266e850381fe1b7dda49bd9830422d2
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
-
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.
|
1
|
+
### master [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.1...master)]
|
2
2
|
|
3
3
|
* xxx
|
4
4
|
|
5
|
+
### 0.34.1 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.34.0...0.34.1)]
|
6
|
+
|
7
|
+
Bugfix:
|
8
|
+
|
9
|
+
* Fix `Page#pdf` to work without `path` parameter.
|
10
|
+
|
5
11
|
### 0.34.0 [[diff](https://github.com/YusukeIwaki/puppeteer-ruby/compare/0.33.0...0.34.0)]
|
6
12
|
|
7
13
|
New features:
|
data/docs/api_coverage.md
CHANGED
data/lib/puppeteer/page.rb
CHANGED
@@ -1008,14 +1008,40 @@ class Puppeteer::Page
|
|
1008
1008
|
end
|
1009
1009
|
end
|
1010
1010
|
|
1011
|
-
# @return [String]
|
1012
|
-
def
|
1011
|
+
# @return [Enumerable<String>]
|
1012
|
+
def create_pdf_stream(options = {})
|
1013
1013
|
pdf_options = PDFOptions.new(options)
|
1014
1014
|
omit_background = options[:omit_background]
|
1015
1015
|
set_transparent_background_color if omit_background
|
1016
1016
|
result = @client.send_message('Page.printToPDF', pdf_options.page_print_args)
|
1017
1017
|
reset_default_background_color if omit_background
|
1018
|
-
|
1018
|
+
|
1019
|
+
Puppeteer::ProtocolStreamReader.new(
|
1020
|
+
client: @client,
|
1021
|
+
handle: result['stream'],
|
1022
|
+
).read_as_chunks
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
# @return [String]
|
1026
|
+
def pdf(options = {})
|
1027
|
+
chunks = create_pdf_stream(options)
|
1028
|
+
|
1029
|
+
StringIO.open do |stringio|
|
1030
|
+
if options[:path]
|
1031
|
+
File.open(options[:path], 'wb') do |f|
|
1032
|
+
chunks.each do |chunk|
|
1033
|
+
f.write(chunk)
|
1034
|
+
stringio.write(chunk)
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
else
|
1038
|
+
chunks.each do |chunk|
|
1039
|
+
stringio.write(chunk)
|
1040
|
+
end
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
stringio.string
|
1044
|
+
end
|
1019
1045
|
rescue => err
|
1020
1046
|
if err.message.include?('PrintToPDF is not implemented')
|
1021
1047
|
raise PrintToPdfIsNotImplementedError.new
|
@@ -15,17 +15,10 @@ class Puppeteer::Page
|
|
15
15
|
# * @property {string|number=} height
|
16
16
|
# * @property {boolean=} preferCSSPageSize
|
17
17
|
# * @property {!{top?: string|number, bottom?: string|number, left?: string|number, right?: string|number}=} margin
|
18
|
-
# * @property {string=} path
|
19
18
|
# */
|
20
19
|
class PDFOptions
|
21
20
|
# @params options [Hash]
|
22
21
|
def initialize(options)
|
23
|
-
unless options[:path]
|
24
|
-
# Original puppeteer allows path = nil, however nothing to do without path actually.
|
25
|
-
# Also in most case, users forget to specify path parameter. So let's raise ArgumentError.
|
26
|
-
raise ArgumentError('"path" parameter must be specified.')
|
27
|
-
end
|
28
|
-
|
29
22
|
@scale = options[:scale]
|
30
23
|
@display_header_footer = options[:display_header_footer]
|
31
24
|
@header_template = options[:header_template]
|
@@ -38,11 +31,8 @@ class Puppeteer::Page
|
|
38
31
|
@height = options[:height]
|
39
32
|
@prefer_css_page_size = options[:prefer_css_page_size]
|
40
33
|
@margin = Margin.new(options[:margin] || {})
|
41
|
-
@path = options[:path]
|
42
34
|
end
|
43
35
|
|
44
|
-
attr_reader :path
|
45
|
-
|
46
36
|
class PaperSize
|
47
37
|
def initialize(width:, height:)
|
48
38
|
@width = width
|
@@ -1,25 +1,14 @@
|
|
1
1
|
class Puppeteer::ProtocolStreamReader
|
2
|
-
def initialize(client:, handle
|
2
|
+
def initialize(client:, handle:)
|
3
3
|
@client = client
|
4
4
|
@handle = handle
|
5
|
-
@path = path
|
6
5
|
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
io_read do |data|
|
13
|
-
out.write(data)
|
14
|
-
file.write(data)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
else
|
18
|
-
io_read { |data| out.write(data) }
|
19
|
-
end
|
7
|
+
# @returns [Enumerable<String>]
|
8
|
+
def read_as_chunks
|
9
|
+
Enumerator.new do |out|
|
10
|
+
io_read { |data| out << data }
|
20
11
|
io_close
|
21
|
-
|
22
|
-
out.string
|
23
12
|
end
|
24
13
|
end
|
25
14
|
|
data/lib/puppeteer/tracing.rb
CHANGED
@@ -45,6 +45,23 @@ class Puppeteer::Tracing
|
|
45
45
|
@recording = false
|
46
46
|
|
47
47
|
stream = await stream_promise
|
48
|
-
Puppeteer::ProtocolStreamReader.new(client: @client, handle: stream
|
48
|
+
chunks = Puppeteer::ProtocolStreamReader.new(client: @client, handle: stream).read_as_chunks
|
49
|
+
|
50
|
+
StringIO.open do |stringio|
|
51
|
+
if @path
|
52
|
+
File.open(@path, 'wb') do |f|
|
53
|
+
chunks.each do |chunk|
|
54
|
+
f.write(chunk)
|
55
|
+
stringio.write(chunk)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
else
|
59
|
+
chunks.each do |chunk|
|
60
|
+
stringio.write(chunk)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
stringio.string
|
65
|
+
end
|
49
66
|
end
|
50
67
|
end
|
data/lib/puppeteer/version.rb
CHANGED
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.34.
|
4
|
+
version: 0.34.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|