Repository: electron
Issue: [Bug]: Linux: Double actions when handling app-command handlers: browser-backward and browser-forward #18322 
Labels: platform/linux,bug :beetle:,has-repro-gist,20-x-y

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

Confirmed to impact these versions:

**v16, v17.0.0, v20.1.0, v30.5.1, v31.6.0, v32.1.2**

Probably impacts all versions in between.

### What operating system are you using?

* Linux (NixOS, Ubuntu) - [testcase gist](https://gist.github.com/LunNova/a4c61b7082d17b8aa637217f763348bf) results in handling of app commands on both button down and button up
* Window - [testcase gist](https://gist.github.com/LunNova/a4c61b7082d17b8aa637217f763348bf) works as expected moving back/forward once per press

### Operating System Version

 Linux lun-hisame-nixos 5.15.19-xanmod1-tt #1-NixOS SMP PREEMPT Tue Jan 1 00:00:00 UTC 1980 x86_64 GNU/Linux  
Linux lun-hisame-nixos 6.11.0 #1-NixOS SMP PREEMPT_DYNAMIC Sun Sep 15 14:57:56 UTC 2024 x86_64 GNU/Linux  
Multiple distros and downstream apps relying on Electron reported in the comments.

### What arch are you using?

x64, aarch64

### Last Known Working Electron version

4

### Expected Behavior

When pressing back/forward mouse buttons on linux, either app command events should be created OR they should be automatically handled and cause navigation.

Two suggested approaches:

- To match Windows behaviour, we should emit app-command events and not cause navigation.
- To minimise breakage of existing Linux apps that don't handle app-command, app-command events should not be emitted and the navigation should still be done automatically

### Actual Behavior

When the mouse side buttons are used, app command events are created AND navigation is automatically done so if an app handles the app-command events per the documentation then navigation will happen twice.

https://github.com/electron/electron/pull/15441 added support for app-command handlers: browser-backward and browser-forward on Linux.

The docs describe how to make use of these here:
https://github.com/electron/electron/blob/v5.0.1/docs/api/browser-window.md#event-app-command-windows-linux

Our code is very similar here, and has been in place to support windows for years:
https://github.com/irccloud/irccloud-desktop/blob/master/app/main.js#L293-L311

When testing this on Ubuntu 19.04, this results in back and forward actions being triggered twice when using the appropriate mouse buttons.

### Testcase Gist URL

https://gist.github.com/LunNova/a4c61b7082d17b8aa637217f763348bf

### Additional Information

A previous ticket was closed #18322 but this is still a problem. I have asked for it to be reopened, but noone seems to have seen that.

Related third party ticket https://support.discord.com/hc/en-us/community/posts/1500000622702-Thumb-mouse-button-on-Linux-registers-twice