Linux — Enable Middle Mouse Button Scrolling on Chrome(-ium) and Electron apps (Discord, etc)

Nikolas Spiridakis
7 min readJul 18, 2022

--

Linux + Chromium + Autoscroll = ?

In this article, I will show you a way I found to enable Middle Mouse Button Scrolling (aka Autoscroll) on Chromium. This works on everything running on Chromium including (of course) the Chrome browser, any Chromium-based browser, and even Electron apps (like Discord, Slack, and many more). I tried to explain it in a very simple way so anyone could understand it.

Table of Contents

TL;DR

Use this flag on Chrome or any Chromium-based browser or app:

--enable-blink-features=MiddleClickAutoscroll

If you don’t understand what this is, keep reading for more details.

If you came here just for the flag please take a moment to star this Chromium Bug so there is a better chance they’ll implement an option in the future instead of having to use flags.

Also if you are interested, you can take a look at the Technical Explanation at the end of the article.

What is Autoscroll?

They say “A picture is worth a thousand words”. I wonder how many a gif is 🤔

Autoscroll in action (on Firefox)

If you have used Windows before, you’ve probably done this. When clicking the middle mouse button you can scroll by just moving the mouse. The further you move the mouse from the original location, the faster it scrolls. Pretty handy!

Why is there no Autoscroll in Linux?

Autoscroll is not a Windows thing; it’s implemented in Firefox and Chrome separately. But on Linux it’s disabled by default. Firefox gives you an option to enable it, but still, it’s disabled by default. Why you may ask?
If you’ve used Linux before and specifically a desktop environment running on X11, you should have noticed that when clicking the middle mouse button, your former selection gets pasted. There is no official way to disable this but there is a workaround later in the article.

Okay, I’m sold; how do I do it?

To do this we need to use what’s called a command line flag. Command line flags are used to tell a program to run with certain settings/parameters. It’s called a command line flag because you specify them through the command line. Don’t worry we won’t use the command line much.

⚠️ Important, before doing anything ⚠️

If you encounter any bugs on the browser/app you added the flag to, make sure to remove it before sending any bug report. This flag is meant to be used only for testing and might cause unpredicted bugs/problems. Remember: we are not supposed to use this feature on Linux!

A little about .desktop files

Applications in most Desktop Environments use .desktop files. You can think of them as shortcuts but they can do a lot more stuff. These are text files and contain (among other stuff) the command that actually runs the application.

The apps you see on your app drawer/menu are just these .desktop shortcuts. Source: Wikipedia

Now we just need to edit the “shortcut” of our app and append the flag. I’ll use Chrome here as an example but you can also do this on everything that’s based on Chromium (Brave, Vivaldi, etc) or Electron (Discord, Slack, etc).

Finding where the .desktop file is

Depending on your installation method the .desktop file could be in one of these 3 locations:

  1. ~/.local/share/applications
  2. /usr/share/applications/
  3. /usr/local/share/applications/

where ~ is your home directory. For the first location, you will need to enable hidden files on your file browser to see it (you can disable it afterward if you want).

A-ha, we found it!

Editing the file

Right-clicking the file and opening it in a text editor (like Gedit or KWrite) will reveal the actual file’s contents.

The Chrome desktop file

.desktop files in browsers are typically big because they contain localizations for every piece of text. We are only interested in the Exec= parts. Use Ctrl+F to find all the Exec= parts and just add the flag at the end of the line. If there is any %something at the end of the line, make sure to put the flag before that. Here is an example:

Before: Exec=/usr/bin/google-chrome-stable %U
After: Exec=/usr/bin/google-chrome-stable --enable-blink-features=MiddleClickAutoscroll %U

The Chrome desktop file after the edits

Save and profit (??)

Now we need to save the file and make sure that all the windows of our browser/app are closed. Depending on your Desktop Environment, you might need to run this little command to “refresh” the shortcuts: sudo update-desktop-database. Then we can just open the app like we normally would. Now Autoscroll should work exactly like Windows!

Final result: Autoscroll working on Chrome. (Note: I do not endorse committing the crime of searching “google” on Google, this is done for demonstration purposes only)

But wait, what’s this big thing that appeared on my browser? Did you hack my computer?

Stability and security will suffer. You sure Chrome?

As scary as it might seem, this message is just informing us that we are using a flag that Chrome (and other browsers/apps) don’t give support for. You see, --enable-blink-features is used by Chromium developers to test upcoming/unreleased features. Autoscroll is technically an unreleased feature since it’s not properly supported on all OSes.

Feel free to dismiss this message. And no, your stability will not suffer, and neither your security. Worst case scenario: you’ll find a bug; you can always disable this by reversing the procedure we just did. The bad news is that this message pops up every time you open the browser and there is no way to disable it (as far as I know).

Why is this thing pasting all over the place??

Why is this thing so broken??

There is one last thing we need to address. If you are using Xorg/X11, you might come across certain situations (like Discord for example) in which if you try to use the scroll wheel button, it will start pasting text. This is actually a feature, not a bug but it gets in the way when trying to use Autoscroll. Unfortunately, there is no official way to disable this on X11 but there is a little program called XMousePasteBlock which attempts to disable it. If you are using KDE make sure to take a look at this issue, you need extra steps to make it work.

Technical Explanation

I’m ending this off with a technical explanation of what this flag exactly does for anyone interested.

Here you can find the exact line on Chromium source code where this feature is disabled for Linux and Mac (actually it’s enabled only for Windows).

The if statement

This if statement just says: “enable this Runtime Enabled Feature if running on Windows”.

According to the Chromium Wiki:

Runtime flags enable Blink developers the ability to control access Chromium users have to new features they implement. Features that are hidden behind a runtime flag are known as Runtime Enabled Features.

Also, we can use command line flags to enable/disable these features:

content provides two switches which can be used to turn runtime enabled features on or off, intended for use during development. They are exposed by both content_shell and chrome.

--enable-blink-features=SomeNewFeature,SomeOtherNewFeature
--disable-blink-features=SomeOldFeature

And this is exactly what we are using here. The actual name of the Blink Flag can be found here:

MiddleClickAutoscroll

This is enabled by default on Windows only. The only part that's
"experimental" is the support on other platforms.

The end

As already mentioned make sure to star this Chromium Bug if you want this to be implemented as an option.

Thanks for reading through the end. I don’t know how I managed to write a 1300+ word article for a single Chromium flag, but I did. Also, this is the first article I ever wrote. Like ever. Make sure to clap (?? I have no idea what you do here) if you found this interesting. Now I feel like a Youtuber. Anyway, have a nice day!

--

--