Module: Puppeteer::ChromeUserDataDir

Defined in:
lib/puppeteer/chrome_user_data_dir.rb

Constant Summary collapse

CHANNELS =

: Array

%w[chrome chrome-beta chrome-canary chrome-dev].freeze
MAC_DIR_NAMES =
{
  'chrome' => 'Chrome',
  'chrome-beta' => 'Chrome Beta',
  'chrome-canary' => 'Chrome Canary',
  'chrome-dev' => 'Chrome Dev',
}.freeze
LINUX_DIR_NAMES =

: Hash[String, String]

{
  'chrome' => 'google-chrome',
  'chrome-beta' => 'google-chrome-beta',
  'chrome-canary' => 'google-chrome-canary',
  'chrome-dev' => 'google-chrome-unstable',
}.freeze
WINDOWS_DIR_NAMES =

: Hash[String, String]

{
  'chrome' => ['Google', 'Chrome', 'User Data'],
  'chrome-beta' => ['Google', 'Chrome Beta', 'User Data'],
  'chrome-canary' => ['Google', 'Chrome SxS', 'User Data'],
  'chrome-dev' => ['Google', 'Chrome Dev', 'User Data'],
}.freeze

Class Method Summary collapse

Class Method Details

.normalize_channel(channel) ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
64
# File 'lib/puppeteer/chrome_user_data_dir.rb', line 59

def self.normalize_channel(channel)
  normalized_channel = channel.to_s
  return normalized_channel if CHANNELS.include?(normalized_channel)

  raise ArgumentError.new("Invalid channel: '#{channel}'. Allowed channel is #{CHANNELS}")
end

.resolve_default(channel, platform: nil, env: ENV, home: nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppeteer/chrome_user_data_dir.rb', line 35

def self.resolve_default(channel, platform: nil, env: ENV, home: nil)
  channel = normalize_channel(channel)
  platform ||= current_platform
  home ||= Dir.home

  case platform.to_sym
  when :windows
    base = env['LOCALAPPDATA']
    base = join_path(:windows, home, 'AppData', 'Local') if base.nil? || base.empty?
    join_path(:windows, base, *WINDOWS_DIR_NAMES.fetch(channel))
  when :darwin
    join_path(:darwin, home, 'Library', 'Application Support', 'Google', MAC_DIR_NAMES.fetch(channel))
  when :linux
    base = env['CHROME_CONFIG_HOME']
    base = env['XDG_CONFIG_HOME'] if base.nil? || base.empty?
    base = join_path(:linux, home, '.config') if base.nil? || base.empty?
    join_path(:linux, base, LINUX_DIR_NAMES.fetch(channel))
  else
    raise ArgumentError.new("Unsupported platform: #{platform}")
  end
end