Sha256: 69cf55257780660116dd2e1a3e5a55f25a94c9cb9f1f3eeba77f7560ad34af4d

Contents?: true

Size: 1.67 KB

Versions: 12

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module SeoCache
  class PageRender
    def initialize
      init_driver
    end

    def get(url, quit_after_render = true)
      @driver.get(url)

      sleep SeoCache.wait_time_for_page_loading if SeoCache.wait_time_for_page_loading

      return @driver.page_source
    rescue StandardError => error
      SeoCache.log_error(error.message)

      return false
    ensure
      @driver&.quit if quit_after_render
    end

    def close_connection
      @driver&.quit
    end

    private

    def init_driver
      # Selenium::WebDriver.logger.level = :info

      Webdrivers.cache_time            = 86_400 * 10 # Chromedriver will be cached for 10 days (except if it detects a new version of Chrome)

      Selenium::WebDriver::Chrome.path = SeoCache.chrome_path if SeoCache.chrome_path

      browser_options = ::Selenium::WebDriver::Chrome::Options.new
      browser_options.args << 'disable-infobars'
      browser_options.args << '--headless'
      browser_options.args << '--no-sandbox'
      browser_options.args << '--incognito'
      browser_options.args << '--disable-dev-shm-usage'
      browser_options.args << '--disable-gpu'
      browser_options.args << '--disable-web-security'
      browser_options.args << '--disable-extensions'
      browser_options.args << '--disable-logging'
      browser_options.args << '--disable-notifications'
      browser_options.args << '--disable-sync'
      browser_options.args << '--window-size=1920x1080'
      browser_options.args << "--remote-debugging-port=#{SeoCache.chrome_debugging_port}" if SeoCache.chrome_debugging_port
      @driver = ::Selenium::WebDriver.for(:chrome, options: browser_options)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
seo_cache-1.2.0 lib/seo_cache/page_render.rb
seo_cache-1.1.2 lib/seo_cache/page_render.rb
seo_cache-1.1.1 lib/seo_cache/page_render.rb
seo_cache-1.1.0 lib/seo_cache/page_render.rb
seo_cache-1.0.7 lib/seo_cache/page_render.rb
seo_cache-1.0.6 lib/seo_cache/page_render.rb
seo_cache-1.0.5 lib/seo_cache/page_render.rb
seo_cache-1.0.4 lib/seo_cache/page_render.rb
seo_cache-1.0.3 lib/seo_cache/page_render.rb
seo_cache-1.0.2 lib/seo_cache/page_render.rb
seo_cache-1.0.1 lib/seo_cache/page_render.rb
seo_cache-1.0.0 lib/seo_cache/page_render.rb