Summary:

Starting from Firefox 162, we'll start dispatching `|mousedown|`, `|mouseup|`, `|auxclick|` and relative pointer events for X1/X2 (4th/5th) buttons of mouse on desktop platforms. X1 (4th) button is typically used for "Back" navigation and X2 (5th) button is typically used for "Forward".

Previously, we intentionally didn't dispatch them because Chrome didn't dispatch them and the following code completely disables the history navigation:

addEventListener("mousedown", event => {
  event.preventDefault();
});

The reason is, this event listener does not check `|event.button|` properly and this is typically used to prevent selection and opening context menu.

However, Chrome started to dispatch the events starting since 2018 [1]. And Chrome allows web pages to prevent the default actions of the buttons only with `|mouseup|` event listener [2]. Therefore, we considered to follow this behavior.


       Note for web developers:

Users may customize their 4th/5th buttons to some other functions and Firefox treat them as default action of X1/X2 buttons only on Windows. E.g., Logi Options+ can assign copy, paste, undo, redo, etc.

If the mouse utility sends |WM_APPCOMMAND| to Firefox after X1/X2 button up, Firefox consumes the message if `|preventDefault()|` of `|mouseup|` is called. So, you may prevent unexpected default actions too [3]. Unfortunately, web apps cannot know the default action.

On the other hand, mouse utility may not send |WM_APPCOMMAND| but simulate a generic shortcut key presses, like `|Ctrl + C|` for copy. Actually, Logi Options+ does this. In this case, `|preventDefault()|` of `|mouseup|` cannot prevent the keyboard events. Therefore, I recommend to handle `|beforeunload|` after X1/X2 button up if you want to prevent only the navigation caused by the button press.


       Bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=2073171


       Platform Coverage:

Desktop for now. Android would be fixed in https://bugzilla.mozilla.org/show_bug.cgi?id=2094817 (However, according to Makoto-san's comment in the bug, it may be impossible to fix on Android.)


       Preference:

|dom.event.mouse.xbuttons.enabled|

And there are some related prefs, |mousebutton.4th.enabled| and |mousebutton.5th.enabled| disable the X1/X2 button work completely with ignoring the native events. These prefs are available for some mouse users who cannot disable the buttons with the mouse utility.


       DevTools Bug:

N/A


       References:

1. https://groups.google.com/a/chromium.org/g/blink-dev/c/MrKpBV26ik4/m/D_zmoAJrAQAJ

2. https://bugzilla.mozilla.org/show_bug.cgi?id=2073171#c1

3. https://searchfox.org/firefox-main/rev/e1bdb5893e652b10528c1e5422d3c90ff146b2da/widget/windows/KeyboardLayout.cpp#2330-2375

--
Masayuki Nakano<[email protected]>
Working on DOM, Events, editor and IME handling for Gecko

--
You received this message because you are subscribed to the Google Groups 
"[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/a/mozilla.org/d/msgid/dev-platform/6b75ac31-91c2-49b1-abd2-3ea50dfe1728%40d-toybox.com.

Reply via email to