I've been attempting to programmatically simulate a mouse click at arbitrary coordinates on a canvas element. Because of technology constraints, I need to avoid jQuery which would make this easier.
Using this answer, I am able to get coordinates of manual clicks.
Using this answer, I'm able to programmatically simulate a mouse click. But unfortunately I need to de-jQuery-ify it, which is, I think, where I've run into problems.
If I try to do something like:
document.querySelector("canvas").dispatchEvent(new Event("mousedown", {pageX: 1, pageY: 1}));
or
document.querySelector("canvas").dispatchEvent(new MouseEvent("mousedown", {pageX: 1, pageY: 1}));
or combinations of the above using 'click' instead of 'mousedown'
I still get strange 'undefined' errors that I don't understand (other than that I can see they are referring to 'mousedown') and never successfully simulate the click.
Some working (and not working) examples:
Working: Displays coordinates of clicks
Working: Fires a programmatic click
Not Working: Combining the two above
Not Working: Trying to fire a programmatic click without jQuery