diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index bc8bfebb5..e2731b347 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -21,6 +21,12 @@ const xhrDebounce = [] let xhrAnalyzed = {} +let initDone + +const initPromise = new Promise((resolve) => { + initDone = resolve +}) + function getRequiredTechnologies(name, categoryId) { return name ? Wappalyzer.requires.find(({ name: _name }) => _name === name).technologies @@ -66,66 +72,34 @@ const Driver = { }), {} ), - tabs: {}, robots: await getOption('robots', {}), ads: [], } - chrome.action.setBadgeBackgroundColor({ color: '#6B39BD' }, () => {}) - - chrome.webRequest.onCompleted.addListener( - Driver.onWebRequestComplete, - { urls: ['http://*/*', 'https://*/*'], types: ['main_frame'] }, - ['responseHeaders'] - ) - - chrome.webRequest.onCompleted.addListener(Driver.onScriptRequestComplete, { - urls: ['http://*/*', 'https://*/*'], - types: ['script'], - }) - - chrome.webRequest.onCompleted.addListener(Driver.onXhrRequestComplete, { - urls: ['http://*/*', 'https://*/*'], - types: ['xmlhttprequest'], - }) - - chrome.tabs.onRemoved.addListener((id) => delete Driver.cache.tabs[id]) - - chrome.tabs.onUpdated.addListener(async (id, { status, url }) => { - if (status === 'complete') { - ;({ url } = await promisify(chrome.tabs, 'get', id)) - } + const { version } = chrome.runtime.getManifest() + const previous = await getOption('version') + const upgradeMessage = await getOption('upgradeMessage', true) - if (url) { - const { hostname } = new URL(url) + await setOption('version', version) - const cache = Driver.cache.hostnames[hostname] + const current = await getOption('version') - Driver.cache.tabs[id] = cache ? resolve(cache.detections) : [] + if (!previous) { + await Driver.clearCache() - await Driver.setIcon(url, Driver.cache.tabs[id]) + if (current) { + open( + 'https://www.wappalyzer.com/installed/?utm_source=installed&utm_medium=extension&utm_campaign=wappalyzer' + ) } - }) - - // Enable messaging between scripts - chrome.runtime.onMessage.addListener(Driver.onMessage) - - const { version } = chrome.runtime.getManifest() - const previous = await getOption('version') - const upgradeMessage = await getOption('upgradeMessage', true) - - if (previous === null) { + } else if (version !== previous && upgradeMessage) { open( - 'https://www.wappalyzer.com/installed/?utm_source=installed&utm_medium=extension&utm_campaign=wappalyzer' + `https://www.wappalyzer.com/upgraded/?utm_source=upgraded&utm_medium=extension&utm_campaign=wappalyzer`, + false ) - } else if (version !== previous && upgradeMessage) { - // open( - // `https://www.wappalyzer.com/upgraded/?utm_source=upgraded&utm_medium=extension&utm_campaign=wappalyzer`, - // false - // ) } - await setOption('version', version) + initDone() }, /** @@ -327,7 +301,11 @@ const Driver = { return } - Promise.resolve(Driver[func].call(Driver[func], ...(args || []))) + new Promise(async (resolve) => { + await initPromise + + resolve(Driver[func].call(Driver[func], ...(args || []))) + }) .then(callback) .catch(Driver.error) @@ -673,6 +651,7 @@ const Driver = { await Driver.setIcon(url, resolved) + /* if (url) { let tabs = [] @@ -686,6 +665,7 @@ const Driver = { tabs.forEach(({ id }) => (Driver.cache.tabs[id] = resolved)) } + */ Driver.log({ hostname, technologies: resolved }) @@ -788,7 +768,7 @@ const Driver = { return } - const { id, url } = tab + const { url } = tab if (await Driver.isDisabledDomain(url)) { await Driver.setIcon(url, []) @@ -798,7 +778,11 @@ const Driver = { const showCached = await getOption('showCached', true) - const resolved = (Driver.cache.tabs[id] || []).filter( + const { hostname } = new URL(url) + + const cache = Driver.cache.hostnames[hostname] + + const resolved = (cache ? resolve(cache.detections) : []).filter( ({ cached }) => showCached || cached === false ) @@ -905,7 +889,6 @@ const Driver = { */ async clearCache() { Driver.cache.hostnames = {} - Driver.cache.tabs = {} xhrAnalyzed = {} @@ -978,4 +961,25 @@ const Driver = { }, } +chrome.action.setBadgeBackgroundColor({ color: '#6B39BD' }, () => {}) + +chrome.webRequest.onCompleted.addListener( + Driver.onWebRequestComplete, + { urls: ['http://*/*', 'https://*/*'], types: ['main_frame'] }, + ['responseHeaders'] +) + +chrome.webRequest.onCompleted.addListener(Driver.onScriptRequestComplete, { + urls: ['http://*/*', 'https://*/*'], + types: ['script'], +}) + +chrome.webRequest.onCompleted.addListener(Driver.onXhrRequestComplete, { + urls: ['http://*/*', 'https://*/*'], + types: ['xmlhttprequest'], +}) + +// Enable messaging between scripts +chrome.runtime.onMessage.addListener(Driver.onMessage) + Driver.init() diff --git a/src/drivers/webextension/js/popup.js b/src/drivers/webextension/js/popup.js index 6ec9d4642..b42f107a5 100644 --- a/src/drivers/webextension/js/popup.js +++ b/src/drivers/webextension/js/popup.js @@ -286,6 +286,8 @@ const Popup = { return templates }, {}) + Popup.onGetDetections() + // Disabled domains const dynamicIcon = await getOption('dynamicIcon', false) @@ -315,6 +317,7 @@ const Popup = { Popup.driver('getDetections').then(Popup.onGetDetections.bind(this)) } else { el.terms.classList.remove('terms--hidden') + el.empty.classList.add('empty--hidden') el.detections.classList.add('detections--hidden') el.issue.classList.add('issue--hidden') el.footer.classList.add('footer--hidden') @@ -538,6 +541,7 @@ const Popup = { * @param {Array} detections */ async onGetDetections(detections = []) { + console.log(detections, 'xxx') Popup.cache.detections = detections const el = { diff --git a/src/drivers/webextension/js/utils.js b/src/drivers/webextension/js/utils.js index 4f56b59f1..270d9a467 100644 --- a/src/drivers/webextension/js/utils.js +++ b/src/drivers/webextension/js/utils.js @@ -97,7 +97,7 @@ const Utils = { }, (response) => { chrome.runtime.lastError - ? reject(new Error(chrome.runtime.lastError.message)) + ? reject(chrome.runtime.lastError) : resolve(response) } )