Skip to content

[Bug]: Linux: Double actions when handling app-command handlers: browser-backward and browser-forward #18322  #32763

Closed

Description

@LunNova

Preflight Checklist

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 results in handling of app commands on both button down and button up
  • Window - testcase gist 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.

#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

Activity

  1. mlaurencin commented on Feb 8, 2022

    @mlaurencin
    Member

    Thanks for reporting this and helping to make Electron better!

    Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use. If you take the code from either of the examples you provided and the issue replicable in the Fiddle Gist, that will helpful.

    Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

    I'm adding the blocked/need-repro label for this reason. After you make a test case, please link to it in a follow-up comment.

  2. added
    blocked/need-repro
    on Feb 8, 2022
  3. LunNova commented on Feb 8, 2022

    @LunNova
    Author

    @mlaurencin

    index.js

    const {app, BrowserWindow} = require('electron');
    
    app.on('window-all-closed', () => {
      if (process.platform !== 'darwin') app.quit()
    })
    app.whenReady().then(async () => {
      let mainWindow = new BrowserWindow({height: 600, width: 600});
      // Handle app command per docs except also refresh and forward
      // https://www.electronjs.org/docs/latest/api/browser-window/#event-app-command-windows-linux
      mainWindow.on('app-command', function (e, cmd) {
        switch (cmd) {
        case 'browser-backward':
          if (mainWindow.webContents.canGoBack()) {
            mainWindow.webContents.goBack();
          }
          break;
        case 'browser-forward':
          if (mainWindow.webContents.canGoForward()) {
            mainWindow.webContents.goForward();
          }
          break;
        case 'browser-refresh':
          mainWindow.webContents.reloadIgnoringCache();
          break;
        default:
          break;
        }
      });
      for (var i = 0; i <= 10; i++) {
        await mainWindow.loadURL("data:text/plain;," + i + "/10");
      }
    });
    

    On Windows: back/forward button presses will go back/forward one page at a time
    On Linux: back/forward button presses will go back/forward two pages instead (once when button is pressed and once when released)

  4. added
    has-repro-gist
    and removed
    blocked/need-repro
    on Feb 16, 2022
  5. hjkatz commented on May 16, 2022

    @hjkatz

    I'm experiencing this issue with Slack's snap on Ubuntu 22.04 as well.

    name:      slack
    summary:   Team communication for the 21st century.
    publisher: Slack✓
    store-url: https://snapcraft.io/slack
    contact:   https://get.slack.help/hc/en-us
    license:   unset
    description: |
    Caution: Slack for Linux is in beta. We’re still busy adding features and ironing out potential
    issues.
    
    Slack brings team communication and collaboration into one place so you can get more work done,
    whether you belong to a large enterprise or a small business. Check off your to-do list and move
    your projects forward by bringing the right people, conversations, tools, and information you need
    together. Slack is available on any device, so you can find and access your team and your work,
    whether you’re at your desk or on the go.
    
    Scientifically proven (or at least rumored) to make your working life simpler, more pleasant, and
    more productive. We hope you’ll give Slack a try.
    
    Stop by and learn more at: https://slack.com/
    commands:
    - slack
    snap-id:      JUJH91Ved74jd4ZgJCpzMBtYbPOzTlsD
    tracking:     latest/stable
    refresh-date: 6 days ago, at 13:49 EDT
    channels:
    latest/stable:     4.25.1 2022-04-04 (61) 108MB -
    latest/candidate:  ↑
    latest/beta:       ↑
    latest/edge:       ↑
    insider/stable:    –
    insider/candidate: –
    insider/beta:      –
    insider/edge:      4.25.1 2022-04-01 (61) 108MB -
    installed:           4.25.1            (61) 108MB -
    
  6. lmcarreiro commented on Jun 17, 2022

    @lmcarreiro

    I'm experiencing this issue with Slack's snap on Ubuntu 22.04 as well.

    Same here, very annoying bug!

    If I install Slack from another source instead of snap, would we have the same issue?

  7. hjkatz commented on Jun 17, 2022

    @hjkatz

    No, I've tried both versions and it seems to be a problem with Slack's imported version of Electron. I also reached out to Slack support and they said they were aware of the problem, but gave no timeline for an intended fix.

  8. diniamo commented on Jul 26, 2022

    @diniamo

    I have this issue on Discord as well.

  9. edoardopirovano commented on Aug 9, 2022

    @edoardopirovano

    Also experiencing this on Slack in Ubuntu 22.04.

  10. rneatherway commented on Aug 17, 2022

    @rneatherway

    Same here. Is there any way that we could move the discussion forward on which solution might be workable?

    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

    @MarshallOfSound might you have an opinion? I ask as you reviewed #15441 and your profile indicates that you work at Slack right now.

  11. 55 remaining items

  12. Tejeev commented on Feb 4, 2025

    @Tejeev

    @mlaurencin is there any hope here?

  13. Tejeev commented on Feb 4, 2025

    @Tejeev

    Looks like folks were updating their app.sar but I don't see one of those in the snap, or I don't know how snaps really work and kinda hate them... probably the later

  14. shinebayar-g commented on Feb 4, 2025

    @shinebayar-g

    Flatpak or Snap doesn't seem to provide .asar files, so I use native package managers and edit the slack file manually for now.

  15. Tejeev commented on Feb 4, 2025

    @Tejeev

    oh, like install from a .deb or something and then edit the file? Snap is unfortuantely native in Ubuntu these days. I keep telling myself I'm going to change distros, but haven't had the time to migrate my configurations and etc to a new distro, let alone pick one.

  16. Tejeev commented on Feb 5, 2025

    @Tejeev

    Ok, so now I need to know how to handle this in the apps whcih do not have a .deb. I've got one or two electron app based tools I use for work which are only published as snaps.
    We need a fix from Electron as this is not a third party problem. This is an electron bug

  17. frends-dani commented on Feb 19, 2025

    @frends-dani

    bump

  18. TomerGodinger commented on Mar 23, 2025

    @TomerGodinger

    My god, I restarted my computer today, two years after last writing here, and this has finally stopped happening in Slack for me.
    (Ubuntu 22.04.5, Slack version 4.43.43 64-bit.)
    I don't know what caused the change, but I'm just really happy to finally stop having this issue! 😁

  19. umpirsky commented on Mar 23, 2025

    @umpirsky

    I can confirm it finally stopped for me on Ubuntu 24.04.2 LTS too!

  20. AleksandrKls commented on Mar 23, 2025

    @AleksandrKls

    Wow, I can confirm too

    Ubuntu 24.04.2 LTS

    "Let the ticket breathe" and the problem solved itself

  21. eliliam commented on Mar 23, 2025

    @eliliam

    Same! What was the thing that actually fixed this issue?

  22. amcsi commented on Apr 15, 2025

    @amcsi

    Looks like it's fixed for me also on Ubuntu 24.04.2 LTS. Not sure if it was the distro or some newer Electron version.

  23. lythandas commented on Apr 15, 2025

    @lythandas

    Working on Ubuntu 24.04.2 LTS confirmed! Great news!

  24. mlaurencin commented on Apr 15, 2025

    @mlaurencin
    Member

    Thank you to everyone that has confirmed this issue is resolved for them using Ubuntu 24.04.2 LTS. Given the number of confirmations, I'm going to go ahead and close this issue. If you are still experiencing it, rather than comment here, please file a new bug report with all the relevant information.

  25. umpirsky commented on Apr 15, 2025

    @umpirsky

    Anyone knows what fixed it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    20-x-ybug 🪲has-repro-gistplatform/linux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions