mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Add delay option to input methods (#171)
Add delay option to input methods for the keyboard and mouse. Closes #156
This commit is contained in:
committed by
Andrey Lushnikov
parent
97f80d243c
commit
fc70ab8f21
15
lib/Page.js
15
lib/Page.js
@@ -532,12 +532,19 @@ class Page extends EventEmitter {
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @param {{delay: (number|undefined)}=} options
|
||||
* @return {!Promise}
|
||||
*/
|
||||
async type(text) {
|
||||
async type(text, options) {
|
||||
let delay = 0;
|
||||
if (options && options.delay)
|
||||
delay = options.delay;
|
||||
let last;
|
||||
for (let char of text)
|
||||
last = this.press(char, {text: char});
|
||||
for (let char of text) {
|
||||
last = this.press(char, {text: char, delay});
|
||||
if (delay)
|
||||
await new Promise(f => setTimeout(f, delay));
|
||||
}
|
||||
await last;
|
||||
}
|
||||
|
||||
@@ -548,6 +555,8 @@ class Page extends EventEmitter {
|
||||
*/
|
||||
async press(key, options) {
|
||||
this._keyboard.down(key, options);
|
||||
if (options && options.delay)
|
||||
await new Promise(f => setTimeout(f, options.delay));
|
||||
await this._keyboard.up(key);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user