Home | Blog | Previous LegacyFox

Coaxing modern Firefox into running legacy Extensions

This is a bonus to the LegacyFox blog post—read that one first.

The stubborn way

If for some reason (like wanting to use your distribution's prepackaged Firefox) this won't cut it for you, there is a more elaborate and less reliable way. This method also worked with regular (non-ESR) versions of Firefox up to v64[1], but using such an outdated browser is not recommended. In June 2019, two high-risk security vulnerabilities have been disclosed, so yeah.

First off: This is a stupid idea. Mozilla prevents you from doing this for good reasons. But here we go:
Let's start off by setting some values in about:config. There is a file that we can use to automatically set them for us. It is located in Firefox's profile directory, which is usually in ~/.mozilla/firefox/, followed by a random string of characters. If you've got more than one, have a look at profiles.ini; one should have Default=1 set.

~/.mozilla/firefox/$PROFILE_NAME/user.js
user_pref("extensions.legacy.enabled", true);
user_pref("xpinstall.signatures.required", false);
user_pref("app.update.enabled", false);  // would override our patched omni.ja

Then we need to patch omni.ja[2], a zip archive that contains much of Firefox' runtime Javascript. In it, there are a bunch of configuration options, including the flag that checks, if you're allowed to enable legacy extensions.

patch-firefox.sh
#!/bin/sh -ex
FIREFOXDIR=/usr/lib64/firefox/  # must be absolute!
TEMP_OMNI=/tmp/omni

rm -rf "$TEMP_OMNI"
mkdir "$TEMP_OMNI"
cd "$TEMP_OMNI"

# unzip will complain about the archive, so ignore exit code
unzip -q "$FIREFOXDIR/omni.ja" ||:

# ALLOW_LEGACY's values is two lines below; hence 'n;n'
sed -i '/MOZ_ALLOW_LEGACY_EXTENSIONS/{n;n;s/false/true/}' \
  modules/AppConstants.jsm

zip -qr9XD "$TEMP_OMNI.ja" -- *

sudo cp "$FIREFOXDIR/omni.ja" "$FIREFOXDIR/omni.ja.bak"
sudo mv "$TEMP_OMNI.ja" "$FIREFOXDIR/omni.ja"

You'll have to run this script after every Firefox update, preferrably automatically. Make sure, the path in FIREFOXDIR is correct for your distribution. A big shout-out to Akkana Peck, on whose code this is based on.

This will let your old add-ons run again, but chances are, they rely on some of Gecko's APIs, which may have been removed and some changes to them might be required. Mozilla won't sign legacy extensions for you any more, so you'll need to persuade Firefox somehow. So we need to disable Add-on signing. This comes courtesy of a user on "Hacker" "News"[4]. I'm too lazy to incorporate this into the above script (patches welcome!), and I'm not sure if you'll need all those scripts to do it, but it works for me™. Depending on your distro, the paths may vary slightly.

/usr/lib64/firefox/config.js
// keep this comment
try {
  Components.utils
    .import('resource://gre/modules/addons/XPIDatabase.jsm', {})
    .XPIDatabase['SIGNED_TYPES'].clear();
} catch (ex) {
  Components.utils.reportError(ex.message);
}
/usr/lib64/firefox/defaults/pref/config-prefs.js
pref("general.config.obscure_value", 0);
pref("general.config.filename", "config.js");
pref("general.config.sandbox_enabled", false);

Footnotes

I hate footnotes. But I won't bore/distract/confuse you with my (attempt at) snarky humour, unless you really want me to. Press your user agent's hotkey for window.history.back() to get back to where you were coming from.