Skip to content

Commit

Permalink
fix: always revert randomMove
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt committed May 9, 2024
1 parent df5c878 commit e04ad7e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/spoof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export const createCursor = (
...options
} satisfies ClickOptions

const wasRandom = !moving
actions.toggleRandomMove(false)

if (selector !== undefined) {
Expand All @@ -367,7 +368,6 @@ export const createCursor = (
// apply moveDelay after click, but not after actual move
moveDelay: 0
})
actions.toggleRandomMove(false)
}

try {
Expand All @@ -381,7 +381,7 @@ export const createCursor = (

await delay(Math.random() * optionsResolved.moveDelay)

actions.toggleRandomMove(true)
actions.toggleRandomMove(wasRandom)
},
async move (
selector: string | ElementHandle,
Expand All @@ -395,6 +395,8 @@ export const createCursor = (
...options
} satisfies MoveOptions

const wasRandom = !moving

const go = async (iteration: number): Promise<void> => {
if (iteration > (optionsResolved.maxTries)) {
throw Error('Could not mouse-over element within enough tries')
Expand Down Expand Up @@ -483,12 +485,15 @@ export const createCursor = (
}
await go(0)

actions.toggleRandomMove(wasRandom)

await delay(Math.random() * optionsResolved.moveDelay)
},
async moveTo (destination: Vector): Promise<void> {
const wasRandom = !moving
actions.toggleRandomMove(false)
await tracePath(path(previous, destination))
actions.toggleRandomMove(true)
actions.toggleRandomMove(wasRandom)
}
}

Expand Down

0 comments on commit e04ad7e

Please sign in to comment.