From b90ed3b8ea609f5b7a181064f2297a3edf7f9a79 Mon Sep 17 00:00:00 2001 From: Blake V <87083504+bvandercar-vt@users.noreply.github.com> Date: Wed, 8 May 2024 10:48:13 -0600 Subject: [PATCH] fix: move applies moveDelay (#128) * fix: move applies moveDelay * fix: default * fix: readme * style: pass whole object * style: revert --- README.md | 2 +- src/spoof.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 542c634..002b518 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Moves the mouse to the specified selector or element. - **options (optional):** Additional options for moving. - `paddingPercentage (number):` Percentage of padding to be added around the element. Default is `0`. - `waitForSelector (number):` Time to wait for the selector to appear in milliseconds. Default is to not wait for selector. - - `moveDelay (number):` Delay after moving the mouse in milliseconds. Default is `2000`. + - `moveDelay (number):` Delay after moving the mouse in milliseconds. Default is `0`. - `maxTries (number):` Maximum number of attempts to mouse-over the element. Default is `10`. - `moveSpeed (number):` Speed of mouse movement. Default is random. - `overshootThreshold (number):` Distance from current location to destination that triggers overshoot to occur. (Below this distance, no overshoot will occur). Default is `500`. diff --git a/src/spoof.ts b/src/spoof.ts index 01e7328..52c1af7 100644 --- a/src/spoof.ts +++ b/src/spoof.ts @@ -28,7 +28,7 @@ export interface MoveOptions extends BoxOptions { readonly waitForSelector?: number /** * Delay after moving the mouse in milliseconds. - * @default 2000 + * @default 0 */ readonly moveDelay?: number /** @@ -60,6 +60,11 @@ export interface ClickOptions extends MoveOptions { * @default 0 */ readonly waitForClick?: number + /** + * Delay after performing the click in milliseconds. + * @default 2000 + */ + readonly moveDelay?: number } export interface PathOptions { @@ -323,7 +328,11 @@ export const createCursor = ( actions.toggleRandomMove(false) if (selector !== undefined) { - await actions.move(selector, options) + await actions.move(selector, { + ...options, + // apply moveDelay after click, but not after actual move + moveDelay: 0 + }) actions.toggleRandomMove(false) } @@ -430,7 +439,9 @@ export const createCursor = ( return await go(iteration + 1) } } - return await go(0) + await go(0) + + await delay(Math.random() * (options?.moveDelay ?? 0)) }, async moveTo (destination: Vector): Promise { actions.toggleRandomMove(false)