-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Description
Description
If using the firefox profile, it will make a copy of your profile folder. Then, when instantiating a firefox profile, if you send an interrupt signal fast enough such that your driver is not fully initialized, this copy will remain. If your profile is large enough and you do this a number of times for various reasons, you may end up with very large copies that consume your available space (which is something that occured to me today with a 1.3GB profile).
Reproducible Code
I have a setup where I use the following code to set up a driver:
def init_driver(run_headless: bool) -> tuple[WebDriver, str]:
try:
# Set Firefox options to use the existing profile
firefox_options = Options()
if run_headless:
firefox_options.add_argument("--headless")
profile_path = os.getenv("OBLIO_FIREFOX_PROFILE_PATH")
if profile_path not in [None, ""]:
logger.debug("using profile path %s", profile_path)
firefox_profile = FirefoxProfile(profile_path)
firefox_options.profile = firefox_profile
logger.debug(f"creating temp profile {firefox_profile._profile_dir}")
driver = webdriver.Firefox(options=firefox_options)
return driver
My main function looks something like this:
def main():
# other code
try:
driver = init_driver(run_headless)
logger.info("driver initialized")
login(driver=driver)
download_oblio_data_locally(
driver=driver, download_directory=DOWNLOADS_DIRECTORY
)
except WebDriverException as e:
logger.error(f"got webdriver error: {str(e)}")
except KeyboardInterrupt:
logger.info("exiting program")
finally:
logger.info("closing driver")
driver.quit()
If I quit my program soon enough such that driver
is not set, but late enough such that profile had been created, it will leave the copy dangling.
I tried to work around it by writing some code that tries to clean up that folder, but was wondering if this could be incorporated into the library code (e.g. catching it in the driver constructor code). If you're willing to make the change, I am open to make the contributions.
Debugging Logs
Not necessary. Check the full code here.
What version of Selenium are you currently using?
4.30.0
The following statements are true
- This applies to the most recent version of Selenium (we can't fix old versions)
- This hasn't already been reported (I searched and didn't find it)
- All information necessary to reproduce the issue has been provided above
Did this work for you before?
Not sure, this is my first time trying it
If yes, what version of Selenium did it work with?
No response
Operating System
Linux pop-os 6.12.10-76061203-generic #202412060638174015461722.04~b4b3ebc SMP PREEMPT_DYNAMIC Fri F x86_64 x86_64 x86_64 GNU/Linux
Selenium Language Binding
Python
Which browsers are you experiencing the issue with?
Firefox
Are you using Selenium Grid?
No