Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

[Bug]: Preventing context menu / "contextmenu" event through preventDefault for an img element does not work. #21929

Closed
MelvinWM opened this issue Oct 14, 2021 · 5 comments
Labels
🐞 bug Crashes, Something isn't working, .. needs:triage Issue needs triage wontfix

Comments

@MelvinWM
Copy link

MelvinWM commented Oct 14, 2021

Steps to reproduce

  1. 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).
  2. Use 'long tap' on the img.
  3. Observe.
  4. (see also https://jsfiddle.net/nc1zuref/ ).

Expected behaviour

A context menu should not open.

Actual behaviour

A context menu unexpectedly opens.

Device name

Galaxy A20s

Android version

Android 11

Firefox release type

Firefox

Firefox version

93.1.0 (Build #2015836707)

Device logs

No response

Additional information

Somewhat minimal reproducible example

https://jsfiddle.net/nc1zuref/ :

  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.

(note that the third img is added purely for the sake of having something to compare with).

Related bugs

This bug may be related to #14067 . I have tried searching for "context menu" and "contextmenu" with the label "🐞+bug", but did not find any open issue that matched.

How this bug can cause problems

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

┆Issue is synchronized with this Jira Task

@MelvinWM MelvinWM added needs:triage Issue needs triage 🐞 bug Crashes, Something isn't working, .. labels Oct 14, 2021
@MelvinWM
Copy link
Author

I believe that it would make sense to add the label "Feature:ContextMenu" to this issue.

@MelvinWM
Copy link
Author

In #14067 , it turns out that, like for img elements, a HTML elements do not work for this either. Regular p elements, on the other hand, do work correctly, with preventDefault correctly preventing a menu from showing up. That said, p elements when long-tapped/pressed show a very different kind of menu (as well as text selection/highlighting) than for img and a elements.

@MelvinWM
Copy link
Author

MelvinWM commented Oct 18, 2021

Upon the advice of very helpful developers (thank you!) in chat.mozilla.org under Android Components, I have also posted a bug issue here: https://bugzilla.mozilla.org/show_bug.cgi?id=1736391 .

@stale
Copy link

stale bot commented Apr 17, 2022

See: #17373 This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 17, 2022
@amedyne
Copy link
Contributor

amedyne commented Apr 19, 2022

Closing issue to track bugzilla instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Crashes, Something isn't working, .. needs:triage Issue needs triage wontfix
Projects
None yet
Development

No branches or pull requests

2 participants