Open Bug 1736391 Opened 9 months ago Updated 1 month ago

Firefox for Android: Preventing context menu / `"contextmenu"` event through `preventDefault` for an `img` or `a` element does not work.


(GeckoView :: General, defect, P3)

Firefox 93


(Webcompat Priority:P3)

Webcompat Priority P3


(Reporter: mithunder, Unassigned)



User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0

Steps to reproduce:

  1. Open Firefox for Android on an Android device.
  2. Have an img element and add a "contextmenu" listener to it that calls preventDefault (the listener can also have the argument passive set to false when adding the listener using addEventListener).
  3. Use 'long tap' on the img.
  4. Observe.
  5. (see also and ).

Actual results:

A context menu unexpectedly opens.

Expected results:

A context menu should not open.

The issue seem related. This issue was first posted at Github, see and . Helpful developers in under Android Components suggested that this could be a GeckoView bug, which is why I am filing it here.

About the link as a reproducible example: :

  1. Right-click on the images or long-tap on them.
  2. For Firefox on desktop, as well as Chrome on Android, using right-click or long tap, the first two imgs correctly do not show context menus, while the third img correctly does show the context menu.
  3. However, for Firefox on Android, all three imgs 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: and .

Priority: -- → P3
Webcompat Priority: --- → P3
Severity: -- → S3

Interestingly there seems to be a test for preventingDefault on Android:

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):
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.

You need to log in before you can comment on or make changes to this bug.