|
|
@ -55,8 +55,15 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
options.maxWait = options.maxWait || 60;
|
|
|
|
options.maxWait = options.maxWait || 60;
|
|
|
|
|
|
|
|
|
|
|
|
super(options);
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
visit(url) {
|
|
|
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
|
|
|
let done = false;
|
|
|
|
|
|
|
|
let browser;
|
|
|
|
|
|
|
|
|
|
|
|
this.browser = async () => puppeteer.launch(chromium ? {
|
|
|
|
try {
|
|
|
|
|
|
|
|
browser = await puppeteer.launch(chromium ? {
|
|
|
|
args: [...chromium.args, '--ignore-certificate-errors'],
|
|
|
|
args: [...chromium.args, '--ignore-certificate-errors'],
|
|
|
|
defaultViewport: chromium.defaultViewport,
|
|
|
|
defaultViewport: chromium.defaultViewport,
|
|
|
|
executablePath: await chromium.executablePath,
|
|
|
|
executablePath: await chromium.executablePath,
|
|
|
@ -65,19 +72,6 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
args: ['--no-sandbox', '--headless', '--disable-gpu', '--ignore-certificate-errors'],
|
|
|
|
args: ['--no-sandbox', '--headless', '--disable-gpu', '--ignore-certificate-errors'],
|
|
|
|
executablePath: CHROME_BIN,
|
|
|
|
executablePath: CHROME_BIN,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async visit(url) {
|
|
|
|
|
|
|
|
let done = false;
|
|
|
|
|
|
|
|
let browser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await new Promise(async (resolve, reject) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
browser = await this.browser();
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
return reject(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
browser.on('disconnected', () => {
|
|
|
|
browser.on('disconnected', () => {
|
|
|
|
if (!done) {
|
|
|
|
if (!done) {
|
|
|
@ -85,7 +79,6 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const page = await browser.newPage();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
|
|
|
|
|
|
|
page.setDefaultTimeout(this.options.maxWait);
|
|
|
|
page.setDefaultTimeout(this.options.maxWait);
|
|
|
@ -93,6 +86,7 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
page.on('error', reject);
|
|
|
|
page.on('error', reject);
|
|
|
|
|
|
|
|
|
|
|
|
page.on('response', (response) => {
|
|
|
|
page.on('response', (response) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (response.status() === 301 || response.status() === 302) {
|
|
|
|
if (response.status() === 301 || response.status() === 302) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -110,6 +104,9 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
|
|
|
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
reject(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type));
|
|
|
|
page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type));
|
|
|
@ -151,20 +148,23 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
this.html = await page.content();
|
|
|
|
this.html = await page.content();
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
return reject(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resolve();
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
throw new Error(error.message || error.toString());
|
|
|
|
reject(error);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
done = true;
|
|
|
|
done = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (browser) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
await browser.close();
|
|
|
|
await browser.close();
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
this.log(error.message || error.toString, 'error');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = PuppeteerBrowser;
|
|
|
|
module.exports = PuppeteerBrowser;
|
|
|
|