From aa28eb80f0a0b0783a78c0874d3fa972e19a7471 Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Tue, 25 Jul 2017 17:03:13 -0700 Subject: [PATCH] Wait for double raf after all mouse events. (#123) This patch starts waiting for double raf after every mouse event. It looks like a good enough workaround to make sure mouse events are delivered. The single raf might not be enough because browser might 'return' an already-prepared frame for us without actually dispatching events. Closes #122 --- lib/Input.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Input.js b/lib/Input.js index 02ce5d8bcae..c49ae3dd34f 100644 --- a/lib/Input.js +++ b/lib/Input.js @@ -115,6 +115,7 @@ class Mouse { x, y, modifiers: this._keyboard._modifiers }); + await this._doubleRaf(); } /** @@ -123,12 +124,15 @@ class Mouse { * @param {!Object=} options */ async click(x, y, options) { - await this.move(x, y); - await this.down(options); + this.move(x, y); + this.down(options); await this.up(options); + } + + async _doubleRaf() { // This is a hack for now, to make clicking less race-prone. See crbug.com/747647 await this._client.send('Runtime.evaluate', { - expression: 'new Promise(f => requestAnimationFrame(f))', + expression: 'new Promise(f => requestAnimationFrame(() => requestAnimationFrame(f)))', awaitPromise: true, returnByValue: true }); @@ -149,6 +153,7 @@ class Mouse { modifiers: this._keyboard._modifiers, clickCount: (options.clickCount || 1) }); + await this._doubleRaf(); } /** @@ -166,6 +171,7 @@ class Mouse { modifiers: this._keyboard._modifiers, clickCount: (options.clickCount || 1) }); + await this._doubleRaf(); } }