Class: TRMNLP::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/trmnlp/screenshot.rb

Instance Method Summary collapse

Constructor Details

#initialize(pool:, viewport_timeout: 5) ⇒ Screenshot

Returns a new instance of Screenshot.



10
11
12
13
# File 'lib/trmnlp/screenshot.rb', line 10

def initialize(pool:, viewport_timeout: 5)
  @pool = pool
  @viewport_timeout = viewport_timeout
end

Instance Method Details

#call(html:, width:, height:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/trmnlp/screenshot.rb', line 15

def call(html:, width:, height:)
  attempts = 0

  begin
    @pool.with_driver { |driver| render(driver, html, width, height) }
  rescue Selenium::WebDriver::Error::TimeoutError,
         Selenium::WebDriver::Error::WebDriverError
    attempts += 1
    retry if attempts <= 1
    raise
  end
end