Skip to content

Instantly share code, notes, and snippets.

@eddiejaoude
Last active September 18, 2024 07:21
Show Gist options
  • Save eddiejaoude/0076739fe610189581d0 to your computer and use it in GitHub Desktop.
Save eddiejaoude/0076739fe610189581d0 to your computer and use it in GitHub Desktop.
Install Firefox addon/extension with no user interaction

Src Reference: http://bernaerts.dyndns.org/download/ubuntu/install-mozilla-addon Article: http://bernaerts.dyndns.org/linux/74-ubuntu/271-ubuntu-firefox-thunderbird-addon-commandline

Firebug & YSlow headless

Headless with Xvfb in Ubuntu

sudo apt-get install xvfb
sudo Xvfb :99.0 -ac
export DISPLAY=:99.0

Firefox profiles

sudo wget -O /usr/local/sbin/install-mozilla-addon http://bernaerts.dyndns.org/download/ubuntu/install-mozilla-addon
sudo chmod +x /usr/local/sbin/install-mozilla-addon

sudo install-mozilla-addon https://addons.mozilla.org/firefox/downloads/latest/5369/addon-5369-latest.xpi
sudo install-mozilla-addon https://addons.mozilla.org/firefox/downloads/latest/1843/addon-1843-latest.xpi

Run Selenium with a Firefox profile

Get selenium

wget http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar

Run selenium

java -jar selenium-server-standalone-2.45.0.jar

Behat config for Firefox profile

extensions:
    Behat\MinkExtension\Extension:
      selenium2:
        browser: firefox
        wd_host: 'app url'
       capabilities: { 'firefox': {'profile':'path/to/your/zip file'} }

References:

sudo wget -O /usr/local/sbin/install-mozilla-addon http://bernaerts.dyndns.org/download/ubuntu/install-mozilla-addon
sudo chmod +x /usr/local/sbin/install-mozilla-addon
sudo install-mozilla-addon https://addons.mozilla.org/firefox/downloads/latest/5369/addon-5369-latest.xpi
sudo install-mozilla-addon https://addons.mozilla.org/firefox/downloads/latest/1843/addon-1843-latest.xpi
wget http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar
sudo apt-get install xvfb
sudo Xvfb :99.0 -ac
export DISPLAY=:99.0
java -jar selenium-server-standalone-2.45.0.jar > /dev/null 2>&1 &
#!/bin/sh
# -------------------------------------------------------
# Command line script to install
# Firefox and Thunderbird add-ons
# as global extensions available to all users
#
# Must be run with sudo
# Depends on unzip and wget
# Parameters :
# $1 = URL of extension on https://addons.mozilla.org/
#
# 26/03/2013, V1.0 - Creation by N. Bernaerts
# -------------------------------------------------------
# ------------------- parameters ----------------------
# set default add-ons URL base
URL_FIREFOX="https://addons.mozilla.org/firefox/"
URL_THUNDER="https://addons.mozilla.org/thunderbird/"
# set global extensions installation path
# you may have to adapt it to your environment
PATH_FIREFOX="/usr/lib/firefox-addons/extensions"
PATH_THUNDER="/usr/lib/thunderbird-addons/extensions"
# ------------------ Script --------------------------
# determine if we are dealing with firefox or thunderbird extension
EXT_FIREFOX=`echo "$1" | grep "$URL_FIREFOX"`
EXT_THUNDER=`echo "$1" | grep "$URL_THUNDER"`
# setup global extension path accordingly
if [ "$EXT_FIREFOX" != "" ]; then PATH_EXTENSION=$PATH_FIREFOX
elif [ "$EXT_THUNDER" != "" ]; then PATH_EXTENSION=$PATH_THUNDER
else PATH_EXTENSION=""
fi
# if add-on is recognised, install it
if [ "$PATH_EXTENSION" != "" ]
then
# download extension
wget -O addon.xpi "$1"
# get extension UID from install.rdf
UID_ADDON=`unzip -p addon.xpi install.rdf | grep "<em:id>" | head -n 1 | sed 's/^.*>\(.*\)<.*$/\1/g'`
# move extension to default installation path
unzip addon.xpi -d "$PATH_EXTENSION/$UID_ADDON"
rm addon.xpi
# set root ownership
chown -R root:root "$PATH_EXTENSION/$UID_ADDON"
chmod -R a+rX "$PATH_EXTENSION/$UID_ADDON"
# end message
echo "Add-on added under $PATH_EXTENSION/$UID_ADDON"
fi
@TheTechOddBug
Copy link

Here http://bernaerts.dyndns.org/linux/74-ubuntu/271-ubuntu-firefox-thunderbird-addon-commandline is mozilla-extension-manager script that can automate installing and removing extensions (local or globally) via command line.

Not available now. Some other source?

Thanks!

@h4b4n3r0
Copy link

h4b4n3r0 commented Feb 22, 2024

From my point of view, sideloading and activating addons is not supported anymore. At least I could not find a way. However, what you still can do is, to add an addon to your firefox profile, but you have to manually activate it at first. This bit of automation makes everything at least a bit nicer.
You can use the following script:

#!/bin/sh
# -------------------------------------------------------
#  Command line script to install 
#  Firefox and Thunderbird add-ons
#  as global extensions available to all users
#
#  Must be run with sudo
#  Depends on unzip and wget
#  Parameters :
#    $1 = URL of extension on https://addons.mozilla.org/
# 
#  26/03/2013, V1.0 - Creation by N. Bernaerts
# -------------------------------------------------------


# -------------------  parameters  ----------------------

# set default add-ons URL base
URL_FIREFOX="https://addons.mozilla.org/firefox/"
URL_THUNDER="https://addons.mozilla.org/thunderbird/"

# set global extensions installation path
# you may have to adapt it to your environment
PATH_FIREFOX="/usr/lib/firefox-addons/extensions"
PATH_THUNDER="/usr/lib/thunderbird-addons/extensions"

# ------------------  Script  --------------------------

# determine if we are dealing with firefox or thunderbird extension
EXT_FIREFOX=`echo "$1" | grep "$URL_FIREFOX"`
EXT_THUNDER=`echo "$1" | grep "$URL_THUNDER"`

# setup global extension path accordingly
if [ "$EXT_FIREFOX" != "" ]; then PATH_EXTENSION=$PATH_FIREFOX
elif [ "$EXT_THUNDER" != "" ]; then PATH_EXTENSION=$PATH_THUNDER
else PATH_EXTENSION=""
fi

# if add-on is recognised, install it
if [ "$PATH_EXTENSION" != "" ]
then
  # download extension
  wget -O addon.xpi "$1"

  ADDON_ID=$(unzip -p addon.xpi manifest.json | grep -Po '"id": "\K[^"]*')
  # to make it a bit more failsafe, you could also use jq:
  # ID=$(unzip -p addon.xpi manifest.json | jq '.browser_specific_settings.gecko.id')
  mv addon.xpi "${PATH_EXTENSION}/${ADDON_ID}.xpi"

  # end message
  echo "Add-on added under $PATH_EXTENSION/$ADDON_ID"
fi

One more hint: To always download the latest xpi from the addon store you can use the following URL:
https://addons.mozilla.org/firefox/downloads/latest/<plugin-name>/latest.xpi

You can identify the plugin name from the URL in the store:
https://addons.mozilla.org/de/firefox/addon/foxyproxy-standard/

E.g .for the foxyproxy plugin you should use "foxyproxy-standard"
https://addons.mozilla.org/firefox/downloads/latest/foxyproxy-standard/latest.xpi

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