Search code examples
seleniumselenium-webdriverfirefoxgeckodriver

Selenium does not install add-on in Firefox when using the addExtensions option


I want to install a custom XPI file in Firefox when running it with selenium and geckodriver in a TypeScript and Jest context.

The important part of the test script is this:

let driver: webdriver.WebDriver;
const firefoxExt = path.resolve(__dirname, '..', '..', 'extension', 'firefox.xpi');
const firefoxOptions = new firefox.Options().addExtensions(firefoxExt);
driver = new webdriver.Builder().forBrowser('firefox').setFirefoxOptions(firefoxOptions).build();

I am expecting Firefox to launch and install firefox.xpi as an add-on, but there are no add-ons present in the opened Firefox instance. There is no issue with the XPI itself, as the XPI can be installed manually, as a temporary extension, without issues. Also, the XPI exists at the path, as otherwise it would error out on path.resolve.

For others to reproduce the issue, I have created a repository with a minimal, reproducible example. See this repo: https://github.com/slhck/web-extension-selenium-test

Note that this is not a duplicate of:

I have created a bug report in Selenium itself, but it has not received any activity yet.

Does anyone know what the issue could be, and how it could be solved?


Solution

  • You can use installAddon. There may be a more elegant way to do this, but the code below works:

    beforeAll(async () => {
      const firefoxExt = path.resolve(__dirname, '..', '..', 'extension', 'firefox.xpi');
      driver = new webdriver.Builder().forBrowser('firefox').build();
      new firefox.Driver(driver.getSession(), driver.getExecutor()).installAddon(firefoxExt, true);
    });