/firefox-omni-tweaks

A script that disables the clickSelectsAll behavior of Firefox, and more.

Primary LanguageShellMIT LicenseMIT

Firefox omni.ja tweaks

A script that directly edits the internal Firefox files stored in the omni.ja and browser/omni.ja archives to customize the behavior of Firefox such as disabling clickSelectsAll, copying automatic URL bar selection to clipboard, etc.

Where does this script work?

The script works for me. 😉 And I’m running Firefox Nightly on Arch Linux. This is the software setup that I’ve tested — it may work for other setups, too, and this script is likely to work with later versions as well:

  • Firefox Nightly 91.0a1 (2020-07-01) through 91.0a1 (2021-07-06) (64-bit)

Note: the versions will only be updated for substantial changes to the script.

How to run the script?

The script applies changes to a specific Firefox install path; it needs to be executed after each update of that Firefox install path. It should not be executed a second time before another Firefox update.

The script automatically modifies the omni.ja file and the browser/omni.ja file, and clears the browser’s startup cache and creates a .purgecaches file, in order to assure that the changes are properly applied when starting Firefox.

This step-by-step guide describes default script execution, i.e. without any options passed; you can pass options listed below.

Also see my Super User answer for detailed steps.

Before using the script for the first time

  1. Download the script.
  2. Set the script as a runnable file.

Before running the script

  1. Update Firefox and start Firefox so it installs all the updates properly.
  2. Close Firefox.

Running the script

  1. Execute the script.

    • Interactively: Either click it in your file manager, then click the “Run in terminal” button, or run it directly as e.g. bash ./fixfx.sh.
    • Non-interactively: Click it in your file manager, then click the “Run” button.

    Interactive execution is recommended.

  2. The script should find your Firefox (and Firefox ESR) install path(s) automatically. If multiple viable paths are found, you can select the one you want to fix. If no paths are found, you can either

    • call the script with the --firefox option, specifying the Firefox install path, or
    • edit the script and put the correct path where it says Fallback path (near the top of the script).

    The correct path contains a browser directory with an omni.ja in it.

  3. The script checks if you have write access to all relevant directories: the Firefox install path, the backup path, and /tmp, where the unzipping happens. If not, you’ll be asked to enter your root password. You can also run the script with sudo instead.

  4. A backup of the internal application resources (omni.ja and browser/omni.ja) of your Firefox installation is created (in /tmp, by default).

  5. After a few moments, you should be able to launch Firefox normally. If everything went well, you should now be able to launch a Firefox with an improved user experience! Press Enter to exit.

  6. However, if Firefox won’t run properly, close Firefox, and restore the backup by typing r and Enter. The backup will be restored and the script will exit. Start Firefox again to go back to normal.

Let me know if something went wrong by creating a new issue. Provide details about terminal output, your system setup, and your software versions.

Since this script partially relies on Firefox making sure to use the newly changed omni.ja and browser/omni.ja, as opposed to a cached version of these files, additional care must be taken to make issues reproducible. See the wiki about the startup cache to gain insight into the cache clearing mechanism.

You may some day receive a warning about a pattern failing to match due to the original Firefox code having changed. Please report these warnings as well.

Restoring the backup

The script offers an opportunity to test Firefox and restore the backup in case something went wrong. It also tells you which file paths are being used and tells you the command lines for restoring the backup, if not already applied.

If you need to restore the backup later on, you can type commands into the terminal which are based on the following snippet. Check if you need to run this as root, and double-check the file paths.

firefox_dir=$(whereis -b firefox | cut -d ' ' -f 2)          # Or put the correct path here, like the `Fallback path` line in the script.
                                                             # `cut -d ' ' -f 2` just takes the first path found, which may not be the right one.
cp -p /tmp/omni-n.ja~ "$firefox_dir/omni.ja"                 # Replace `n` by the incremental number of the backup file name.
cp -p /tmp/browser_omni-n.ja~ "$firefox_dir/browser/omni.ja" # Replace `n` by the incremental number of the backup file name.
touch "$firefox_dir/browser/.purgecaches"                    # This is necessary only here. A "$firefox_dir/.purgecaches" is ignored.

