Class: Kleya::Browser
- Inherits:
-
Object
- Object
- Kleya::Browser
- Defined in:
- lib/kleya/browser.rb
Instance Method Summary collapse
-
#capture(url, options = {}) ⇒ Artifact
The screenshot artifact.
-
#initialize(**options) ⇒ Browser
constructor
A new instance of Browser.
-
#quit ⇒ void
Quits the browser.
Constructor Details
#initialize(**options) ⇒ Browser
Returns a new instance of Browser.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kleya/browser.rb', line 9 def initialize(**) if [:width] || [:height] @viewport = Viewport.new( width: [:width] || Preset::DESKTOP.width, height: [:height] || Preset::DESKTOP.height ) elsif [:preset] if Preset.const_defined?([:preset].to_s.upcase) @viewport = Preset.const_get([:preset].to_s.upcase) else raise ArgumentError, "Preset #{[:preset]} not found" end else @viewport = Preset::DESKTOP end @options = end |
Instance Method Details
#capture(url, options = {}) ⇒ Artifact
Returns the screenshot artifact.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kleya/browser.rb', line 41 def capture(url, = {}) browser.goto(url) format = [:format] || :jpeg quality = [:quality] || 90 encoding = [:encoding] || :base64 full = [:area] == :page data = browser.screenshot(format:, quality:, encoding:, full:) Artifact.new(data:, url:, viewport: @viewport, format:, quality:, encoding:) rescue Ferrum::TimeoutError raise TimeoutError, 'Browser timed out' end |
#quit ⇒ void
57 58 59 60 |
# File 'lib/kleya/browser.rb', line 57 def quit @browser&.quit @browser = nil end |