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);
await page.setRequestInterception(true);
page.on('error', error => reject(new Error(`page error: ${error.message || error}`)));
page.on('response', (response) => {
try {
if (response.status() === 301 || response.status() === 302) {
return;
let responseReceived = false;
page.on('request', (request) => {
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) {
this.statusCode = response.status();
@ -105,6 +120,10 @@ class PuppeteerBrowser extends Browser {
this.contentType = headers['content-type'] || null;
}
if (response.status() < 300 || response.status() > 399) {
responseReceived = true;
}
} catch (error) {
reject(new Error(`page error: ${error.message || error}`));
}
@ -114,10 +133,16 @@ class PuppeteerBrowser extends Browser {
await page.setUserAgent(this.options.userAgent);
try {
await Promise.race([
page.goto(url, { waitUntil: 'domcontentloaded' }),
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
const links = await page.evaluateHandle(() => Array.from(document.getElementsByTagName('a')).map(({

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

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

Loading…
Cancel
Save