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.new( width: [:width] || Preset::DESKTOP.width, height: [:height] || Preset::DESKTOP.height ) elsif [:preset] if Preset.const_defined?([:preset].to_s.upcase) = Preset.const_get([:preset].to_s.upcase) else raise ArgumentError, "Preset #{options[:preset]} not found" end else = Preset::DESKTOP end = end |
Instance Method Details
#capture(url, options = {}) ⇒ Artifact
Returns the screenshot artifact.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kleya/browser.rb', line 40 def capture(url, = {}) browser.goto(url) format = [:format] || :jpeg quality = [:quality] || 90 encoding = [:encoding] || :base64 data = browser.screenshot( format: format, quality: quality, encoding: encoding ) Artifact.new(data:, url:, viewport: , format:, quality:, encoding:) rescue Ferrum::TimeoutError raise TimeoutError, 'Browser timed out' end |
#quit ⇒ void
59 60 61 62 |
# File 'lib/kleya/browser.rb', line 59 def quit @browser&.quit @browser = nil end |