'Move mouse with javascript

I am trying to do simple mouse move with javascript but I am unable to do it and dont know what is wrong.

function doMove(){
    let element = document.getElementById('root');

    let eventMouseDown = new MouseEvent("mousedown", {
        clientX: window.innerWidth/2,
        clientY: window.innerHeight/2
    });
    let eventMouseMove = new MouseEvent("mousemove", {
        clientX: (window.innerWidth/2)+50,
        clientY: window.innerHeight/2
    });
    let eventMouseUp = new MouseEvent("mouseup", {
        clientX: (window.innerWidth/2)+50,
        clientY: window.innerHeight/2
    });

    element.dispatchEvent(eventMouseDown);
    element.dispatchEvent(eventMouseMove);
    element.dispatchEvent(eventMouseUp);
}

First I put mouse down then move and then realease which should simulate me moving with mouse on map for example. How can I make it work?



Solution 1:[1]

You can't move mouse using JavaScript in the website. Imagine that you are opening a website and it takes control over your mouse.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Konrad Linkowski