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

@ -178,7 +178,7 @@ const Content = {
// Text // Text
// eslint-disable-next-line unicorn/prefer-text-content // 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 // CSS rules
let css = [] let css = []

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