Module: Ferrum::Page::Screenshot

Included in:
Ferrum::Page
Defined in:
lib/ferrum/page/screenshot.rb

Instance Method Summary collapse

Instance Method Details

#document_sizeObject



28
29
30
31
32
33
# File 'lib/ferrum/page/screenshot.rb', line 28

def document_size
  evaluate <<~JS
    [document.documentElement.offsetWidth,
     document.documentElement.offsetHeight]
  JS
end

#pdf(**opts) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ferrum/page/screenshot.rb', line 14

def pdf(**opts)
  path, encoding = common_options(**opts)
  options = pdf_options(**opts)
  data = command("Page.printToPDF", **options).fetch("data")
  return data if encoding == :base64
  save_file(path, data)
end

#screenshot(**opts) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ferrum/page/screenshot.rb', line 6

def screenshot(**opts)
  path, encoding = common_options(**opts)
  options = screenshot_options(path, **opts)
  data = command("Page.captureScreenshot", **options).fetch("data")
  return data if encoding == :base64
  save_file(path, data)
end

#viewport_sizeObject



22
23
24
25
26
# File 'lib/ferrum/page/screenshot.rb', line 22

def viewport_size
  evaluate <<~JS
    [window.innerWidth, window.innerHeight]
  JS
end