Selenium, Web Proxy and HTTP Basic Auth

Problem Statement:
Please offer a solution for basic authentication · Issue #6644 · SeleniumHQ/selenium

Solution
Install Firefox version 66.0.5 from here - 
https://ftp.mozilla.org/pub/firefox/releases/66.0.5/
Why v66.0.5 specifically? Because it’s the latest version of Firefox where authentication alert 
handling would work. If you’re using a Linux box then you also need to run the “dpkg configure” 
command to install the package successfully. Once everything is done, please make sure the 
version of Firefox you just downloaded/installed is correct by running the “firefox --version” 
command. 

Let’s define the firefox driver now:
     proxy_host = ''
     proxy_port = ''

    def create_firefox_driver(user_agent = False):
    cap = DesiredCapabilities().FIREFOX

    options = Options()
    options.headless = True

    profile = webdriver.FirefoxProfile()
    if user_agent:
    profile.set_preference("general.useragent.override", user_agent) 
    # if you want to pass useragent
    profile.set_preference("network.proxy.type", 1)
    profile.set_preference("network.proxy.http", proxy_host)
    profile.set_preference("network.proxy.http_port", int(proxy_port))
    profile.set_preference('network.proxy.no_proxies_on', 'localhost,127.0.0.1')
    profile.update_preferences()
    driver = webdriver.Firefox(capabilities=cap,
                               options=options,
                               firefox_profile=profile)
    return driver

Now, let’s use the function in our code - 
    driver = create_firefox_driver()
    driver.get(url)

Above code will prompt for the username/ password. 
Since, we typically want the entire process to be automated, we will enter the credentials from
within the code: 
    keyToSend = "<username>\ue004<password>"
    alert_window = driver.switch_to.alert
    alert_window.send_keys(keysToSend=keyToSend)
    alert_window.accept()

Try running with options.headless = False to see everything runs fine. This should work and you should
see the requests being made through the proxy server. Check on proxy dashboard (if you’ve bought
one and you got dashboard access to it)

Google Chrome
If you can/want to use Google Chrome then follow this tutorial
https://botproxy.net/docs/how-to/setting-chromedriver-proxy-auth-with-selenium-using-python/ 
However it doesn’t work with headless browsers as Chrome doesn’t support extensions in headless mode. 
Here’s what Google developer says - 
https://bugs.chromium.org/p/chromium/issues/detail?id=706008#c5

Reference
https://stackoverflow.com/questions/38304253/how-to-set-proxy-authentication-user-password-using-python-selenium