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
This commit is contained in:
JoelEinbinder 2017-07-25 17:03:13 -07:00 committed by Andrey Lushnikov
parent 1a50403090
commit aa28eb80f0

View File

@ -115,6 +115,7 @@ class Mouse {
x, y, x, y,
modifiers: this._keyboard._modifiers modifiers: this._keyboard._modifiers
}); });
await this._doubleRaf();
} }
/** /**
@ -123,12 +124,15 @@ class Mouse {
* @param {!Object=} options * @param {!Object=} options
*/ */
async click(x, y, options) { async click(x, y, options) {
await this.move(x, y); this.move(x, y);
await this.down(options); this.down(options);
await this.up(options); await this.up(options);
}
async _doubleRaf() {
// This is a hack for now, to make clicking less race-prone. See crbug.com/747647 // This is a hack for now, to make clicking less race-prone. See crbug.com/747647
await this._client.send('Runtime.evaluate', { await this._client.send('Runtime.evaluate', {
expression: 'new Promise(f => requestAnimationFrame(f))', expression: 'new Promise(f => requestAnimationFrame(() => requestAnimationFrame(f)))',
awaitPromise: true, awaitPromise: true,
returnByValue: true returnByValue: true
}); });
@ -149,6 +153,7 @@ class Mouse {
modifiers: this._keyboard._modifiers, modifiers: this._keyboard._modifiers,
clickCount: (options.clickCount || 1) clickCount: (options.clickCount || 1)
}); });
await this._doubleRaf();
} }
/** /**
@ -166,6 +171,7 @@ class Mouse {
modifiers: this._keyboard._modifiers, modifiers: this._keyboard._modifiers,
clickCount: (options.clickCount || 1) clickCount: (options.clickCount || 1)
}); });
await this._doubleRaf();
} }
} }