class Selenium::WebDriver::Chromium::Options
def add_argument(arg)
def add_argument(arg) @options[:args] << arg end
def add_emulation(**opts)
def add_emulation(**opts) @options[:emulation] = opts end
def add_encoded_extension(encoded)
def add_encoded_extension(encoded) @encoded_extensions << encoded end
def add_extension(path)
def add_extension(path) validate_extension(path) end
def add_preference(name, value)
def add_preference(name, value) @options[:prefs][name] = value end
def binary_path
def binary_path Chrome.path end
def camelize?(key)
def camelize?(key) !%w[localState prefs].include?(key) end
def enable_android(package: 'com.android.chrome', serial_number: nil, use_running_app: nil, activity: nil)
def enable_android(package: 'com.android.chrome', serial_number: nil, use_running_app: nil, activity: nil) @options[:android_package] = package @options[:android_activity] = activity unless activity.nil? @options[:android_device_serial] = serial_number unless serial_number.nil? @options[:android_use_running_app] = use_running_app unless use_running_app.nil? end
def encode_extension(path)
def encode_extension(path) File.open(path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read } end
def extensions=(extensions)
def extensions=(extensions) extensions.each { |ext| validate_extension(ext) } end
def initialize(profile: nil, **opts)
def initialize(profile: nil, **opts) super(**opts) @profile = profile @options = {args: [], prefs: {}, emulation: {}, extensions: [], local_state: {}, exclude_switches: [], perf_logging_prefs: {}, window_types: []}.merge(@options) @logging_prefs = options.delete(:logging_prefs) || {} @encoded_extensions = @options.delete(:encoded_extensions) || [] @extensions = [] @options.delete(:extensions).each { |ext| validate_extension(ext) } end
def process_browser_options(browser_options)
def process_browser_options(browser_options) enable_logging(browser_options) unless @logging_prefs.empty? options = browser_options[self.class::KEY] options['binary'] ||= binary_path if binary_path if @profile options['args'] ||= [] options['args'] << "--user-data-dir=#{@profile.directory}" end return if (@encoded_extensions + @extensions).empty? options['extensions'] = @encoded_extensions + @extensions.map { |ext| encode_extension(ext) } end
def validate_extension(path)
def validate_extension(path) raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path) raise Error::WebDriverError, "file was not an extension #{path.inspect}" unless File.extname(path) == '.crx' @extensions << path end