Potential fix for caching issue

main
Elbert Alias 3 years ago
parent a778181ccd
commit 5f9d939cee

@ -31,7 +31,7 @@ function getJs(technologies) {
}) })
} }
script.setAttribute('src', chrome.extension.getURL('js/inject.js')) script.setAttribute('src', chrome.runtime.getURL('js/inject.js'))
document.body.appendChild(script) document.body.appendChild(script)
}) })
@ -129,7 +129,9 @@ const Content = {
* Initialise content script * Initialise content script
*/ */
async init() { async init() {
if (await Content.driver('isDisabledDomain', location.href)) { const url = location.href
if (await Content.driver('isDisabledDomain', url)) {
return return
} }
@ -236,7 +238,7 @@ const Content = {
Content.cache = { html, css, scripts, meta } Content.cache = { html, css, scripts, meta }
await Content.driver('onContentLoad', [ await Content.driver('onContentLoad', [
location.href, url,
Content.cache, Content.cache,
Content.language, Content.language,
]) ])
@ -313,7 +315,7 @@ const Content = {
}) })
}, },
async analyzeRequires(requires) { async analyzeRequires(url, requires) {
await Promise.all( await Promise.all(
Object.keys(requires).map(async (name) => { Object.keys(requires).map(async (name) => {
if (!Content.analyzedRequires.includes(name)) { if (!Content.analyzedRequires.includes(name)) {
@ -324,7 +326,7 @@ const Content = {
await Promise.all([ await Promise.all([
Content.onGetTechnologies(technologies, name), Content.onGetTechnologies(technologies, name),
Content.driver('onContentLoad', [ Content.driver('onContentLoad', [
location.href, url,
Content.cache, Content.cache,
Content.language, Content.language,
name, name,
@ -340,12 +342,14 @@ const Content = {
* @param {Array} technologies * @param {Array} technologies
*/ */
async onGetTechnologies(technologies = [], requires) { async onGetTechnologies(technologies = [], requires) {
const url = location.href
const js = await getJs(technologies) const js = await getJs(technologies)
const dom = getDom(technologies) const dom = getDom(technologies)
await Promise.all([ await Promise.all([
Content.driver('analyzeJs', [location.href, js, requires]), Content.driver('analyzeJs', [url, js, requires]),
Content.driver('analyzeDom', [location.href, dom, requires]), Content.driver('analyzeDom', [url, dom, requires]),
]) ])
}, },
} }

@ -137,7 +137,7 @@ const Driver = {
async loadTechnologies() { async loadTechnologies() {
try { try {
const { technologies, categories } = await ( const { technologies, categories } = await (
await fetch(chrome.extension.getURL('technologies.json')) await fetch(chrome.runtime.getURL('technologies.json'))
).json() ).json()
setTechnologies(technologies) setTechnologies(technologies)
@ -503,6 +503,8 @@ const Driver = {
cache.dateTime = Date.now() cache.dateTime = Date.now()
console.log('xxx', { url, hostname, cache, detections })
// Remove duplicates // Remove duplicates
cache.detections = cache.detections cache.detections = cache.detections
.concat(detections) .concat(detections)
@ -588,7 +590,7 @@ const Driver = {
) )
try { try {
await Driver.content(url, 'analyzeRequires', [requires]) await Driver.content(url, 'analyzeRequires', [url, requires])
} catch (error) { } catch (error) {
// Continue // Continue
} }
@ -682,7 +684,7 @@ const Driver = {
chrome.browserAction.setIcon( chrome.browserAction.setIcon(
{ {
tabId, tabId,
path: chrome.extension.getURL( path: chrome.runtime.getURL(
`../images/icons/${ `../images/icons/${
/\.svg$/i.test(icon) /\.svg$/i.test(icon)
? `converted/${icon.replace(/\.svg$/, '.png')}` ? `converted/${icon.replace(/\.svg$/, '.png')}`

@ -3,9 +3,9 @@
/* globals chrome */ /* globals chrome */
const Utils = { const Utils = {
agent: chrome.extension.getURL('/').startsWith('moz-') agent: chrome.runtime.getURL('/').startsWith('moz-')
? 'firefox' ? 'firefox'
: chrome.extension.getURL('/').startsWith('safari-') : chrome.runtime.getURL('/').startsWith('safari-')
? 'safari' ? 'safari'
: 'chrome', : 'chrome',