Add timeout to evaluateHandle calls

main
Elbert Alias 4 years ago
parent 94c275b195
commit 892fe1ac14

@ -195,6 +195,14 @@ class Site {
} }
} }
timeout() {
return new Promise(() =>
setTimeout(() => {
throw new Error('The website took too long to respond')
}, this.options.maxWait)
)
}
async goto(url) { async goto(url) {
// Return when the URL is a duplicate or maxUrls has been reached // Return when the URL is a duplicate or maxUrls has been reached
if ( if (
@ -292,22 +300,16 @@ class Site {
try { try {
await Promise.race([ await Promise.race([
page.goto(url.href, { waitUntil: 'domcontentloaded' }), this.timeout(),
new Promise((resolve, reject) => page.goto(url.href, { waitUntil: 'domcontentloaded' })
setTimeout(
() => reject(new Error('The website took too long to respond')),
this.options.maxWait
)
)
]) ])
} catch (error) {
this.error(error)
}
await sleep(1000) await sleep(1000)
// Links // Links
const links = await ( const links = await Promise.race([
this.timeout(),
await (
await page.evaluateHandle(() => await page.evaluateHandle(() =>
Array.from(document.getElementsByTagName('a')).map( Array.from(document.getElementsByTagName('a')).map(
({ hash, hostname, href, pathname, protocol, rel }) => ({ ({ hash, hostname, href, pathname, protocol, rel }) => ({
@ -321,33 +323,46 @@ class Site {
) )
) )
).jsonValue() ).jsonValue()
])
// Script tags // Script tags
const scripts = await ( const scripts = await Promise.race([
this.timeout(),
await (
await page.evaluateHandle(() => await page.evaluateHandle(() =>
Array.from(document.getElementsByTagName('script')) Array.from(document.getElementsByTagName('script'))
.map(({ src }) => src) .map(({ src }) => src)
.filter((src) => src) .filter((src) => src)
) )
).jsonValue() ).jsonValue()
])
// Meta tags // Meta tags
const meta = await ( const meta = await Promise.race([
this.timeout(),
await (
await page.evaluateHandle(() => await page.evaluateHandle(() =>
Array.from(document.querySelectorAll('meta')).reduce((metas, meta) => { Array.from(document.querySelectorAll('meta')).reduce(
const key = meta.getAttribute('name') || meta.getAttribute('property') (metas, meta) => {
const key =
meta.getAttribute('name') || meta.getAttribute('property')
if (key) { if (key) {
metas[key.toLowerCase()] = [meta.getAttribute('content')] metas[key.toLowerCase()] = [meta.getAttribute('content')]
} }
return metas return metas
}, {}) },
{}
)
) )
).jsonValue() ).jsonValue()
])
// JavaScript // JavaScript
const js = await page.evaluate( const js = await Promise.race([
this.timeout(),
await page.evaluate(
(technologies) => { (technologies) => {
return technologies.reduce((technologies, { name, chains }) => { return technologies.reduce((technologies, { name, chains }) => {
chains.forEach((chain) => { chains.forEach((chain) => {
@ -380,6 +395,7 @@ class Site {
.filter(({ js }) => Object.keys(js).length) .filter(({ js }) => Object.keys(js).length)
.map(({ name, js }) => ({ name, chains: Object.keys(js) })) .map(({ name, js }) => ({ name, chains: Object.keys(js) }))
) )
])
// Cookies // Cookies
const cookies = (await page.cookies()).reduce( const cookies = (await page.cookies()).reduce(
@ -424,13 +440,16 @@ class Site {
} }
if (!this.language) { if (!this.language) {
this.language = await ( this.language = await Promise.race([
this.timeout(),
await (
await page.evaluateHandle( await page.evaluateHandle(
() => () =>
document.documentElement.getAttribute('lang') || document.documentElement.getAttribute('lang') ||
document.documentElement.getAttribute('xml:lang') document.documentElement.getAttribute('xml:lang')
) )
).jsonValue() ).jsonValue()
])
} }
if (!this.language) { if (!this.language) {
@ -490,6 +509,9 @@ class Site {
this.emit('goto', url) this.emit('goto', url)
return reducedLinks return reducedLinks
} catch (error) {
this.error(error)
}
} }
async analyze(url = this.originalUrl, index = 1, depth = 1) { async analyze(url = this.originalUrl, index = 1, depth = 1) {

@ -13,7 +13,7 @@
"software" "software"
], ],
"homepage": "https://www.wappalyzer.com", "homepage": "https://www.wappalyzer.com",
"version": "6.1.1", "version": "6.2.0",
"author": "Wappalyzer", "author": "Wappalyzer",
"license": "MIT", "license": "MIT",
"repository": { "repository": {

@ -4,7 +4,7 @@
"author": "Wappalyzer", "author": "Wappalyzer",
"homepage_url": "https://www.wappalyzer.com", "homepage_url": "https://www.wappalyzer.com",
"description": "Identify web technologies", "description": "Identify web technologies",
"version": "6.0.16", "version": "6.2.0",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

@ -13,7 +13,7 @@
"software" "software"
], ],
"homepage": "https://www.wappalyzer.com", "homepage": "https://www.wappalyzer.com",
"version": "6.1.1", "version": "6.2.0",
"author": "Wappalyzer", "author": "Wappalyzer",
"license": "MIT", "license": "MIT",
"repository": { "repository": {

Loading…
Cancel
Save