module Browsed module Firefox private def register_firefox_driver(driver_options: {}, timeout: 60, debug: false) headless = driver_options.fetch(:headless, false) download_path = driver_options.fetch(:download_path, self.configuration.download_path) private_browsing = driver_options.fetch(:private_browsing, false) profile = Selenium::WebDriver::Firefox::Profile.new if private_browsing profile["browser.privatebrowsing.autostart"] = true end unless download_path.to_s.empty? profile["browser.download.useDownloadDir"] = true profile["browser.download.dir"] = download_directory profile["browser.download.folderList"] = 2 profile["browser.helperApps.neverAsk.saveToDisk"] = "text/plain, application/vnd.ms-excel, text/csv, text/comma-separated-values, application/octet-stream, text/x-comma-separated-values, application/csv, application/x-filler" profile["toolkit.telemetry.prompted"] = true profile["pdfjs.disabled"] = true end profile["general.useragent.override"] = self.user_agent unless self.user_agent.to_s.empty? profile = firefox_proxy_options(profile) options = Selenium::WebDriver::Firefox::Options.new(profile: profile) options.args << "--headless" if headless Capybara.register_driver self.driver do |app| Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) end end def firefox_proxy_options(profile) if self.proxy && !self.proxy.empty? && self.proxy.has_key?(:host) && self.proxy.has_key?(:port) profile.proxy = 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 profile end end end