Options in detail

As usual, short options can be combined, e.g. -qb '/tmp' which expands into -q -b '/tmp'. A -- marks the end of options, meaning every option after that will be ignored. There are no positional arguments for this script, so in fact, after --, everything is ignored.

  • -f DIR, --firefox DIR

    Picks DIR as the Firefox install path that is to be fixed.

    Note that DIR must include a browser/omni.ja file. If this validation fails, the script terminates.

    Omit this option to let the script find all firefox or firefox-esr paths on your system, validate them, and pick the one directory that is found. If more than one viable directory is found, the script will ask for selection of a specific directory (unless -q or --quiet is passed).

  • -o FIX_OPTION, --option FIX_OPTION

    Choose which functionality you want to change in the internal files. This flag can be used multiple times.

    FIX_OPTION can have a few different forms:

    • To turn the option yourOptionHere off, use yourOptionHere= (e.g. --option preventClickSelectsAll= or -o preventClickSelectsAll=). This sets the option entry’s value to an empty string, which acts as a false value in Bash.
    • To turn the option yourOptionHere on, just type yourOptionHere by itself, or with any other substring after = (e.g. -o preventClickSelectsAll or -o preventClickSelectsAll=true).
    • To supply a custom value, use yourOptionHere=yourValueHere.

    To supply multiple option settings, use the flag multiple times (e.g. -o optionA= -o optionB).

    See the available options below. Unrecognized options are ignored.

  • -b DIR, --backup DIR

    Stores backup of internal Firefox files omni.ja and browser/omni.ja in DIR.

    DIR must either point to an existing directory, or its parent directory must exist. DIR pointing to anything other than a directory is not allowed. One directory is automatically created if not yet existing.

    Incremental files like omni-0.ja~, omni-1.ja~, etc., and browser_omni-0.ja~, browser_omni-1.ja~, etc. are created within that directory.

    Omitting this option defaults to backups being stored in /tmp.

  • -q, --quiet

    Only errors (specifically, anything echo’d to STDERR) will be logged. Normal (STDOUT) output will be suppressed. This will also suppress asking for confirmation.

    By default, output will be emitted, but if the script was not executed in an interactive terminal, all interactive selections or confirmation questions are suppressed, regardless of whether the --quiet option was passed or not. If confirmation questions are suppressed and the script finds more than one viable Firefox install path, it will automatically pick the most recently updated one. Note that these tests aren’t perfect and that they can break using some file descriptor redirection, but it should cover most basic cases of executing this script.

  • -h, -?, --help, --?

    If this option is present, the help information is printed, and the script exits. The help text contains contextual information such as the path name of the script source, the default options, etc.

Available options

Option flag Default Description
--option autoCompleteCopiesToClipboard Off Enables selection clipboard as described in autoSelectCopiesToClipboard; also enables copying selection in URL bar triggered by typing a URL which is known by the browser (e.g. typing gi may autocomplete github.com, and the part thub.com is selected; the option enables automatically copying this selection to the clipboard). The option autoCompleteCopiesToClipboard requires autoSelectCopiesToClipboard to be set and is ignored without it.
--option autoSelectCopiesToClipboard Off

Certain actions trigger an automatic selection of text in the URL bar or the search bar which aren’t considered user-initiated and as such are not added to the selection clipboard (e.g. selected text which can be inserted with middle-click on Linux) — see Bugzilla Bug 1653191.

This option enables clipboard selection for most cases: Ctrl+L or F6 for URL bar selection; Ctrl+K for search bar selection; Esc to restore the original URL; Tab to focus either URL bar or search bar; or single-click or double-click selecting the entire text — if enabled.

However, additional options must be passed if selection triggered by a tab switch should also be copied (tabSwitchCopiesToClipboard), and if selection triggered by URL auto-complete should be copied (autoCompleteCopiesToClipboard).

