Screenshots
screenshot(**options) : String | Integer
Saves screenshot on a disk or returns it as base64.
- options
Hash- :path
Stringto save a screenshot on the disk.:encodingwill be set to:binaryautomatically - :encoding
Symbol:base64|:binaryyou can set it to return image as Base64 - :format
String"jpeg" ("jpg") | "png" | "webp" - :quality
Integer0-100 works for jpeg only - :full
Booleanwhether you need full page screenshot or a viewport - :selector
Stringcss selector for given element, optional - :area
Hasharea for screenshot, optional- :x
Integer - :y
Integer - :width
Integer - :height
Integer
- :x
- :scale
Floatzoom in/out - :background_color
Ferrum::RGBA.new(0, 0, 0, 0.0)to have specific background color
- :path
page.go_to("https://google.com/")
# Save on the disk in PNG
page.screenshot(path: "google.png") # => 134660
# Save on the disk in JPG
page.screenshot(path: "google.jpg") # => 30902
# Save to Base64 the whole page not only viewport and reduce quality
page.screenshot(full: true, quality: 60, encoding: :base64) # "iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAYAAAC6uhUNAAAAAXNSR0IArs4c6Q...
# Save on the disk with the selected element in PNG
page.screenshot(path: "google.png", selector: "textarea") # => 11340
# Save to Base64 with an area of the page in PNG
page.screenshot(path: "google.png", area: { x: 0, y: 0, width: 400, height: 300 }) # => 54239
# Save with specific background color
page.screenshot(background_color: Ferrum::RGBA.new(0, 0, 0, 0.0))
pdf(**options) : String | Boolean
Saves PDF on a disk or returns it as base64.
- options
Hash-
:path
Stringto save a pdf on the disk.:encodingwill be set to:binaryautomatically -
:encoding
Symbol:base64|:binaryyou can set it to return pdf as Base64 -
:landscape
Booleanpaper orientation. Defaults to false. -
:scale
Floatzoom in/out -
:format
symbolstandard paper sizes :letter, :legal, :tabloid, :ledger, :A0, :A1, :A2, :A3, :A4, :A5, :A6 -
:paper_width
Floatset paper width -
:paper_height
Floatset paper height -
See other native options you can pass
-
page.go_to("https://google.com/")
# Save to disk as a PDF
page.pdf(path: "google.pdf", paper_width: 1.0, paper_height: 1.0) # => true
mhtml(**options) : String | Integer
Saves MHTML on a disk or returns it as a string.
- options
Hash- :path
Stringto save a file on the disk.
- :path
page.go_to("https://google.com/")
page.mhtml(path: "google.mhtml") # => 87742