dont assume new target is a new page
This commit is contained in:
parent
f49b85897d
commit
6be5975050
1 changed files with 6 additions and 2 deletions
|
@ -164,17 +164,21 @@ module.exports = class RiotSession {
|
|||
waitForNewPage(timeout = 5000) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutHandle = setTimeout(() => {
|
||||
this.browser.removeEventListener('targetcreated', callback);
|
||||
this.browser.removeListener('targetcreated', callback);
|
||||
reject(new Error(`timeout of ${timeout}ms for waitForNewPage elapsed`));
|
||||
}, timeout);
|
||||
|
||||
const callback = async (target) => {
|
||||
if (target.type() !== 'page') {
|
||||
return;
|
||||
}
|
||||
this.browser.removeListener('targetcreated', callback);
|
||||
clearTimeout(timeoutHandle);
|
||||
const page = await target.page();
|
||||
resolve(page);
|
||||
};
|
||||
|
||||
this.browser.once('targetcreated', callback);
|
||||
this.browser.on('targetcreated', callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue