|
|
|
@ -68,18 +68,19 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async visit(url) {
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
let done = false;
|
|
|
|
|
let browser;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
browser = await this.browser();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
|
reject(new Error(error.message || error.toString()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
browser.on('disconnected', () => {
|
|
|
|
|
if (!done) {
|
|
|
|
|
throw new Error('Disconnected');
|
|
|
|
|
reject(new Error('Disconnected'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -90,9 +91,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
await page.setRequestInterception(true);
|
|
|
|
|
|
|
|
|
|
page.on('error', (error) => {
|
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
|
});
|
|
|
|
|
page.on('error', reject);
|
|
|
|
|
|
|
|
|
|
page.on('request', request => request.continue());
|
|
|
|
|
|
|
|
|
@ -122,7 +121,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
await Promise.race([
|
|
|
|
|
page.goto(url, { waitUntil: 'networkidle2' }),
|
|
|
|
|
new Promise(resolve => setTimeout(resolve, this.options.maxWait)),
|
|
|
|
|
new Promise(_resolve => setTimeout(_resolve, this.options.maxWait)),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
@ -156,12 +155,13 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
this.html = await page.content();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
|
reject(error.message || error.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
done = true;
|
|
|
|
|
|
|
|
|
|
await browser.close();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|