Sha256: dce03a162875467d7b6665ba11649320561c1c37a3239153b304bbb532743b70

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

module Browsed
  module Chrome
    
    private
      def register_chrome_driver(driver_options: {}, timeout: 60, debug: false)
        profile                 =   Selenium::WebDriver::Chrome::Profile.new
        
        profile["user-agent"]   =   self.user_agent unless self.user_agent.to_s.empty?
        
        proxy_options           =   chrome_proxy_options
        capabilities            =   !proxy_options.nil? ? Selenium::WebDriver::Remote::Capabilities.chrome(proxy: proxy_options) : {}
        options                 =   Selenium::WebDriver::Chrome::Options.new(profile: profile)
        
        Capybara.register_driver self.driver do |app|
          Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, desired_capabilities: capabilities)
        end
      end
    
      def chrome_proxy_options
        proxy_options           =   nil
        
        if self.proxy && !self.proxy.empty? && self.proxy.has_key?(:host) && self.proxy.has_key?(:port)
          proxy_options         =   Selenium::WebDriver::Proxy.new(
            http: "#{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)}",
            ssl:  "#{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)}"
          )
          
          log("Will use proxy #{self.proxy.fetch(:host)}:#{self.proxy.fetch(:port)} to initiate the request.")
        end
      
        return proxy_options
      end
  
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
browsed-0.1.8 lib/browsed/chrome.rb
browsed-0.1.7 lib/browsed/chrome.rb
browsed-0.1.6 lib/browsed/chrome.rb
browsed-0.1.5 lib/browsed/chrome.rb
browsed-0.1.4 lib/browsed/chrome.rb
browsed-0.1.3 lib/browsed/chrome.rb
browsed-0.1.2 lib/browsed/chrome.rb
browsed-0.1.1 lib/browsed/chrome.rb
browsed-0.1.0 lib/browsed/chrome.rb