|
|
|
@ -57,11 +57,12 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
super(options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
visit(url) {
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
async visit(url) {
|
|
|
|
|
let done = false;
|
|
|
|
|
let browser;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await new Promise(async (resolve, _reject) => {
|
|
|
|
|
try {
|
|
|
|
|
browser = await puppeteer.launch(chromium ? {
|
|
|
|
|
args: [...chromium.args, '--ignore-certificate-errors'],
|
|
|
|
@ -75,7 +76,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
browser.on('disconnected', () => {
|
|
|
|
|
if (!done) {
|
|
|
|
|
reject(new Error('browser: disconnected'));
|
|
|
|
|
_reject(new Error('browser: disconnected'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -83,7 +84,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
page.setDefaultTimeout(this.options.maxWait * 2);
|
|
|
|
|
|
|
|
|
|
page.on('error', error => reject(new Error(`page error: ${error.message || error}`)));
|
|
|
|
|
page.on('error', error => _reject(new Error(`page error: ${error.message || error}`)));
|
|
|
|
|
|
|
|
|
|
page.on('response', (response) => {
|
|
|
|
|
try {
|
|
|
|
@ -105,7 +106,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reject(new Error(`page error: ${error.message || error}`));
|
|
|
|
|
_reject(new Error(`page error: ${error.message || error}`));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -155,19 +156,22 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reject(new Error(`visit error: ${error.message || error}`));
|
|
|
|
|
} finally {
|
|
|
|
|
_reject(new Error(`visit error: ${error.message || error}`));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
done = true;
|
|
|
|
|
|
|
|
|
|
if (browser) {
|
|
|
|
|
try {
|
|
|
|
|
await browser.close();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
this.log(error.message || error.toString(), 'error');
|
|
|
|
|
} catch (_error) {
|
|
|
|
|
this.log(_error.message || _error.toString(), 'error');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|