mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: add reset to mouse (#10340)
This commit is contained in:
@@ -598,6 +598,29 @@ export class Mouse {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the mouse to the default state: No buttons pressed; position at
|
||||
* (0,0).
|
||||
*/
|
||||
async reset(): Promise<void> {
|
||||
const actions = [];
|
||||
for (const [flag, button] of [
|
||||
[MouseButtonFlag.Left, MouseButton.Left],
|
||||
[MouseButtonFlag.Middle, MouseButton.Middle],
|
||||
[MouseButtonFlag.Right, MouseButton.Right],
|
||||
[MouseButtonFlag.Forward, MouseButton.Forward],
|
||||
[MouseButtonFlag.Back, MouseButton.Back],
|
||||
] as const) {
|
||||
if (this.#state.buttons & flag) {
|
||||
actions.push(this.up({button: button}));
|
||||
}
|
||||
}
|
||||
if (this.#state.position.x !== 0 || this.#state.position.y !== 0) {
|
||||
actions.push(this.move(0, 0));
|
||||
}
|
||||
await Promise.all(actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the mouse to the given coordinate.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user