diff --git a/src/spoof.ts b/src/spoof.ts index d783cf3..0dbcfcf 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) } }