I can run the following in the Chrome console and it does what I want without error:
document.querySelector('.flat.pagination.next').dispatchEvent(new MouseEvent("mousedown",{ view: window, bubbles: true, cancelable: true, clientX: 0, clientY: 0, button: 0 }));
However, if I put the same line of code in to a Tampermonkey script, I get the following error:
Uncaught TypeError: Failed to construct 'MouseEvent': Failed to read the 'view' property from 'UIEventInit': Failed to convert value to 'Window'.
Presumably there is something wrong with the view: window part, but I can't see why it would behave differently in the console to a script.
Any ideas how I can get it to work?
I was able to get it to work as I needed by removing the options:
document.querySelector('.flat.pagination.next').dispatchEvent(new MouseEvent('mousedown'));