0

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?

slhck
  • 36,575
  • 28
  • 148
  • 201

1 Answers1

2

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);
});
Sers
  • 12,047
  • 2
  • 12
  • 31