Firefox

From postmarketOS Wiki
Alt text
Firefox running on Phosh with mobile-config-firefox

postmarketOS ships the desktop version of Firefox as default in Phosh and Plasma Mobile, the mobile and privacy friendly configuration from mobile-config-firefox. To remove this configuration, uninstall the mobile-config-firefox package.

Installation

Depending on the user interface you have installed, Firefox is already part of your postmarketOS installation (e.g. in Phosh and Sxmo). For others, install the following two packages:

$ sudo apk add mobile-config-firefox firefox-esr

Instead of firefox-esr, you can also install firefox to get the slightly newer version (but be aware that sometimes it includes changes that break the mobile configuration, and we need a bit to catch up with it. Help with that is of course always appreciated).

Tips and Tricks

Scale and keyboard on wayland desktop environments

Some desktop environments do not set the env variable MOZ_ENABLE_WAYLAND. As a workaround, you can replace the default Firefox launcher with a custom one.

These commands will create firefox wrapper, which will run firefox with wayland and firefox launcher (icon in menu)

mkdir -p ~/.local/bin/
echo '#!/bin/bash'\n'MOZ_ENABLE_WAYLAND=1 firefox-esr $@' > ~/.local/bin/firefox-esr-wl
chmod +x ~/.local/bin/firefox-esr-wl
mkdir -p ~/.local/share/applications/
cp /usr/share/applications/firefox-esr.desktop ~/.local/share/applications/
sed -i 's/Exec=firefox-esr/Exec=firefox-esr-wl/g' ~/.local/share/applications/firefox-esr.desktop

Run it, then relogin

Webapps

Warning: This no longer works on recent versions of postmarketOS (including stable releases) because Firefox has removed support for the site specific browser mode. You can, though, replace --ssb with --kiosk to achieve a similar result in certain sites. (--kiosk opens websites in kiosk-mode which is the same of a normal browsing session but without the browser UI (Menus,Url-bar,toolbar etc. etc). Some sites do not react well, and it is suggested to memorise the keyboard shortcuts of Firefox, especially the one for closing the active tab and for going backward/forward )

To create webapps for use with Firefox, the following shell script can be used. It generates a separate Firefox profile for isolation, and adds a desktop entry that opens the corresponding site as a single-site browser (without a url-bar).

#!/usr/bin/env bash
# Create firefox profile
set -e
name=$1
url=$2
# Ugly, copy-pasted from SO
simple_name=$(echo "$name" | awk '{print tolower($0)}' | sed 's/ //g')
echo "Creating webapp $name, using $url."

firefox -CreateProfile $simple_name
profile_dir=$(find ~/.mozilla/firefox/ -maxdepth 1 | grep $simple_name)
echo 'user_pref("browser.ssb.enabled",true);' > $profile_dir/user.js

# Create desktop entry
cat >~/.local/share/applications/$simple_name.desktop <<EOL
[Desktop Entry]
Exec=firefox -P $simple_name --ssb $url
Icon=/home/user/.local/share/applications/$simple_name.png
Type=Application
Terminal=false
Name=$name
StartupNotify=true
StartupWMClass=firefox
EOL

# Get icon
wget $url/favicon.ico -O /tmp/favicon.ico
convert /tmp/favicon.ico /tmp/favicon.png
mv /tmp/favicon.png .local/share/applications/$simple_name.png ||
mv /tmp/favicon-0.png .local/share/applications/$simple_name.png
rm /tmp/favicon*.png

Save this script as /add-webapp.sh, and mark it as executable. Running the command ./add-webapp.sh "Hacker News" "https://news.ycombinator.com" will create a launcher shortcut to Hacker News.

Harware accelerated rendering

To make firefox on pinephone/pinetab/pb/pbp smoother you need to change layers.acceleration.force-enabled to true in about:config. To ensure that it kicked in check about:support, graphics->compositing should become OpenGL.

From Firefox 93, the legacy hardware acceleration layers have been disabled and only webrender is allowed. Webrender requires gles 3 to be able to use hardware acceleration, otherwise it will use "software webrenderer". Since Pinephone does not support gles3, from Firefox 93, the browser experience has become much worse because everything is software rendered. Fortunately firefox-esr (available from repositories and on par with security updates as the latest version) is still at v 91.6, so it is still possible to use legacy hardware acceleration layers. They are not enabled by default, to do it there is need to change two parameters in about:config, that are layers.acceleration.force-enable to true and gfx.webrender.force-disabled to true.

Hide tabs toolbar and navbar

Open firefox, search and install Panorama View addons (or whatever tabs view addons). Enter URL about:support, choose Open Directory at Profile Directory. Edit chrome/userChrome.css(if it doesn't exist, you can create one)

Tabs Toolbar and navbar on top screen:

/* Hide tabs toolbar on top*/
#TabsToolbar {
   visibility: collapse !important;
}

/* Hide navbar on top*/
#nav-bar {
  /* customize this value. */
  --navbar-margin: -30px;

  margin-top: var(--navbar-margin);
  margin-bottom: 0;
  z-index: -100;
  transition: all 0.3s ease !important;
  opacity: 0;
}

#navigator-toolbox:focus-within > #nav-bar,
#navigator-toolbox:hover > #nav-bar
{
  margin-top: 0;
  margin-bottom: var(--navbar-margin);
  z-index: 100;
  opacity: 1;
}

Tabs Toolbar and navbar on bottom screen:

/* Hide tabs toolbar on bottom*/
#TabsToolbar {
   visibility: collapse !important;
}

/* Hide navbar on bottom*/
#nav-bar {
  /* customize this value. */
  --navbar-margin: -30px;

  margin-top: 0;
  margin-bottom: var(--navbar-margin);
  z-index: -100;
  transition: all 0.3s ease !important;
  opacity: 0;
}

#navigator-toolbox:focus-within > #nav-bar,
#navigator-toolbox:hover > #nav-bar
{
  margin-top: var(--navbar-margin);
  margin-bottom: 0;
  z-index: 100;
  opacity: 1;
}

Customize Toolbar to edit Panorama View first icon showing on navigation bar.

Mobile friendlier layout

Alt text
Firefox running on Sxmo with user0 script

First we need to get bash support:

sudo apk add bash

Then we remove the standard solution:

sudo apk del mobile-config-firefox 

Grab user0`s script from codeberg, make it executable and run it (make sure to select "Add Recommended Preferences"):

git clone https://codeberg.org/user0/Mobile-Friendly-Firefox.git
sudo chmod +x Mobile-Friendly-Firefox/install.sh
bash Mobile-Friendly-Firefox/install.sh

Select the desired setting.


Remove Items from URL Bar

Long click onto the item and select remove.

Force Website Mobile

Some websites do not show in mobile version and are then hard to read. Press:

 ctrl + shift + m 

and select iphoneSE layout on top left.

Policies and other search engines

By default, mobile-config-firefox adds a policies entry to get rid of invasive stuff. While this is a great idea it my cause some trouble for users living in non-free countries.

To enable google search engine, you can edit:

./etc/firefox/policies/policies.json

See the original file here.

Be aware that, in a free country, it makes sense to avoid google.com as search engine and at least use startpage, 4get, SearxNG, Whoogle, or any other search which does not expose your privacy.

"I need privacy, not because my actions are questionable, because the judgement and intentions of institutions and governments are questionable"

Hide Search Results

To get rid of certain websites appearing as search results, create a uBlock origin rule with the help of https://letsblock.it/filters/search-results

Copy the generated file to My Filters on uBlock dashboard

See also