class Selenium::WebDriver::Manager

def add_cookie(opts = {})

def add_cookie(opts = {})
  raise ArgumentError, 'name is required' unless opts[:name]
  raise ArgumentError, 'value is required' unless opts[:value]
  # NOTE: This is required because of https://bugs.chromium.org/p/chromedriver/issues/detail?id=3732
  opts[:secure] ||= false
  same_site = opts.delete(:same_site)
  opts[:sameSite] = same_site if same_site
  http_only = opts.delete(:http_only)
  opts[:httpOnly] = http_only if http_only
  obj = opts.delete(:expires)
  opts[:expiry] = seconds_from(obj).to_int if obj
  @bridge.add_cookie opts
end

def all_cookies

def all_cookies
  @bridge.cookies.map { |cookie| convert_cookie(cookie) }
end

def convert_cookie(cookie)

def convert_cookie(cookie)
  {
    name: cookie['name'],
    value: cookie['value'],
    path: cookie['path'],
    domain: cookie['domain'] && strip_port(cookie['domain']),
    expires: cookie['expiry'] && datetime_at(cookie['expiry']),
    same_site: cookie['sameSite'],
    http_only: cookie['httpOnly'],
    secure: cookie['secure']
  }
end

def cookie_named(name)

def cookie_named(name)
  convert_cookie(@bridge.cookie(name))
end

def datetime_at(int)

def datetime_at(int)
  DateTime.civil(1970) + (int / SECONDS_PER_DAY)
end

def delete_all_cookies

def delete_all_cookies
  @bridge.delete_all_cookies
end

def delete_cookie(name)

def delete_cookie(name)
  @bridge.delete_cookie name
end

def initialize(bridge)

def initialize(bridge)
  @bridge = bridge
end

def seconds_from(obj)

def seconds_from(obj)
  case obj
  when Time
    obj.to_f
  when DateTime
    (obj - DateTime.civil(1970)) * SECONDS_PER_DAY
  when Numeric
    obj
  else
    raise ArgumentError, "invalid value for expiration date: #{obj.inspect}"
  end
end

def strip_port(str)

def strip_port(str)
  str.split(':', 2).first
end

def timeouts

def timeouts
  @timeouts ||= Timeouts.new(@bridge)
end

def window

def window
  @window ||= Window.new(@bridge)
end