How to Simulate Mouse Click Along With Mouse Move Using JavaScript

How to simulate mouse click along with mouse move using javascript

You cannot move the mousepointer with javascript, because of the security implications that it incurs.

use io hook to move puppteer's mouse

In puppeteer documentation website:

https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-class-mouse

Using ‘page.mouse’ to trace a 100x100 square.

await page.mouse.move(0, 0);
await page.mouse.down();
await page.mouse.move(0, 100);
await page.mouse.move(100, 100);
await page.mouse.move(100, 0);
await page.mouse.move(0, 0);
await page.mouse.up();

So to make mouse drag, you've to put some await page.mouse.move() after an await page.mouse.down() and before an await page.mouse.up()

page.mouse.click() is a combination of two event mouse.down() and mouse.up() in same position on a very short time delay.

And in IOHook documentation:
https://wilix-team.github.io/iohook/usage.html#mousedrag

Triggered when user clicks and drags something.

{ button: 0, clicks: 0, x: 373, y: 683, type: 'mousedrag' }

So the solution here is, you have to listen the mousedrag event.



Related Topics



Leave a reply



Submit