Enabling a Native File Dialog for Firefox on Plasma Desktop

May 19, 2020, 4 p.m.

Firefox is an excellent browser with many useful and innovative features that is created by an organization that respects and strives to protect its users' privacy. It is also a GTK based application which means that it will use GTK elements in dialog windows for browsing files to upload to a website or to save files to the computer from a website. Plasma users would prefer to have native Qt/KDE Frameworks based file dialog windows.

Unfortunately, no distribution except openSUSE provides a modified version of a Firefox package that uses native Plasma file dialogs. This article describes a procedure to make the needed modification ourselves.

Introduction

Firefox being a GTK based program uses GTK resources in displaying a file dialog, something that is limiting to Plasma users that value all of the features that Qt/KDE Frameworks provides in its file dialog. Fortunately it is possible to easily modify this behavior by using xdg-desktop-portal and its KDE specific auxiliary xdg-desktop-portal-kde and launching Firefox with a specific environment variable.

openSUSE describes its xdg-desktop-portal as:

A portal frontend service for Flatpak and possibly other desktop containment frameworks. xdg-desktop-portal works by exposing a series of D-Bus interfaces known as portals under a well-known name (org.freedesktop.portal.Desktop) and object path (/org/freedesktop/portal/desktop). The portal interfaces include APIs for file access, opening URIs, printing and others.

Before describing the procedure, two sets of screenshots are displayed below that illustrate the difference between the Firefox file dialog without the modification.

Default Behavior of Saving a File in Firefox
Notice the windows related to saving a file use GTK.
Click on any of the thumbnails to view a slideshow of the images.

The screenshots above depict the file dialog opened by Firefox without the modification.

Modified Behavior of Saving a File in Firefox
After the the modifications described below, the Firefox opens file related dialog windows using Qt and KDE Frameworks.
Click on any of the thumbnails to view a slideshow of the images.

The screenshots above depict the file dialog opened by Firefox with the modification.

Procedure

  1. Install the dg-desktop-portal and xdg-desktop-portal-kde packages on the system, if they are available on the distribution you are using. The second is necessary for the Qt/KF native dialog for GTK applications running in Plasm. Both are available in Arch, Ubuntu, Fedora, and openSUSE.
  2. Edit the Exec line of Firefox's .desktop file at /usr/share/applications/firefox.desktop so that it is run with the value of the environment variable GTK_USE_PORTAL set to 1. Replace the line
    Exec=/usr/lib/firefox/firefox %u
    with
    Exec=GTK_USE_PORTAL=1 /usr/lib/firefox/firefox %u
  3. If you used a procedure similar to Installing Multiple Versions of Firefox Including Multiple Profiles to to also install Firefox Beta and/or Firefox Developer Edition, then change the Exec line in /usr/share/applications/firefox-beta.desktop and /usr/share/applications/firefox-developer-edition.desktop also to read:
    Exec=GTK_USE_PORTAL=1 firefox-beta -P beta %u
    and
    Exec=GTK_USE_PORTAL=1 firefox-developer-edition -P developer-edition %u
  4. Make a backup of the modified Firefox desktop file so that when an update overwrites it, the backup can be copied over the distribution updated desktop file, after comparing the two and making changes as needed.

The desktop file before the modification is shown in the next screenshot.

The Firefox .desktop File

The desktop file after the modification is shown in the next screenshot.

The Modified Firefox .desktop File

References

Reddit post that briefly describes the procedure.

Conclusion

No distribution I have tried except openSUSE, even those that are specifically Plasma focused or provide a Plasma based edition, such as Fedora KDE Spin or Kubuntu, provide a Firefox package that uses a native Plasma filed dialog. Fortunately, it is simple for end users to make the necessary modifications.