Even by using evt.preventDefault() the browser menu pops up - after I changed from BJS 5.0 to 5.10

According to

I wrote my own control. With BJS 5.0.0 it was ok:
The 2nd (left) mouse key rotates the scene and NO browser menu is visible.
With 5.10.0 that browser menu pops up. :frowning:

I debugged it and evt.preventDefault(); is called correctly.
It is reproducible with FireFox and Opera.

@PolygonalSun will have a look into it :slight_smile:

I can take a look and see what’s going on. If it worked in 5.0.0 but not in 5.10.0, that at least narrows down possible issues.

5.0.0 alpha 22
to be exact

alpha.22 was released more than a year ago. Have you tried different versions? Would you be able to reproduce that or show some code? I am sure it will help @PolygonalSun debug the issue

There is a simple test file: template 2nd
I found some old versions-archives in GitHub to test: 5.1.0 is still ok.
5.2.0 … 5.10.0 and 5.11.0 not :frowning:
I could not debug evt.preventDefault(); :-/

In the chanes for 5.2
-# Small fixes and improvements for input managment #1032
looks related, but I don’t see a cause.

Hey @DerKarlos, so here’s what I’ve found. The reason the right-click menu is coming up with newer versions and not with older ones is actually because of a bug fix. In earlier versions, we had a callback function onContextMenu that was used to both suppress that menu and allow users to perform custom actions. The original bug was that this callback was never being removed so when users would make custom inputs and remove the default ones, onContextMenu was still being called. With this fix, it’s properly being removed so there’s no suppression of that menu. I am currently working on a fix but if you need a workaround in the mean time, you should be able to do something like:

canvas.addEventListener("contextmenu", (evt) => {

As long as preventDefault is called from within the contextmenu event context, it should stop it from popping up.


I’ve created and merged a PR that should address future context menu pop-up instances: Engine: Add event listener to disable right-click menu when there’s a canvas element by PolygonalSun · Pull Request #12697 · BabylonJS/Babylon.js (github.com)