SebastianSimon / firefox-omni-tweaks

A script that disables the clickSelectsAll behavior of Firefox, and more.
MIT License
43 stars 8 forks source link
firefox url-bar ux workaround

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. This also applies to Firefox ESR.

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:

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

How to run the script?

The script applies changes to a set of Firefox install paths; it needs to be executed after an update of the Firefox install paths. It should not be executed a second time before another Firefox update.

The script automatically modifies the omni.ja files and the browser/omni.ja files, and clears the browsers’ startup caches and creates .purgecaches files, 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 presets or options passed. You can use the web app to choose custom presets for the script or 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 from the original source.
  2. Set the script as a runnable file.

Before running the script

  1. Update all Firefox browsers you want to fix and start each Firefox browser so they install all the updates properly.
  2. Close all Firefox browsers you want to fix.

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 (i.e. running in background; no terminal shown).

    Interactive execution is recommended.

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

    • call the script with the --firefox option, specifying the Firefox install paths, or
    • use the web app to download a version of the script with the paths specified in the presets.

    The correct paths contain an omni.ja file, as well as a browser directory with another omni.ja file in it.

  3. The script checks if you have write access to all relevant directories: the Firefox install paths, 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. All specified Firefox paths are processed:
    1. A backup of the internal application resources (omni.ja and browser/omni.ja) of your Firefox installation is created (in /tmp, by default).
    2. After a few moments, you should be able to launch the processed Firefox browser normally. If everything went well, you can now test your browser with an improved user experience! Press Enter to exit.
    3. However, if the Firefox browser won’t run properly, close Firefox, and restore the backup by typing r and Enter. The backup will be restored. Start Firefox again to go back to normal.
    4. Repeat for the next Firefox path; at the end, the script will exit.

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 `firefox_dir=/usr/lib/firefox`.
                                                             # `cut -d ' ' -f 2` just takes the first path found, which might 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.

Using the web app

The web app lets you choose all the options and tweaks that you want and put them into a customized shell script as presets.

Once you’ve downloaded the customized script, set it as a runnable file, make sure Firefox is up-to-date and closed, and then run the script (steps 2, 3, and 4). The script should then run exactly as specified. You can make sure if the presets are set correctly: they’re in the settings array between # Begin presets. and # End presets..

You can theoretically still pass command line options to the script; these will get additionally applied. For example, if you specified a firefoxDirs|0 in the web app, passing another -f directory will add it as firefoxDirs|1. Opt-in options such as -q, -a, or -y cannot be disabled once they’ve been enabled. A -b or -o option is overridden by a later instance of the same option.

Running the web app

If you fork this repo, the web app can be served using a simple HTTP server, e.g. http-server from NPM.

Options in detail

As usual, short options can be combined, e.g. -qyab '/tmp' which expands into -q -y -a -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.

Interaction between -a, -f, -q, and -y

Based on the options passed to the script, the script will first collect certain Firefox paths (e.g. the specified ones from -f, or the automatically found ones), then filter them (e.g. the most recent modification date using -y, or all of them). The script will only process the filtered set of Firefox paths.

-y passed -a passed -f passed Collection Filter (resulting set)
➕ Automatically found If interactively executed and -q not passed and more than one path found, prompt user to choose which paths to process. Otherwise, process all.
✔️ ➕ Specified All
✔️ ➕ Automatically found All
✔️ ✔️ ➕ Automatically found
➕ Specified
All
✔️ ❌ or ✔️ ➕ Automatically found Only youngest
✔️ ✔️ ➕ Specified Only youngest
✔️ ✔️ ✔️ ➕ Automatically found
➕ Specified
Only youngest

Available options

Option flag Default Description
--option autoCompleteCopiesToClipboard Off This option requires autoSelectCopiesToClipboard to be set and is ignored without it. This option additionally enables copying selection in the 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).
--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 the wiki entry.

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 clearSearchBarOnSubmit Off Submitting a search from the separate search bar clears it. There’s discussion about this feature on Super User and on Bugzilla.
--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. Bugzilla Bug 1668692 already changed this from 15 seconds to 5 seconds, but still didn’t offer an easily accessible option to change this duration.
--option tabSwitchCopiesToClipboard Off This option requires autoSelectCopiesToClipboard to be set and is ignored without it. This option additionally 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).

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.

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.


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.