mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: avoid unnecessary zero-delays in input code (#4934)
This commit is contained in:
parent
11ff374ca3
commit
3773229ac2
13
lib/Input.js
13
lib/Input.js
@ -156,16 +156,15 @@ class Keyboard {
|
|||||||
* @param {{delay: (number|undefined)}=} options
|
* @param {{delay: (number|undefined)}=} options
|
||||||
*/
|
*/
|
||||||
async type(text, options) {
|
async type(text, options) {
|
||||||
let delay = 0;
|
const delay = (options && options.delay) || null;
|
||||||
if (options && options.delay)
|
|
||||||
delay = options.delay;
|
|
||||||
for (const char of text) {
|
for (const char of text) {
|
||||||
if (keyDefinitions[char])
|
if (keyDefinitions[char]) {
|
||||||
await this.press(char, {delay});
|
await this.press(char, {delay});
|
||||||
else
|
} else {
|
||||||
await this.sendCharacter(char);
|
|
||||||
if (delay)
|
if (delay)
|
||||||
await new Promise(f => setTimeout(f, delay));
|
await new Promise(f => setTimeout(f, delay));
|
||||||
|
await this.sendCharacter(char);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +175,7 @@ class Keyboard {
|
|||||||
async press(key, options = {}) {
|
async press(key, options = {}) {
|
||||||
const {delay = null} = options;
|
const {delay = null} = options;
|
||||||
await this.down(key, options);
|
await this.down(key, options);
|
||||||
if (delay !== null)
|
if (delay)
|
||||||
await new Promise(f => setTimeout(f, options.delay));
|
await new Promise(f => setTimeout(f, options.delay));
|
||||||
await this.up(key);
|
await this.up(key);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user