|
|
|
@ -46,44 +46,43 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async visit(url) {
|
|
|
|
|
const browser = await this.browser();
|
|
|
|
|
try {
|
|
|
|
|
const browser = await this.browser();
|
|
|
|
|
|
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
|
|
|
|
|
await page.setRequestInterception(true);
|
|
|
|
|
page.setDefaultTimeout(this.options.maxWait);
|
|
|
|
|
|
|
|
|
|
page.on('request', request => request.continue());
|
|
|
|
|
await page.setRequestInterception(true);
|
|
|
|
|
|
|
|
|
|
page.on('response', (response) => {
|
|
|
|
|
if (response.status() === 301 || response.status() === 302) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
page.on('request', request => request.continue());
|
|
|
|
|
|
|
|
|
|
if (!this.statusCode) {
|
|
|
|
|
this.statusCode = response.status();
|
|
|
|
|
page.on('response', (response) => {
|
|
|
|
|
if (response.status() === 301 || response.status() === 302) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.headers = {};
|
|
|
|
|
if (!this.statusCode) {
|
|
|
|
|
this.statusCode = response.status();
|
|
|
|
|
|
|
|
|
|
const headers = response.headers();
|
|
|
|
|
this.headers = {};
|
|
|
|
|
|
|
|
|
|
Object.keys(headers).forEach((key) => {
|
|
|
|
|
this.headers[key] = Array.isArray(headers[key]) ? headers[key] : [headers[key]];
|
|
|
|
|
});
|
|
|
|
|
const headers = response.headers();
|
|
|
|
|
|
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
Object.keys(headers).forEach((key) => {
|
|
|
|
|
this.headers[key] = Array.isArray(headers[key]) ? headers[key] : [headers[key]];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type));
|
|
|
|
|
this.contentType = headers['content-type'] || null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await page.setUserAgent(this.options.userAgent);
|
|
|
|
|
page.on('console', ({ _type, _text, _location }) => this.log(`${_text} (${_location.url}: ${_location.lineNumber})`, _type));
|
|
|
|
|
|
|
|
|
|
await page.setUserAgent(this.options.userAgent);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await Promise.race([
|
|
|
|
|
page.goto(url, {
|
|
|
|
|
timeout: this.options.maxWait,
|
|
|
|
|
waitUntil: 'networkidle2',
|
|
|
|
|
}),
|
|
|
|
|
page.goto(url, { waitUntil: 'networkidle2' }),
|
|
|
|
|
new Promise(resolve => setTimeout(resolve, this.options.maxWait)),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
@ -117,13 +116,11 @@ class PuppeteerBrowser extends Browser {
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
this.html = await page.content();
|
|
|
|
|
|
|
|
|
|
await page.close();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw new Error(error.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await page.close();
|
|
|
|
|
|
|
|
|
|
this.page = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|