Skip to content

Instantly share code, notes, and snippets.

Last active January 31, 2018 09:38
Show Gist options
  • Save diemol/53ad9065686f4c330596725a8147aad5 to your computer and use it in GitHub Desktop.
Save diemol/53ad9065686f4c330596725a8147aad5 to your computer and use it in GitHub Desktop.
How to use a Firefox custom profile with

Steps to follow in the host machine (most likely, your machine).

Create a Firefox Profile

Copy the created profile to a given folder

  • In OSX, the profiles are located at ~/Library/Application Support/Firefox/Profiles. Find where they are in your operating system.
  • In the profiles folder you will find the profile you just created, for this case we will use the folder name hcqx24zh.selenium.
  • Copy the profile to a folder called firefox in a given location. E.g.:
mkdir /tmp/firefox/
cp -r ~/Library/Application Support/Firefox/Profiles/hcqx24zh.selenium /tmp/firefox/

Create the file profiles.ini

  • In the /tmp/firefox folder, create a text file called profiles.ini, with the following content:


  • This file is needed because Firefox will use it as a reference to know which profiles exist. So even if the profile is present but the file is not, Firefox won't be aware of the profile.

Start the docker-selenium container

In short, we will mount a volume using the /tmp/firefox folder to a specific path in the container. In addition, we will use the JAVA_OPTS configuration option to pass the Firefox profile name.

Note that when passing the option -Dwebdriver.firefox.profile to Selenium Grid, the specified value must be the profile name, not the path. In this case, it will look like this: -Dwebdriver.firefox.profile=selenium.

There is a small issue with docker, we cannot pass an env var like this: JAVA_OPTS='-Dwebdriver.firefox.profile=selenium'. We get the following error (even when trying without quotations or with double quotations):

docker: Error parsing reference: " " is not a valid repository/tag: invalid reference format.
See 'docker run --help'.

Therefore, we export the env var first and then we use it in the docker run command.

export JAVA_OPTS=-Dwebdriver.firefox.profile=selenium

(If there is a different way to do this, please let me know).

Now we can start the container (using the Firefox Standalone debug here, but it can work with the other Firefox images):

docker run --rm -p 4444:4444 -p 5900:5900 \
  -v /tmp/firefox:/home/seluser/.mozilla/firefox \
  -e JAVA_OPTS selenium/standalone-firefox-debug:3.4.0-chromium

What happens there, is that the folder where the custom profile is, gets mapped to the folder where Firefox looks for the existing profiles. When Firefox finds the profiles.ini file, it notices the file and the profiles described in the file.

That's it, the tests should run with a Firefox custom profile run in docker-selenium.


Create the custom profile and the profiles.ini file, then build the docker-selenium image on your own including these files in the expected folder (/home/seluser/.mozilla/firefox), and start the grid/node with the -Dwebdriver.firefox.profile=selenium option.

Keep in mind

  • I might have missed some Firefox configuration options that could make this process easier. If you find them, we can update this small document.
  • I noticed that the profile stores paths relative to your machine/OS. In my case, I created a custom profile in OSX and it was being used in the docker-selenium container (Ubuntu), and some options I configured were not present due to this. So better double check that the options are there or just create the profile in an Ubuntu machine.


Copy link

As an alternative I created a Firefox profile and created a tar archive ff_profile.tar.gz. I also created a profiles.ini file like in the example above and modified like this

java ${JAVA_OPTS} -Dwebdriver.firefox.profile=seluser -jar /opt/selenium/selenium-server-standalone.jar \

by adding the java option selecting the user profile.
Then I built a custom image using Dockerfile including these lines

COPY profiles.ini /home/seluser/.mozilla/firefox/profiles.ini
COPY ff_profile.tar.gz /home/seluser/.mozilla/firefox/ff_profile.tar.gz
RUN tar -zxvf /home/seluser/.mozilla/firefox/ff_profile.tar.gz -C /home/seluser/.mozilla/firefox/

This was tested in the grid with selenium/node-firefox:3.0.1 as source image.

Copy link

Hey DJ ,
Can you please share Selenium Hybrid framework Code with Readme file if you have?
I am learning selenium but dont get idea how to create it.

Can you please send code for slenium framework code on

Copy link

Musinux commented Jan 31, 2018

FYI, You don't have to follow this procedure if you are using node selenium-webdriver because as the documentation for the firefox driver says:

You may customize the Firefox binary and profile when running against a
remote Selenium server. Your custom profile will be packaged as a zip and
transfered to the remote host for use. The profile will be transferred
_once for each new session_. The performance impact should be minimal if
you've only configured a few extra browser preferences
const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
let options = new firefox.Options()

let driver = new Builder()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment