Timing/race condition with Xwayland-on-demand breaks firefox & confuses gedit etc
Tested versions
- Ubuntu Desktop 22.04 LTS / mutter 42.2-0ubuntu1
- Ubuntu Desktop 22.10 pre-release / mutter 43.0-1ubuntu1
- Fedora Workstation 36 / mutter 42.5-1.fc36
(all are "bad")
Bug summary
On the Ubuntu reddit: "Firefox 102.0 snap in Ubuntu 22.04 launches to black screen", meaning a black window. Reported by 3 unique users.
Firefox bug 1788205 "black window when launched". Robert Mader suggests reporting to mutter.
Ubuntu bug 1987976 "firefox black window". This bug affects 4 people
I have access to a machine where this happens every time. Starting Firefox after logging in shows a black window. It can be worked around by quitting and restarting Firefox.
The bug requires Firefox to be using Xwayland, i.e. X11 protocol inside a Wayland session. This appears to be the default when running non-nightly versions of Firefox under Ubuntu. I don't know why.
I believe the bug is sensitive to timing. I found it much harder to reproduce on a newer machine, which was probably a faster machine.
If, instead of running Firefox, I run "GDK_BACKEND=x11 gedit" ? Then gedit does not show a black window. However, it incorrectly draws larger window borders with square corners. I don't know how to attach a screenshot here. Here is a screenshot of the gedit issue, but it is hosted on the Firefox bugzilla.
Steps to reproduce
Here are the steps I used, on the somewhat faster machine.
1. Create a file "~/.local/share/applications/firefox2.desktop", with the following contents
[Desktop Entry]
Version=1.0
Name=Firefox Web Browser 2
Exec=/bin/bash -c "WAYLAND_DISPLAY='' firefox"
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=firefox
Categories=GNOME;GTK;Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;video/webm;application/x-xpinstall;
StartupNotify=true
StartupWMClass=firefox
2. Open the GNOME application menu, and find "Firefox Web Browser 2". Right click and pin it to the dash / add it as a favourite / whatever your GNOME flavour calls it.
3. If you are in a virtual machine, remove the package "spice-vdagent". In a virtual machine, I believe this package activates Xwayland at login, and will suppress the bug.
4. Log out.
5. Log in.
6. Immediately click on the "Firefox Web Browser 2". This might require a quick hand and/or a mouse. Inside a virtual machine, you may be able to pre-position the mouse cursor.
What happened
A black window appears. It stays black.
What did you expect to happen
A usable firefox window appears, after a short delay.