pythonseleniumbrowsermob-proxybrowsermob

Activate Ecc for Browsermob/Selenium


I have the problem that the testing with Selenium and browsermob becomes very slow for certain websites. Here is my current code for setting up the server and proxy:

    server = Server(path_browsermob)
    server.start()
    proxy = server.create_proxy()
    co = webdriver.ChromeOptions()
    co.add_argument('--proxy-server={host}:{port}'.format(host='localhost', port=proxy.port))
    driver = webdriver.Chrome(path_driver, chrome_options=co)

I already read that one way to speed up testing is to use EC certificates instead of RSA. However, how do I do activate ECC with the code above?


Solution

  • I had this same question after learning about this "issue" with browsermob-proxy and SSL certs.

    After digging around in the browsermob-proxy python library it looks as if any extra parameters are passed into the URL when creating the proxy.

    With that you should be able to pass any of the parameters outlined in API documentation into create_proxy().

    Here's my code snippet (although, I'm not sure how to query the proxy to see if its actually set).

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from browsermobproxy import Server
    
    #Create proxy server
    bmp_server_opts = {"port": 8080}
    bmp_server = Server("browsermob-proxy-2.1.4/bin/browsermob-proxy", options = bmp_server_opts)
    bmp_server.start()
    time.sleep(1)
    proxy_server = bmp_server.create_proxy({"useEcc": True, "trustAllServers": True})
    time.sleep(1)
    selenium_proxy = proxy_server.selenium_proxy()
    
    #Create Firefox options
    firefox_opts = webdriver.FirefoxOptions()
    firefox_profile = webdriver.FirefoxProfile()
    firefox_opts.set_headless()
    firefox_profile.set_proxy(selenium_proxy)
    
    #Fire up a Firefox browser
    firefox_browser = webdriver.Firefox(firefox_profile = firefox_profile, firefox_options = firefox_opts)
    wait_load = WebDriverWait(firefox_browser, 10)
    proxy_server.new_har("103398", options = {'captureHeaders': True, "captureContent": True})
    

    Although there was still some issues with even setting useEcc to true and I ended up adding trustAllServers which ignores ssl checking all together, but I'm not sure this would be the right way to go if you needed close to true user experience. In either case I still have fairly slow SSL/TLS connections.