Guide to screensharing on Sway from Firefox/Chromium

I spent some time trying to get things to work and in the end I decided to compile the instructions in a compact and coherent guide.

  1. Install Chromium 81.0.4044.122 or later, or Firefox 84.0-1 or later.
  2. Install pipewire, and if you’re using Chromium, libpipewire02 as well. If you’re using Arch, both packages are available in the official repositories.
  3. Install xdg-desktop-portal-wlr. It is available in the official Arch repositories.
  4. If you’re running Firefox, make sure that MOZ_ENABLE_WAYLAND=1 is set before you start it to make sure it’s running natively. If you’re using Chromium, start it with the following flags, for the same reason: chromium --enable-features=UseOzonePlatform --enable-gpu --ozone-platform=wayland.
  5. If you’re running Chrome, enable enable-webrtc-pipewire-capturer in chrome://flags.
  6. Make sure that the environment variables XDG_SESSION_TYPE=wayland and XDG_CURRENT_DESKTOP=sway are set and exported - it doesn’t work without them.
  7. From the shell, run: $ /usr/lib/xdg-desktop-portal -r & /usr/lib/xdg-desktop-portal-wlr. This will run the former as a background job, so don’t close your shell.
  8. Run your browser.
  9. Profit, screen sharing should now work (I tested it in both FF and Chromium and it works on discordapp.com). You can also test if it works here.