How to install extension permanently in geckodriver How to install extension permanently in geckodriver selenium selenium

How to install extension permanently in geckodriver


Note: OP didn't specify a language, so this answer is for Python. The other Selenium WebDriver language bindings have similar mechanisms for creating profiles and adding extensions.


You can install the Extension each time you instantiate the driver.

First, download the extension (XPI file) you want from: https://addons.mozilla.org.

Then, in your code... create a FirefoxProfile() and use the add_extension() method to add the extension. Then you can instantiate a driver using that profile.

For example, this will launch Firefox with a newly created profile containing the "HTTPS Everywhere" extension:

from selenium import webdriverprofile = webdriver.FirefoxProfile() profile.add_extension(extension='https_everywhere-2019.1.31-an+fx.xpi')driver = webdriver.Firefox(firefox_profile=profile) 


You need to launch geckdriver with an exisitng profile by specifying the profile path of firefox

For python you can do it by this:

profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default') // change this pathbrowser = webdriver.Firefox(firefox_profile=profile)

For C# you can do this:

string path = @"C:\Users\username\AppData\Local\Mozilla\Firefox\Profiles\myi5go1k.default";FirefoxProfile ffprofile = new FirefoxProfile(path);Driver = new FirefoxDriver(ffprofile);


You can install an extension/addon permanently within a specific Firefox Profile and use it. To achieve that you need follow the below mentioned steps:

  • You need to create a new Firefox Profile manually (e.g. FirefoxExtensionProfile) following the instructions at Creating a new Firefox profile on Windows.
  • Open a Firefox Browsing session manually and invoke the url https://addons.mozilla.org/en-US/firefox/
  • In the Search Box search for an extension e.g. HTTPS Everywhere.
  • Click on the search result and install / enable (incase previously installed and currently disabled) the extension.
  • Now you can use the following Java solution to open the Firefox Profile FirefoxExtensionProfile containing the extension HTTPS Everywhere

    • Code Block:

      package A_MozillaFirefox;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.firefox.FirefoxOptions;import org.openqa.selenium.firefox.FirefoxProfile;import org.openqa.selenium.firefox.ProfilesIni;public class A_FirefoxProfile_dc_opt {    public static void main(String[] args) {        System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");        ProfilesIni profile = new ProfilesIni();        FirefoxProfile testprofile = profile.getProfile("FirefoxExtensionProfile");        FirefoxOptions opt = new FirefoxOptions();        opt.setProfile(testprofile);        WebDriver driver =  new FirefoxDriver(opt);        driver.get("https://www.google.com");    }}
    • Browser Snapshot:

Extension_HTTPS Everywhere


Reference

You can find a couple of relevant discussions in: