How to install custom extension to headless Firefox in Linux?

4.2k views Asked by At

Automated tests with Selenium are awesome, but how to do them on headless Firefox with a pre-installed extension?

I found this for Chrome, but nothing for Firefox

How to install an extension to FF?

4

There are 4 answers

1
Ondřej Doněk On

You can install add-on globally via command line using (e.g. on my Ubuntu):

gksudo firefox -install-global-extension "path_to_your.xpi"
2
André On

I don't know the language you are using, but if you have the xpi file handy you can install (or rather enable it like this)

this is a javascript way, but all selenium drivers work the same (look for the profile part)

let binary;
switch (channel) {
    case 'nightly':
    binary = new firefox.Binary(firefox.Channel.NIGHTLY);
    break;
    case 'beta':
    binary = new firefox.Binary(firefox.Channel.BETA);
    break;
    default:
    binary = new firefox.Binary(firefox.Channel.RELEASE);
}

binary.addArguments('-headless');

let options = new firefox.Options();
options.setBinary(binary);

let profile = new firefox.Profile();
profile.addExtension(path.join(__dirname, '[email protected]'));
options.setProfile(profile);

driver = new webdriver.Builder()
    .forBrowser('firefox')
    .setFirefoxOptions(options)
    .build();
1
Waruna Perera On

Best thing is to use some thing like Xvfb . And run firefox in headless mode. http://tobyho.com/2015/01/09/headless-browser-testing-xvfb/

1
Atif Hussain On

now you can install any chrome extension to Firefox. here is the solution. How to install chrome extension to firefox?