Fix for showing non-cached results

main
Elbert Alias 2 years ago
parent 13b41f01db
commit 5568246913

@ -37,6 +37,12 @@ function getRequiredTechnologies(name, categoryId) {
: undefined : undefined
} }
function isSimilarUrl(a, b) {
const normalise = (url) => String(url || '').replace(/(\/|\/?#.+)$/, '')
return normalise(a) === normalise(b)
}
const Driver = { const Driver = {
lastPing: Date.now(), lastPing: Date.now(),
@ -198,11 +204,13 @@ const Driver = {
url, url,
js js
.map(({ name, chain, value }) => { .map(({ name, chain, value }) => {
return analyzeManyToMany( const technology = technologies.find(
technologies.find(({ name: _name }) => name === _name), ({ name: _name }) => name === _name
'js',
{ [chain]: [value] }
) )
return technology
? analyzeManyToMany(technology, 'js', { [chain]: [value] })
: []
}) })
.flat() .flat()
) )
@ -230,6 +238,10 @@ const Driver = {
({ name: _name }) => name === _name ({ name: _name }) => name === _name
) )
if (!technology) {
return []
}
if (typeof exists !== 'undefined') { if (typeof exists !== 'undefined') {
return analyzeManyToMany(technology, 'dom.exists', { return analyzeManyToMany(technology, 'dom.exists', {
[selector]: [''], [selector]: [''],
@ -625,13 +637,7 @@ const Driver = {
) )
) )
const resolved = resolve(cache.detections).map((detection) => { const resolved = resolve(cache.detections).map((detection) => detection)
detection.cached = detection.lastUrl !== url
delete detection.lastUrl
return detection
})
const requires = [ const requires = [
...Wappalyzer.requires.filter(({ name }) => ...Wappalyzer.requires.filter(({ name }) =>
@ -652,22 +658,6 @@ const Driver = {
await Driver.setIcon(url, resolved) await Driver.setIcon(url, resolved)
/*
if (url) {
let tabs = []
try {
tabs = await promisify(chrome.tabs, 'query', {
url: globEscape(url),
})
} catch (error) {
// Continue
}
tabs.forEach(({ id }) => (Driver.cache.tabs[id] = resolved))
}
*/
Driver.log({ hostname, technologies: resolved }) Driver.log({ hostname, technologies: resolved })
await Driver.ping() await Driver.ping()
@ -698,8 +688,9 @@ const Driver = {
let icon = 'default.svg' let icon = 'default.svg'
const _technologies = technologies.filter( const _technologies = technologies.filter(
({ slug, cached }) => ({ slug, lastUrl }) =>
slug !== 'cart-functionality' && (showCached || cached === false) slug !== 'cart-functionality' &&
(showCached || isSimilarUrl(url, lastUrl))
) )
if (dynamicIcon) { if (dynamicIcon) {
@ -784,7 +775,7 @@ const Driver = {
const cache = Driver.cache.hostnames[hostname] const cache = Driver.cache.hostnames[hostname]
const resolved = (cache ? resolve(cache.detections) : []).filter( const resolved = (cache ? resolve(cache.detections) : []).filter(
({ cached }) => showCached || cached === false ({ lastUrl }) => showCached || isSimilarUrl(url, lastUrl)
) )
await Driver.setIcon(url, resolved) await Driver.setIcon(url, resolved)
@ -980,6 +971,28 @@ chrome.webRequest.onCompleted.addListener(Driver.onXhrRequestComplete, {
types: ['xmlhttprequest'], types: ['xmlhttprequest'],
}) })
chrome.tabs.onUpdated.addListener(async (id, { status, url }) => {
console.log({ id, status, url })
if (status === 'complete') {
;({ url } = await promisify(chrome.tabs, 'get', id))
}
if (url) {
const { hostname } = new URL(url)
const showCached = await getOption('showCached', true)
const cache = Driver.cache.hostnames[hostname]
const resolved = (cache ? resolve(cache.detections) : []).filter(
({ lastUrl }) => showCached || isSimilarUrl(url, lastUrl)
)
await Driver.setIcon(url, resolved)
}
})
// Enable messaging between scripts // Enable messaging between scripts
chrome.runtime.onMessage.addListener(Driver.onMessage) chrome.runtime.onMessage.addListener(Driver.onMessage)