electron / electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
https://electronjs.org
MIT License
114.2k stars 15.4k forks source link

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

Open LunNova opened 2 years ago

LunNova commented 2 years ago

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?

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:

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

mlaurencin commented 2 years ago

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.

LunNova commented 2 years ago

@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)

LunNova commented 2 years ago

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

hjkatz commented 2 years ago

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 -
lmcarreiro commented 2 years ago

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?

hjkatz commented 2 years ago

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.

diniamo commented 2 years ago

I have this issue on Discord as well.

edoardopirovano commented 2 years ago

Also experiencing this on Slack in Ubuntu 22.04.

rneatherway commented 2 years ago

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 https://github.com/electron/electron/pull/15441 and your profile indicates that you work at Slack right now.

JFGHT commented 2 years ago

Bump on this.

In the meanwhile you can use the keyboard shortcut: ALT + LEFT.

LunNova commented 2 years ago

Tested again on electron v20.1.0, still reproduces. Can we get the labels updated @mlaurencin ?

AddisonG commented 2 years ago

Still getting this in Slack (v4.28.171) on Ubuntu 20.04, and have had this for a few years now.

mennoxx commented 2 years ago

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.

Thats what they already said, when I reported the issue to Slack 2 years ago unfortunately.. I don't expect them to fix this anymore while it still annoyes me every single day.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

wbollock commented 1 year ago

bump 🙏

LunNova commented 1 year ago

It's still broken.

lmcarreiro commented 1 year ago

Very annoying issue. I'm getting on Slack 4.29.149 64-bit Ubuntu 22.04

TomerGodinger commented 1 year ago

Yes, still happening and immensely frustrating.

naclonts commented 1 year ago

Happening for me on Slack Debian 11, as well.

jason-h-35 commented 1 year ago

bump

kznrluk commented 1 year ago

bump, Slack desktop on Arch linux and XFCE4.

alangalvino commented 1 year ago

bump

IrrerPolterer commented 1 year ago

Still experiencing the issue in Slack. Mouse-Back and Mouse-Forward each register twice (on button press and release)

3cas commented 1 year ago

Experiencing this issue with WebCatalog on Linux.

BinaryVixen899 commented 1 year ago

Still experienceing this with the Slack app in Ubuntu 23.04

jonathan-saindon commented 1 year ago

I am experiencing this as well on Mint 21.1 with kernel 5.15.0-73-generic. Currently using Slack version 4.32.127 64-bit

mpearson commented 1 year ago

Seeing this bug on Ubuntu 18.04 as well as 22.04. Slack version 4.32.127 64-bit. Extremely annoying. I have several other Electron apps which do not have this problem, e.g. VS Code and Discord, so presumably it's just an electron version issue?

ReillyBrogan commented 1 year ago

Seeing this bug on Ubuntu 18.04 as well as 22.04. Slack version 4.32.127 64-bit. Extremely annoying. I have several other Electron apps which do not have this problem, e.g. VS Code and Discord, so presumably it's just an electron version issue?

Most likely the apps that do not have this issue are explicitly ignoring either the app-command events or the navigation events.

wugaosheng123 commented 1 year ago

hello @codebytere I think this is a problem with the example code in the docs. browser-backward and browser-forward events are handled by default to navigate the page, so shouldn't have to perform win.webContents.goBack() in win.on('app-command', (e, cmd)......, or else clicking the mouse button once navigates the page twice.

图片

But I didn't find the default handing of browser-backward and browser-forward in electron's code (which performs the navigation of the page), and I'm guessing this is done by chromium.If so, is this issure meaningless?Because browser-backward and browser-forward already has a default action, unless he is told to perform another behavior instead of doing page navigation

I would be more than happy to submit a pr for this

shawn-mccool-mollie commented 1 year ago

Is there any work around? We have many people using slack and this is a significant usability issue.

TaylorMichaelHall commented 1 year ago

Is there any work around? We have many people using slack and this is a significant usability issue.

The keyboard shortcuts work. Another option on Linux is to use the Slack webapp instead of the desktop app - the back/forward mouse buttons work there for me.

lsaintier commented 1 year ago

Today my compagny rollout a new slack release and it's still there. I can't believe it's still not fixed.

