Skip to content

Commit

Permalink
fix(page): fix missing awaits in mouse.click (#4541)
Browse files Browse the repository at this point in the history
Lack of await causes dangling promises, which lead to unhandled rejections that cannot be caught if these calls fail (e.g. if the page is closed). 

References #4536
  • Loading branch information
pqvst authored and aslushnikov committed Jun 10, 2019
1 parent 7faf1c9 commit dd6fcfe
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/Input.js
Expand Up @@ -224,11 +224,20 @@ class Mouse {
*/
async click(x, y, options = {}) {
const {delay = null} = options;
this.move(x, y);
this.down(options);
if (delay !== null)
if (delay !== null) {
await Promise.all([
this.move(x, y),
this.down(options),
]);
await new Promise(f => setTimeout(f, delay));
await this.up(options);
await this.up(options);
} else {
await Promise.all([
this.move(x, y),
this.down(options),
this.up(options),
]);
}
}

/**
Expand Down

0 comments on commit dd6fcfe

Please sign in to comment.