Search code examples
javalinuxfirefox

How to solve or suppress Gtk-Warnings when opening a website in Java?


I am currently working on a larger project but was able to pin point my problem to one line:

java.awt.Desktop.getDesktop().browse(new URI("https://google.com"));

When attempting to open a website using the java.awt.Desktop class in Java, such as Google, the following GTK warning is printed to my console twice. How do I solve or suppress this warning?

[146880, Main Thread] WARNING: GTK+ module /snap/firefox/4090/gnome-platform/usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so cannot be loaded.
GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.: 'glib warning', file /build/firefox/parts/firefox/build/toolkit/xre/nsSigHandlers.cpp:187

(firefox:146880): Gtk-WARNING **: 21:05:50.793: GTK+ module /snap/firefox/4090/gnome-platform/usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so cannot be loaded.
GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.
Gtk-Message: 21:05:50.793: Failed to load module "canberra-gtk-module"
  1. I followed this post and attempted to resolve the issue by installing, removing, and reinstalling the module, but the warning persists.
  2. I started and tried to suppress the warning, but I have not found any option in Firefox to disable the warning.
  3. Additionally, the command export GTK_MODULES=gail:atk-bridge did not successfully suppress the Gtk warning generated by Firefox.
  4. I also tried redirecting the standard error stream using System.setErr(new PrintStream(new FileOutputStream("/dev/null")));, but this did not resolve the issue.

Ubuntu 22.04.4 LTS Firefox 124.0.2 (64-bit)

Any idea is appreciated.


Solution

  • Like mentioned by yvs2014 the message only occurs when installing Firefox via snap, like in my case, and probably when installing via flatpak. To solve the problem simply follow the official download provided by Mozilla and use .deb.

    Caution: Remember to back up your settings, passwords, profiles, etc. before reinstalling.