alangalvino commented 1 year ago

Still experiencing the issue in Slack.

MKimiSH commented 1 year ago

One workaround for Slack (works on Ubuntu 22.04) with an additional right click:

  1. Find a place where right click calls out a text editing menu from the system (Copy/Paste/Cut or just Copy), not the one from Slack (Add reaction, reply in thread, etc.). I usually do it on the blank area to the right of the channel title.
  2. Right click in that region, and see the copy-paste menu pop-up.
  3. Move the cursor to be still in Slack but outside the copy-paste menu. This is important, because when we click forward/backward when the cursor is in the menu, nothing happens (at least for me).
  4. Click forward/backward. This should only move forward/backward by one page, not two.
eizieizi commented 10 months ago

itsdanomano found a temporary solution for the issue (posted on reddit), but it has to be re-done after every app update. https://www.reddit.com/r/Slack/comments/qfodd7/when_i_press_back_on_a_mouse_in_the_slack_app_on/

Also for Snap its not so easy as the snap files are read only. Maybe one could work arround the issue with file mounts.

vtushevskiyNV commented 8 months ago

itsdanomano found a temporary solution for the issue (posted on reddit), but it has to be re-done after every app update. https://www.reddit.com/r/Slack/comments/qfodd7/when_i_press_back_on_a_mouse_in_the_slack_app_on/

Also for Snap its not so easy as the snap files are read only. Maybe one could work arround the issue with file mounts.

doesn't work for me

genka-pokos commented 8 months ago

itsdanomano found a temporary solution for the issue (posted on reddit), but it has to be re-done after every app update. https://www.reddit.com/r/Slack/comments/qfodd7/when_i_press_back_on_a_mouse_in_the_slack_app_on/ Also for Snap its not so easy as the snap files are read only. Maybe one could work arround the issue with file mounts.

doesn't work for me

Try the command from the mythin's message. Works for me

marcodiiga commented 8 months ago

I also would love to see this fixed: I must reapply the reddit fix each time slack gets updated unfortunately.

theodotdot commented 5 months ago

Has anyone noticed the above fix not working anymore?

Stopped working for me running slack-desktop 4.37.101 on Ubuntu 20.04

genka-pokos commented 5 months ago

Has anyone noticed the above fix not working anymore?

Stopped working for me running slack-desktop 4.37.101 on Ubuntu 20.04

Try this one by lalten https://www.reddit.com/r/Slack/comments/qfodd7/comment/kxo523r/, works for me

theodotdot commented 5 months ago

Ah that did fix it, I missed it in the reddit thread. So it seems like the above link is the fix that is working for the latest versions, thank you!

tiaraju commented 5 months ago

Still happening on ubuntu 22.04. Same issue for me. Really frustrating 😢

it's the fix supposed to work by having slack installed by snap?

fnagua1 commented 3 months ago

Same issue here in Ubunto 22.04 and Slack 4.38.125. Do we have an ETA for the fix?

Thank you in advance!

genka-pokos commented 3 months ago

Since the last Slack update, the Reddit fix is no longer working. This is ridiculous, this issue is two years old, and all that needs to be done is to handle buttons only on release, not on push.

UPD: The reddit fix is now working again thanks to itsdanomano https://www.reddit.com/r/Slack/comments/qfodd7/comment/k4937gj/

eizieizi commented 3 months ago

Still happening on ubuntu 22.04. Same issue for me. Really frustrating 😢

it's the fix supposed to work by having slack installed by snap?

No, as SNAP images use their own filesystem, like a container this is more difficult to achieve. I switched from snap back to classic installed slack.

AleksandrKls commented 3 months ago

Same issue here in Ubuntu 24.04 and Slack 4.39.88

electron-issue-triage[bot] commented 2 weeks ago

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

mpearson commented 2 weeks ago

Bump, still seeing this on Slack 4.39.95 (installed via Snap) / Ubuntu 22.04.

LunNova commented 2 weeks ago

Ran the same testcase on Electron v30.5.1, v31.6.0, v32.1.2, all on Linux (NixOS). Still broken, moves back once on button down and a second time on button release.

eliliam commented 1 week ago

Electron team, why can we not fix this?