In Python Selenium how to set a Firefox `about:config` entry without modifying the file system profile, nor web-scraping `about:config`?
Yesterday 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

  1. Use FirefoxOptions to set preferences before launching the browser.
  2. Map the about:config key to its corresponding preference name (e.g., browser.startup.homepage for the homepage).
  3. 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:
    • browser.startup.homepage → Homepage URL
    • network.proxy.type → Proxy type (0 = direct, 1 = manual, etc.)
    • privacy.trackingprotection.enabled → Tracking protection
  • Boolean/Integer/String: Use the appropriate Python type for the preference value (e.g., True/False for booleans, 1 for integers, "value" for strings).
  • No File System Modifications: This method does not touch the filesystem or require scraping about:config.

How to Find the Correct Preference Name

  1. Open about:config in Firefox.
  2. Search for the setting you want to change.
  3. The Name column is the preference name to use in set_preference.

Limitations

  • Not all about:config entries can be set this way (e.g., some are read-only or require browser restarts).
  • Some preferences may require a browser restart to take effect. In such cases, you may need to set them in the profile before launching Selenium.
Yesterday 11:37pm

This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.

Vibe can make mistakes. Check answers. Learn more