From 6a50888d346d5f243c4552c5baf8e6e883dcdea5 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 10 Jun 2019 16:53:38 -0700 Subject: [PATCH] fix(firefox): fix missing awaits in mouse.click (#4561) This applies the same fix we used on the Chrome-side and adds a test. Fix #4536 --- experimental/puppeteer-firefox/lib/Input.js | 17 +++++++++++++---- test/click.spec.js | 7 +++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/experimental/puppeteer-firefox/lib/Input.js b/experimental/puppeteer-firefox/lib/Input.js index 10bbb401..d8f7f523 100644 --- a/experimental/puppeteer-firefox/lib/Input.js +++ b/experimental/puppeteer-firefox/lib/Input.js @@ -218,11 +218,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), + ]); + } } /** diff --git a/test/click.spec.js b/test/click.spec.js index f32ca97b..205f02b4 100644 --- a/test/click.spec.js +++ b/test/click.spec.js @@ -55,6 +55,13 @@ module.exports.addTests = function({testRunner, expect, puppeteer}) { await page.click('span'); expect(await page.evaluate(() => window.CLICKED)).toBe(42); }); + it('should not throw UnhandledPromiseRejection when page closes', async({page, server}) => { + const newPage = await page.browser().newPage(); + await Promise.all([ + newPage.close(), + newPage.mouse.click(1, 2), + ]).catch(e => {}); + }); it('should click the button after navigation ', async({page, server}) => { await page.goto(server.PREFIX + '/input/button.html'); await page.click('button');