|
|
@ -62,7 +62,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
let browser;
|
|
|
|
let browser;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await new Promise(async (resolve, _reject) => {
|
|
|
|
await new Promise(async (resolve, reject) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
browser = await puppeteer.launch(chromium ? {
|
|
|
|
browser = await puppeteer.launch(chromium ? {
|
|
|
|
args: [...chromium.args, '--ignore-certificate-errors'],
|
|
|
|
args: [...chromium.args, '--ignore-certificate-errors'],
|
|
|
@ -70,13 +70,13 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
executablePath: await chromium.executablePath,
|
|
|
|
executablePath: await chromium.executablePath,
|
|
|
|
headless: chromium.headless,
|
|
|
|
headless: chromium.headless,
|
|
|
|
} : {
|
|
|
|
} : {
|
|
|
|
args: ['--no-sandbox', '--headless', '--disable-gpu', '--ignore-certificate-errors', '--disable-dev-shm-usage'],
|
|
|
|
args: ['--no-sandbox', '--headless', '--disable-gpu', '--ignore-certificate-errors'],
|
|
|
|
executablePath: CHROME_BIN,
|
|
|
|
executablePath: CHROME_BIN,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
browser.on('disconnected', () => {
|
|
|
|
browser.on('disconnected', () => {
|
|
|
|
if (!done) {
|
|
|
|
if (!done) {
|
|
|
|
_reject(new Error('browser: disconnected'));
|
|
|
|
reject(new Error('browser: disconnected'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -84,7 +84,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
|
|
page.setDefaultTimeout(this.options.maxWait * 2);
|
|
|
|
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) => {
|
|
|
|
page.on('response', (response) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -106,7 +106,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
_reject(new Error(`page error: ${error.message || error}`));
|
|
|
|
reject(new Error(`page error: ${error.message || error}`));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -117,7 +117,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
await Promise.race([
|
|
|
|
await Promise.race([
|
|
|
|
page.goto(url, { waitUntil: 'domcontentloaded' }),
|
|
|
|
page.goto(url, { waitUntil: 'domcontentloaded' }),
|
|
|
|
new Promise(_resolve => setTimeout(() => {
|
|
|
|
new Promise(_resolve => setTimeout(() => {
|
|
|
|
this.log('Timeout', 'error');
|
|
|
|
this.log('timeout', 'error');
|
|
|
|
|
|
|
|
|
|
|
|
_resolve();
|
|
|
|
_resolve();
|
|
|
|
}, this.options.maxWait)),
|
|
|
|
}, this.options.maxWait)),
|
|
|
@ -156,21 +156,25 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
resolve();
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
_reject(new Error(`visit error: ${error.message || error}`));
|
|
|
|
reject(new Error(`visit error: ${error.message || error}`));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
this.log(`visit error: ${error.message || error}`, 'error');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
done = true;
|
|
|
|
done = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (browser) {
|
|
|
|
if (browser) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await browser.close();
|
|
|
|
await browser.close();
|
|
|
|
} catch (_error) {
|
|
|
|
|
|
|
|
this.log(_error.message || _error.toString(), 'error');
|
|
|
|
this.log('browser close ok');
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
this.log(`browser close error: ${error.message || error}`, 'error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|