Getting Chromium-based browsers to a usable state on Wayland

02/04/2023

We all know that Firefox is the way to go when using Linux, but it just so happened that I need to use a Chromium-based browser for work, mostly because Google Docs does not work that well in Firefox. Installing Chrom(ium) on modern Linux is easy, you can just use Flatpak, and install it using a single command.

When you run it, however, you are likely to run into a number of issues:

  1. Hardware decoding does not work for videos
  2. After attempting to enable hardware decoding, videos will stutter and work slowly
  3. Other strange bugs, like sound cutting out when switching away from the browser, or when showing multiple animations ant the same time
  4. Scrolling feels off

All these things can be traced to a small number of incompatibilities and Mesa bugs, which are actualyl quite easy to work around.

First, let’s start with the hardware decoding problem. This can be easily worked around by either switching to X11 from Wayland, which is not acceptable, or doing some configuration changes for the browser. Please note that all examples below will assume that you have Brave installed as your browser, but they should work for any other chromium based browser, and even for stock Google Chrome.

To run the browser from the command line, we can use the following command:

flatpak run com.brave.Browser

To work around the decoding problem, we should set some command line flags that will force the browser to use system VA-API, and will disable GPU driver checks.

--enable-features=VaapiVideoDecoder 
--use-gl=egl 
--enable-features=VaapiIgnoreDriverChecks 
--disable-features=UseChromeOSDirectVideoDecoder,Vulkan

We might also need to forcefully tell the browser which VA-API driver to use. We can do this using an environmental variable:

LIBVA_DRIVER_NAME=iHD

The full command to enable hardware acceleration is thus:

LIBVA_DRIVER_NAME=iHD flatpak run com.brave.Browser \
    --enable-features=VaapiVideoDecoder --use-gl=egl \
    --enable-features=VaapiIgnoreDriverChecks \
    --disable-features=UseChromeOSDirectVideoDecoder,Vulkan

We will also need to disable Wayland support for the browser using, for example, Flatseal. This is because hardware acceleration on Wayland is currently very broken on Chromium-based browsers.

The browser will run like this, but you will most likely notice some strange issues with its behavior. For example, the videos might stop playing when you switch away from the browser window or the browser might become very slow when playing multiple animation in multiple windows at once.

All this can be traced to this Mesa bug, which is actually fixed in the development version, but it’s still not available in distributions and in flatpak. So we will have to work around that.

First, we will need to install a git version of mesa into Flatpak:

flatpak remote-add --user flathub-beta https://flathub.org/beta-repo/flathub-beta.flatpakrepo
flatpak install flathub-beta org.freedesktop.Platform.GL.mesa-git//22.08

22.08 is the version of Mesa currently used by Brave. Then, we will need to use an environment variable to tell flatpak to use the git version of Mesa:

FLATPAK_GL_DRIVERS=mesa-git LIBVA_DRIVER_NAME=iHD flatpak run com.brave.Browser \
    --enable-features=VaapiVideoDecoder --use-gl=egl \
    --enable-features=VaapiIgnoreDriverChecks \
    --disable-features=UseChromeOSDirectVideoDecoder,Vulkan

We might also need to forcefully disable VSync using a command line argument

FLATPAK_GL_DRIVERS=mesa-git LIBVA_DRIVER_NAME=iHD flatpak run com.brave.Browser \
    --enable-features=VaapiVideoDecoder --use-gl=egl \
    --enable-features=VaapiIgnoreDriverChecks \
    --disable-gpu-vsync \
    --disable-features=UseChromeOSDirectVideoDecoder,Vulkan

When run like this, the browser should behave normally and everything should work. You can confirm that hardware decoding for videos is used by going to youtube and using intel_gpu_top to observe the GPU load.

The only problem left is the scrolling. This is a longstanding issue in Chromium, and there are multiple workarounds available. For me, the simlest and best one is install an extension that will fix the scrolling speed, for example this one: https://chrome.google.com/webstore/detail/linux-scroll-speed-fix/mlboohjioameadaedfjcpemcaangkkbp. What I also do is enable the flag Windows Scrolling Personality. These 2 things together make the overall experience very tolerable with both the mouse and touchpad.

With this, your browser should be just as useful as on any other platform. I hope that these issues will be fixed at one point, and that all these workarounds will not be needed at all.