From 08e784261f60a548b456dd80d341db0e1c826217 Mon Sep 17 00:00:00 2001 From: Blake V <87083504+bvandercar-vt@users.noreply.github.com> Date: Thu, 9 May 2024 12:44:23 -0600 Subject: [PATCH] fix: Always revert to previous randomMove value (#132) * clamp * fix: always revert randomMove --- src/spoof.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/spoof.ts b/src/spoof.ts index d8389ea..b622ff9 100644 --- a/src/spoof.ts +++ b/src/spoof.ts @@ -359,6 +359,7 @@ export const createCursor = ( ...options } satisfies ClickOptions + const wasRandom = !moving actions.toggleRandomMove(false) if (selector !== undefined) { @@ -367,7 +368,6 @@ export const createCursor = ( // apply moveDelay after click, but not after actual move moveDelay: 0 }) - actions.toggleRandomMove(false) } try { @@ -381,7 +381,7 @@ export const createCursor = ( await delay(Math.random() * optionsResolved.moveDelay) - actions.toggleRandomMove(true) + actions.toggleRandomMove(wasRandom) }, async move ( selector: string | ElementHandle, @@ -395,6 +395,8 @@ export const createCursor = ( ...options } satisfies MoveOptions + const wasRandom = !moving + const go = async (iteration: number): Promise => { if (iteration > (optionsResolved.maxTries)) { throw Error('Could not mouse-over element within enough tries') @@ -483,12 +485,15 @@ export const createCursor = ( } await go(0) + actions.toggleRandomMove(wasRandom) + await delay(Math.random() * optionsResolved.moveDelay) }, async moveTo (destination: Vector): Promise { + const wasRandom = !moving actions.toggleRandomMove(false) await tracePath(path(previous, destination)) - actions.toggleRandomMove(true) + actions.toggleRandomMove(wasRandom) } }