#StackBounty: #python #firefox #geckodriver #connection-refused #minidump Firefox connection refused when adding -profile argument to p…

Bounty: 50

I’m attempting to add options to the startup of my Firefox selenium driver in python to capture crash data. The function I use to startup the driver looks like this:

import os 
from selenium import webdriver  
from selenium.webdriver.firefox.options import Options as FFOptions
from selenium.webdriver.firefox.webdriver import WebDriver as FirefoxWebDriver 
import tempfile
SELENIUM_TEMP_DIR = os.path.abspath('./data/raw')


def get_local_firefox_driver():
    
    os.environ['MOZ_FORCE_DISABLE_E10S'] = '1'
    ff_options = FFOptions()

    # Add custom crash dump folder
    profile_temp = tempfile.mkdtemp(".selenium", dir=SELENIUM_TEMP_DIR)
    print("*** Using profile: {}".format(profile_temp))
    ff_options.add_argument("-profile")
    ff_options.add_argument(profile_temp)

    ff_profile = webdriver.FirefoxProfile()
    # set some privacy settings
    ff_profile.set_preference("places.history.enabled", False)
    ff_profile.set_preference("privacy.clearOnShutdown.offlineApps", True)
    ff_profile.set_preference("privacy.clearOnShutdown.passwords", True)
    ff_profile.set_preference("privacy.clearOnShutdown.siteSettings", True)
    ff_profile.set_preference("privacy.sanitize.sanitizeOnShutdown", True)
    ff_profile.set_preference("signon.rememberSignons", False)
    ff_profile.set_preference("network.cookie.lifetimePolicy", 2)
    ff_profile.set_preference("network.dns.disablePrefetch", True)
    ff_profile.set_preference("network.http.sendRefererHeader", 0)
    ff_profile.set_preference("permissions.default.image", 2)

    driver = webdriver.Firefox(firefox_profile=ff_profile, options=ff_options)
    return driver

When I attempt to startup the driver with this version of the function I get this error:

Traceback (most recent call last):
  File "/Users/username/project_name/error_demo.py", line 2, in <module>
    driver = get_local_firefox_driver(headless=False)
  File "/Users/username/project_name/src/selenium_helper.py", line 129, in get_local_firefox_driver
    driver = webdriver.Firefox(firefox_profile=ff_profile, options=ff_options, capabilities=ff_capabilities)
  File "/Users/username/miniconda3/envs/live_auction/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/Users/username/miniconda3/envs/live_auction/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Users/username/miniconda3/envs/live_auction/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Users/username/miniconda3/envs/live_auction/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/username/miniconda3/envs/live_auction/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: connection refused

During the crash, Firefox actually opens and looks likes this:
enter image description here

If I comment out the section of code that is intended to capture the crash data

# Add custom crash dump folder
profile_temp = tempfile.mkdtemp(".selenium", dir=SELENIUM_TEMP_DIR)
print("*** Using profile: {}".format(profile_temp))
ff_options.add_argument("-profile")
ff_options.add_argument(profile_temp)

I get no errors and the Firefox browser opens up like this:

enter image description here

How does get_local_firefox_driver() need to be modified to get Firefox and geckodriver to startup correctly with the ability to capture crash data?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.