From 6be597505026fdc006ce6e47f9b1795ad4626596 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 23 Aug 2018 10:03:37 +0200 Subject: [PATCH] dont assume new target is a new page --- src/session.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/session.js b/src/session.js index ba0384b91f..bcccc9d6cc 100644 --- a/src/session.js +++ b/src/session.js @@ -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); }); }