Prevent repeat analysis of the identical XHR requests

main
Elbert Alias 3 years ago
parent c84bcc6cdf
commit 7a3ed8add4

@ -721,7 +721,7 @@ class Site {
await this.promiseTimeout(
page.evaluateHandle(() =>
// eslint-disable-next-line unicorn/prefer-text-content
document.body.innerText.replace(/\s+/g, ' ')
document.body.innerText.replace(/\s+/g, ' ').slice(0, 25000)
),
{ jsonValue: () => '' },
'Timeout (text)'

@ -178,7 +178,7 @@ const Content = {
// Text
// eslint-disable-next-line unicorn/prefer-text-content
const text = document.body.innerText.replace(/\s+/g, ' ')
const text = document.body.innerText.replace(/\s+/g, ' ').slice(0, 25000)
// CSS rules
let css = []

@ -19,6 +19,8 @@ const hostnameIgnoreList =
const xhrDebounce = []
let xhrAnalyzed = {}
const scriptsPending = []
function getRequiredTechnologies(name, categoryId) {
@ -458,16 +460,34 @@ const Driver = {
return
}
let originHostname
try {
;({ hostname: originHostname } = new URL(request.originUrl))
} catch (error) {
return
}
if (!xhrDebounce.includes(hostname)) {
xhrDebounce.push(hostname)
setTimeout(async () => {
xhrDebounce.splice(xhrDebounce.indexOf(hostname), 1)
xhrAnalyzed[originHostname] = xhrAnalyzed[originHostname] || []
if (!xhrAnalyzed[originHostname].includes(hostname)) {
xhrAnalyzed[originHostname].push(hostname)
if (Object.keys(xhrAnalyzed).length > 500) {
xhrAnalyzed = {}
}
Driver.onDetect(
request.originUrl || request.initiator,
await analyze({ xhr: hostname })
).catch(Driver.error)
}
}, 1000)
}
},
@ -886,6 +906,8 @@ const Driver = {
Driver.cache.hostnames = {}
Driver.cache.tabs = {}
xhrAnalyzed = {}
await setOption('hostnames', {})
},