7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ferrum/browser/api/screenshot.rb', line 7
def screenshot(**opts)
encoding, path, options = screenshot_options(**opts)
data = if options[:format].to_s == "pdf"
options = {}
options[:paperWidth] = @paper_size[:width].to_f if @paper_size
options[:paperHeight] = @paper_size[:height].to_f if @paper_size
options[:scale] = @zoom_factor if @zoom_factor
page.command("Page.printToPDF", **options)
else
page.command("Page.captureScreenshot", **options)
end.fetch("data")
return data if encoding == :base64
bin = Base64.decode64(data)
File.open(path.to_s, "wb") { |f| f.write(bin) }
end
|