module Capybara::Selenium::Driver::W3CFirefoxDriver

def reset!

def reset!
  # Use instance variable directly so we avoid starting the browser just to reset the session
  return unless @browser
  if browser_version >= 68
    begin
      # Firefox 68 hangs if we try to switch windows while a modal is visible
      browser.switch_to.alert&.dismiss
    rescue Selenium::WebDriver::Error::NoSuchAlertError
      # Swallow
    end
  end
  switch_to_window(window_handles.first)
  window_handles.slice(1..).each { |win| close_window(win) }
  super
end