Firefox acting strangely with some event binding since version v65 on ubuntu and windows. Using Jquery "on" function to add a custom context menu. When the context menu is triggered, attaching a click event to body to close it when a left click is happened. It's working in chrome and worked in firefox till version v65. Now if I click right click, the context menu opens and closes immediately.
I analyzed the Firefox changelog a couple of times, but didn't found any change which can result in this behavior.
There is the changelog: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/65
The minimal code to reproduce the problem:
var container = $(".container")
var contextMenu = $(".contextmenu")
$(document).on("contextmenu", (function(e) {
e.preventDefault();
if ($(e.target).is(container)) {
contextMenu.show();
$(document).off("click.contextTest");
$(document).on("click.contextTest", (function(e) {
if(!$(e.target).is(contextMenu)) {
contextMenu.hide();
}
}));
}
}));
$(document).on("click.contextMenuItem", '.context-menu-item', (function(e) {
alert('button clicked');
}));
https://jsfiddle.net/Lcakpjev/1/
Example with 'mousedown': https://jsfiddle.net/Lcakpjev/2/
'mouseup' doing the same behavior like 'click'.
Right click inside the box to show the "context menu", then left click anywhere outside of the "context menu" box to hide it.
In Chrome the example works fine but in Firefox from v65 the context menu just blinks one. Older Firefox works fine as well.