Firefox for Android: Preventing context menu / `"contextmenu"` event through `preventDefault` for an `img` or `a` element does not work.
Categories
(GeckoView :: General, defect, P3)
Tracking
(Webcompat Priority:P3, firefox116 fixed)
Tracking | Status | |
---|---|---|
firefox116 | --- | fixed |
People
(Reporter: mithunder, Assigned: hiro)
References
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0
Steps to reproduce:
- Open Firefox for Android on an Android device.
- Have an
img
element and add a"contextmenu"
listener to it that callspreventDefault
(the listener can also have the argumentpassive
set tofalse
when adding the listener usingaddEventListener
). - Use 'long tap' on the
img
. - Observe.
- (see also https://jsfiddle.net/nc1zuref/ and https://github.com/mozilla-mobile/fenix/issues/21929 ).
Actual results:
A context menu unexpectedly opens.
Expected results:
A context menu should not open.
The issue https://bugzilla.mozilla.org/show_bug.cgi?id=1447227 seem related. This issue was first posted at Github, see https://github.com/mozilla-mobile/fenix/issues/21929 and https://github.com/mozilla-mobile/fenix/issues/14067 . Helpful developers in chat.mozilla.org under Android Components suggested that this could be a GeckoView bug, which is why I am filing it here.
About the jsfiddle.net link as a reproducible example:
https://jsfiddle.net/nc1zuref/ :
- Right-click on the images or long-tap on them.
- For Firefox on desktop, as well as Chrome on Android, using right-click or long tap, the first two
img
s correctly do not show context menus, while the thirdimg
correctly does show the context menu. - However, for Firefox on Android, all three
img
s show the context menu.
Motivation for the bug: One example where this bug can give problems is if you have a touch event listener on an img
, where the user for some actions is meant to continue to touch down on the img
for longer periods (for instance for moving some graphical element around while still being able to see the graphical element), detecting the specific touch position on the img
, and where there is a real-time aspect to it. The context menu appearing suddenly is therefore troublesome. It works on Chrome on Android. I don't know what an easy work-around would be, apart from finding and using some element other than img
where preventDefault
does work for the "contextmenu"
event for Firefox on Android (while I have not looked into it, I would assume that it would work for some element other than img
).
Remarks: While both img
and a
elements have this bug, p
elements do not, though p
elements also show a very different kind of menu than for img
and a
elements.
I am not certain at all, in part given that I am not well versed in Firefox's code base, and I haven't downloaded its source yet, but these might (or might not) be relevant: https://searchfox.org/mozilla-central/source/gfx/layers/apz/util/APZEventState.cpp#294 and https://bugzilla.mozilla.org/show_bug.cgi?id=1558506 .
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Interestingly there seems to be a test for preventingDefault on Android: https://searchfox.org/mozilla-central/source/gfx/layers/apz/test/mochitest/helper_long_tap.html#97-149
I am not sure if this test tests this case, or if it is not executed at all.
A wild guess (without knowing any FF code): https://searchfox.org/mozilla-central/source/gfx/layers/apz/util/APZEventState.cpp#298
This code seems like a special case for Android, which explains why it does not trigger in mobile simulator..
It would be interesting to know what happens if we handle Context Menus on Android like on all other Platforms.
Assignee | ||
Comment 5•2 years ago
|
||
There are two problems;
- ContentDelegate listens contextmenu events with "capture: true"
- ContentDelegateChild doesn't ignore preventDefaulted events just like Firefox does
Though I am not sure why we specify the "capture: true" option, it's there since the beginning of GeckoView context menu handling in https://hg.mozilla.org/mozilla-central/rev/60f7e2cb890c . My best guess is that they were misunderstanding its use cases.
Assignee | ||
Comment 7•2 years ago
|
||
Updated•2 years ago
|
Comment 9•2 years ago
|
||
bugherder |
Description
•