JavaScript preventDefault is delayed/not working when app is deployed on a network

I have an application with custom context menus that are displayed on right-click. When that happens, I don't want default windows menu to appear. I use the following code to accomplish that:

            // right click
if (e.which == 3) {
    let menuVisible = false;
    const toggleMenu = command => { = command === "show" ? "block" : "none";
        menuVisible = !menuVisible;
    const setPosition = ({ top, left }) => { = `${left}px`; = `${top}px`;
    const origin = {
        left: e.pageX,
        top: e.pageY
    // toggle right clicked menu visibility
    window.addEventListener("click", e => {
        if (menuVisible) toggleMenu("hide");
    // Set up an event handler for the document right click
    document.addEventListener("contextmenu", function (event) {
        // Only do something when the element that was actually right-clicked
        if ("menu")) {

When app is running on localhost everything works as expected. However, when application is deployed on a network server and then accessed from any clients on the network the default menu appears first and then custom menu displayed behind it. There are no any errors. Any advise on how to fix that will be greatly appreciated.

Update: It seems that if right mouse button is hold not just clicked the behavior is as expected.

Read more here:

Content Attribution

This content was originally published by goryef at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: