Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Simulates a mouse click at the specified selector or element.
- `hesitate (number):` Delay before initiating the click action in milliseconds. Default is `0`.
- `waitForClick (number):` Delay between mousedown and mouseup in milliseconds. Default is `0`.
- `moveDelay (number):` Delay after moving the mouse in milliseconds. Default is `2000`. If `randomizeMoveDelay=true`, delay is randomized from 0 to `moveDelay`.
- `button (MouseButton):` Mouse button to click. Default is `left`.
- `clickCount (number):` Number of times to click the button. Default is `1`.

#### `move(selector: string | ElementHandle, options?: MoveOptions): Promise<void>`

Expand Down
17 changes: 14 additions & 3 deletions src/spoof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export interface ClickOptions extends MoveOptions {
* @default 2000
*/
readonly moveDelay?: number
/**
* @default "left"
*/
readonly button?: Protocol.Input.MouseButton
/**
* @default 1
*/
readonly clickCount?: number
}

export interface PathOptions {
Expand Down Expand Up @@ -505,6 +513,8 @@ export const createCursor = (
hesitate: 0,
waitForClick: 0,
randomizeMoveDelay: true,
button: 'left',
clickCount: 1,
...defaultOptions?.click,
...options
} satisfies ClickOptions
Expand All @@ -525,9 +535,10 @@ export const createCursor = (

const cdpClient = getCDPClient(page)
const dispatchParams: Omit<Protocol.Input.DispatchMouseEventRequest, 'type'> = {
...previous,
button: 'left',
clickCount: 1
x: previous.x,
y: previous.y,
button: optionsResolved.button,
clickCount: optionsResolved.clickCount
}
await cdpClient.send('Input.dispatchMouseEvent', { ...dispatchParams, type: 'mousePressed' })
await delay(optionsResolved.waitForClick)
Expand Down