Prevent in-page navigation in NPM/Puppeteer driver

main
Elbert Alias 5 years ago
parent 93acdd7d6f
commit 0d7f38ce51

@ -84,14 +84,29 @@ class PuppeteerBrowser extends Browser {
page.setDefaultTimeout(this.options.maxWait * 2); page.setDefaultTimeout(this.options.maxWait * 2);
await page.setRequestInterception(true);
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) => { let responseReceived = false;
try {
if (response.status() === 301 || response.status() === 302) { page.on('request', (request) => {
return; if (
responseReceived
&& request.isNavigationRequest()
&& request.frame() === page.mainFrame()
&& request.url() !== url
) {
this.log(`abort navigation to ${request.url()}`);
request.abort('aborted');
} else {
request.continue();
} }
});
page.on('response', (response) => {
try {
if (!this.statusCode) { if (!this.statusCode) {
this.statusCode = response.status(); this.statusCode = response.status();
@ -105,6 +120,10 @@ class PuppeteerBrowser extends Browser {
this.contentType = headers['content-type'] || null; this.contentType = headers['content-type'] || null;
} }
if (response.status() < 300 || response.status() > 399) {
responseReceived = true;
}
} catch (error) { } catch (error) {
reject(new Error(`page error: ${error.message || error}`)); reject(new Error(`page error: ${error.message || error}`));
} }
@ -114,10 +133,16 @@ class PuppeteerBrowser extends Browser {
await page.setUserAgent(this.options.userAgent); await page.setUserAgent(this.options.userAgent);
try {
await Promise.race([ await Promise.race([
page.goto(url, { waitUntil: 'domcontentloaded' }), page.goto(url, { waitUntil: 'domcontentloaded' }),
new Promise((_resolve, _reject) => setTimeout(() => _reject(new Error('timeout')), this.options.maxWait)), new Promise((_resolve, _reject) => setTimeout(() => _reject(new Error('timeout')), this.options.maxWait)),
]); ]);
} catch (error) {
if (!this.statusCode) {
throw new Error(error.message || error.toString());
}
}
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({ const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({

@ -2,7 +2,7 @@
"name": "wappalyzer", "name": "wappalyzer",
"description": "Uncovers the technologies used on websites", "description": "Uncovers the technologies used on websites",
"homepage": "https://www.wappalyzer.com", "homepage": "https://www.wappalyzer.com",
"version": "5.9.25", "version": "5.9.26",
"author": "Elbert Alias", "author": "Elbert Alias",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

@ -4,7 +4,7 @@
"author": "Elbert Alias", "author": "Elbert Alias",
"homepage_url": "https://www.wappalyzer.com", "homepage_url": "https://www.wappalyzer.com",
"description": "Identify web technologies", "description": "Identify web technologies",
"version": "5.9.25", "version": "5.9.26",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

Loading…
Cancel
Save