123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Chromium::Profile Private

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: rb/lib/selenium/webdriver/chromium/profile.rb

Class Method Summary

Instance Method Summary

::Selenium::WebDriver::ProfileHelper - Included

Constructor Details

.new(model = nil) ⇒ Profile

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 30

def initialize(model = nil)
  WebDriver.logger.deprecate(
    'Chromium::Profile (including Chrome::Profile and Edge::Profile)',
    "Options#add_argument('--user-data-dir=...'), Options#add_preference, and Options#add_extension",
    id: :chromium_profile
  )

  @model = verify_model(model)
  @extensions = []
  @encoded_extensions = []
  @directory = nil
end

Instance Method Details

#[](key)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 68

def [](key)
  parts = key.split('.')
  parts.inject(prefs) { |a, e| a.fetch(e) }
end

#[]=(key, value)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 63

def []=(key, value)
  parts = key.split('.')
  parts[0..-2].inject(prefs) { |a, e| a[e] ||= {} }[parts.last] = value
end

#add_encoded_extension(encoded)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 49

def add_encoded_extension(encoded)
  @encoded_extensions << encoded
end

#add_extension(path)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 43

def add_extension(path)
  raise Error::WebDriverError, "could not find extension at #{path.inspect}" unless File.file?(path)

  @extensions << path
end

#as_json

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 82

def as_json(*)
  extensions = @extensions.map do |crx_path|
    File.open(crx_path, 'rb') { |crx_file| Base64.strict_encode64 crx_file.read }
  end

  extensions.concat(@encoded_extensions)

  opts = {'directory' => directory || layout_on_disk}
  opts['extensions'] = extensions if extensions.any?
  opts
end

#directory

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 53

def directory
  @directory || layout_on_disk
end

#layout_on_disk

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 73

def layout_on_disk
  @directory = @model ? create_tmp_copy(@model) : Dir.mktmpdir('webdriver-chrome-profile')
  FileReaper << @directory

  write_prefs_to @directory

  @directory
end

#prefs (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 103

def prefs
  @prefs ||= read_model_prefs
end

#prefs_file_for(dir) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 113

def prefs_file_for(dir)
  File.join dir, 'Default', 'Preferences'
end

#read_model_prefs (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 107

def read_model_prefs
  return {} unless @model

  JSON.parse File.read(prefs_file_for(@model))
end

#write_prefs_to(dir) (private)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/chromium/profile.rb', line 96

def write_prefs_to(dir)
  prefs_file = prefs_file_for(dir)

  FileUtils.mkdir_p File.dirname(prefs_file)
  File.open(prefs_file, 'w') { |file| file << JSON.generate(prefs) }
end