Firefox WebDriver takes forever to start with 28,000+ entries detected in cache?

266 views Asked by At

I'm trying to launch a specific profile in Selenium v4 and Java using the following code:

System.setProperty("webdriver.gecko.driver", path_to_geckdriver);
File firefoxProfileFile = new File(path_to_file);
FirefoxProfile firefoxProfile = new FirefoxProfile(firefoxProfileFile);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxProfile);

It took 411 seconds (almost 7 minutes) to load said profile.

When debugging above, I noticed that the folder: \MyProfile\cache2\entries\ has 28,000 items in it totaling 1+ GB of data. I deleted all of the items and ran above code again and this time it took (only?) 69 seconds to load said profile.

My question is:

  1. What process is populating this folder with so many garbage entries? How can I prevent FF from populating \MyProfile\cache2\entries\ with so many entries in the future?

  2. While the load time is now much better, is 60 second load time really the fastest I can achieve?

P.S: I am not creating a temporary FF profile, rather I'm loading existing profile from file.

1

There are 1 answers

2
undetected Selenium On

When you initiate a Browsing Context using Selenium from an existing FirefoxProfile the following settings/configurations:

  • browser settings
  • Extensions
  • Bookmarks
  • Apps
  • Saved Passwords
  • Browsing History

are copied from the actual profile directory into a temporary rust_mozprofile as follows:

1521447102321   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\SOS\\AppData\\Local\\Temp\\rust_mozprofile.2oSwrQwQoby9"

Naturally, the more the settings/configurations to be copied the more time is required for the I/O to complete.

You can find a relevant detailed discussion in webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?

However, to reduce the amount of the leftovers from the executions you should always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.