From dd6fcfe77b38667d186f4989283e4a585f3d5b18 Mon Sep 17 00:00:00 2001 From: Philip Bergqvist Date: Mon, 10 Jun 2019 04:42:19 -0400 Subject: [PATCH] fix(page): fix missing awaits in mouse.click (#4541) 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 --- lib/Input.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/Input.js b/lib/Input.js index a0789b1e..5911afe3 100644 --- a/lib/Input.js +++ b/lib/Input.js @@ -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), + ]); + } } /**