--option doubleClickSelectsAll Off Double-clicking the URL bar or the search bar selects the entire input field.
--option preventClickSelectsAll On Clicking the URL bar or the search bar no longer selects the entire input field.
--option secondsSeekedByKeyboard=number Pressing or in the built-in video player (including Picture-in-Picture mode) seeks by number seconds. Fixes Bugzilla Bug 1668692 which asks for the seek interval to be changed from 15 seconds to 5 seconds. The equivalent option would be -o secondsSeekedByKeyboard=5.
--option tabSwitchCopiesToClipboard Off Enables copying selection in URL bar triggered by switching to a tab with a focused URL bar (with either clicking or with Ctrl+(Shift)+Tab, Ctrl+Page Up, Ctrl+Page Down, Alt+1..9, and possibly other ways). The option tabSwitchCopiesToClipboard requires autoSelectCopiesToClipboard to be set and is ignored without it.

Examples

We’ll assume that the script is callable via ./fixfx.sh. The exact path and file name depends on where you placed the file.

  • The following command fixes a specific Firefox installation located under /usr/lib/firefox-de_DE and creates an incremental backup of the original omni.ja in /tmp. The specified directory must contain a browser/omni.ja.

    ./fixfx.sh --firefox /usr/lib/firefox-de_DE
  • This command fixes an automatically determined Firefox installation, while creating a backup of omni.ja and browser/omni.ja in the specified directory. The file names are incremental, e.g. omni-0.ja~, omni-1.ja~, etc.

    ./fixfx.sh -b /home/user/backups/my_firefox_backups
  • This command enables the behavior where double-clicking a URL bar selects the entire URL, but not a single click.

    ./fixfx.sh -o preventClickSelectsAll -o doubleClickSelectsAll

    If you want both click behaviors and preventClickSelectsAll is the default in your script (see ./fixfx.sh -h to check), use this instead:

    ./fixfx.sh -o preventClickSelectsAll= -o doubleClickSelectsAll

Exit status

The script distinguishes between four different status codes when exiting. Error codes (i.e. status codes greater than 0) are usually accompanied by an error message printed to STDERR.

  • 0 for success: everything went as expected, the script terminated successfully.
  • 1 for general failure due to utilities used in the script: e.g. some file was not found, some directory could not be created, directory navigation failed, unzipping or zipping the omni.ja failed, read or write permissions could not be granted, etc.
  • 2 for incorrect script usage: e.g. --backup, --firefox, or --option used without values, the specified Backup directory isn’t an existing directory, the specified Firefox path is not a valid Firefox path, etc.
  • 130 if the script process was terminated (e.g. via Ctrl+C) or killed.

A brief history of the scope of this repository

See this answer on Super User for full context and an explanation of the script. The repo’s URL used to be https://github.com/SebastianSimon/firefox-selection-fix.

Various browsers have started adopting a particular behavior when clicking the address bar: the entire URL is selected. This goes against good UX practices. In Firefox, there used to be the preferences browser.urlbar.clickSelectsAll, browser.urlbar.update1, and browser.urlbar.update2 to control this behavior and other updates, but the latter two were always expected to be temporary.

Around March 2020, the browser.urlbar.clickSelectsAll preference has been removed. Since then, this bug has been under discussion, where a patch has been suggested — this would involve recompiling Firefox from scratch. As the clickSelectsAll doesn’t work” duplicates accumulate on Bugzilla to this day, one of these has received a comment by Stephen McCarthy which describes a workaround that involves editing internal Firefox files. This workaround looks like the simplest approach, but the approach didn’t work as-is.

This repo provides a script that attempts to give us users the browser.urlbar.clickSelectsAll = false experience back.

I realized the potential of this script: it could also be used to change any aspect of Firefox’s behavior, not just this selection behavior. Indeed, several months later, some users have requested a few other features, so I started including new features and customization options. Since then, the repo has been renamed to its current name.