How to trigger the right mouse click event through JS?

I want to trigger the right mouse click event through JS.

Here is my test code:

            var obj = document.getElementById("testItem");
            var evObj = document.createEvent("MouseEvents",);
            evObj.initEvent('click', true, false);
            Object.defineProperty(evObj, "button", {
                value: 2,
                writable: false
            });
            Object.defineProperty(evObj, "buttons", {
                value: 2,
                writable: false
            });
            obj.dispatchEvent(evObj);

I tried lots of methods, but they didn’t work.

Anyone know how to solve it?

Thank you in advance.