In Python Selenium how to set a Firefox `about:config` entry without modifying the file system profile, nor web-scraping `about:config`?
Jun 6, 11:37pm
To set a Firefox about:config entry programmatically using Selenium without modifying the file system profile or web-scraping about:config, you can use Firefox's preferences (also known as "prefs") system. Selenium allows you to set preferences directly when launching the browser via FirefoxOptions.
How to Set a about:config Entry via Selenium
Use FirefoxOptions to set preferences before launching the browser.
Map the about:config key to its corresponding preference name (e.g., browser.startup.homepage for the homepage).
Pass the preferences to the Firefox driver.
Example Code
python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
# Create Firefox options
options = Options()
# Set the preference (replace 'pref_name' and 'pref_value' with your target)
options.set_preference("pref_name", "pref_value")
# Example: Disable Firefox's default "new tab" page
options.set_preference("browser.newtabpage.enabled", False)
# Example: Set a custom homepage
options.set_preference("browser.startup.homepage", "https://example.com")
# Launch Firefox with the options
driver = webdriver.Firefox(options=options)
# Continue with your Selenium script
driver.get("https://example.com")
Key Notes
Preference Names: The preference names in about:config are the same as those used in set_preference. For example: