Add 1s delay in WebExtension driver, fix links in popup

main
Elbert Alias 5 years ago
parent e36ae46783
commit eae4350627

@ -13,7 +13,7 @@
"software" "software"
], ],
"homepage": "https://www.wappalyzer.com", "homepage": "https://www.wappalyzer.com",
"version": "6.0.1", "version": "5.10.2",
"author": "Wappalyzer", "author": "Wappalyzer",
"license": "MIT", "license": "MIT",
"repository": { "repository": {

@ -5,83 +5,90 @@
/* eslint-env browser */ /* eslint-env browser */
const port = browser.runtime.connect({ const port = browser.runtime.connect({
name: 'content.js', name: 'content.js'
}); })
if (typeof browser !== 'undefined' && typeof document.body !== 'undefined') { ;(async function() {
try { if (typeof browser !== 'undefined' && typeof document.body !== 'undefined') {
port.postMessage({ id: 'init' }); await new Promise((resolve) => setTimeout(resolve, 1000))
// HTML try {
let html = new XMLSerializer().serializeToString(document); port.postMessage({ id: 'init' })
const chunks = []; // HTML
const maxCols = 2000; let html = new XMLSerializer().serializeToString(document)
const maxRows = 3000;
const rows = html.length / maxCols;
let i; const chunks = []
const maxCols = 2000
const maxRows = 3000
const rows = html.length / maxCols
for (i = 0; i < rows; i += 1) { let i
if (i < maxRows / 2 || i > rows - maxRows / 2) {
chunks.push(html.slice(i * maxCols, (i + 1) * maxCols)); for (i = 0; i < rows; i += 1) {
if (i < maxRows / 2 || i > rows - maxRows / 2) {
chunks.push(html.slice(i * maxCols, (i + 1) * maxCols))
}
} }
}
html = chunks.join('\n'); html = chunks.join('\n')
// Scripts // Scripts
const scripts = Array.prototype.slice const scripts = Array.prototype.slice
.apply(document.scripts) .apply(document.scripts)
.filter(script => script.src) .filter((script) => script.src)
.map(script => script.src) .map((script) => script.src)
.filter(script => script.indexOf('data:text/javascript;') !== 0); .filter((script) => script.indexOf('data:text/javascript;') !== 0)
port.postMessage({ id: 'analyze', subject: { html, scripts } }); port.postMessage({ id: 'analyze', subject: { html, scripts } })
// JavaScript variables // JavaScript variables
const script = document.createElement('script'); const script = document.createElement('script')
script.onload = () => { script.onload = () => {
const onMessage = (event) => { const onMessage = (event) => {
if (event.data.id !== 'js') { if (event.data.id !== 'js') {
return; return
} }
window.removeEventListener('message', onMessage); window.removeEventListener('message', onMessage)
port.postMessage({ id: 'analyze', subject: { js: event.data.js } }); port.postMessage({ id: 'analyze', subject: { js: event.data.js } })
script.remove(); script.remove()
}; }
window.addEventListener('message', onMessage); window.addEventListener('message', onMessage)
port.postMessage({ id: 'get_js_patterns' }); port.postMessage({ id: 'get_js_patterns' })
}; }
script.setAttribute('src', browser.extension.getURL('js/inject.js')); script.setAttribute('src', browser.extension.getURL('js/inject.js'))
document.body.appendChild(script); document.body.appendChild(script)
} catch (error) { } catch (error) {
port.postMessage({ id: 'log', subject: error }); port.postMessage({ id: 'log', subject: error })
}
} }
} })()
port.onMessage.addListener((message) => { port.onMessage.addListener((message) => {
switch (message.id) { switch (message.id) {
case 'get_js_patterns': case 'get_js_patterns':
postMessage({ postMessage(
id: 'patterns', {
patterns: message.response.patterns, id: 'patterns',
}, window.location.href); patterns: message.response.patterns
},
break; window.location.href
)
break
default: default:
// Do nothing // Do nothing
} }
}); })
// https://stackoverflow.com/a/44774834 // https://stackoverflow.com/a/44774834
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/executeScript#Return_value // https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/executeScript#Return_value
undefined; // eslint-disable-line no-unused-expressions undefined // eslint-disable-line no-unused-expressions

@ -354,14 +354,17 @@ wappalyzer.driver.getRobotsTxt = async (host, secure = false) => {
/** /**
* Anonymously track detected applications for research purposes * Anonymously track detected applications for research purposes
*/ */
wappalyzer.driver.ping = async (hostnameCache = {}, adCache = []) => { wappalyzer.driver.ping = async (
hostnameCache = { expires: 0, hostnames: {} },
adCache = []
) => {
const tracking = await getOption('tracking', true) const tracking = await getOption('tracking', true)
const termsAccepted = const termsAccepted =
userAgent() === 'chrome' || (await getOption('termsAccepted', false)) userAgent() === 'chrome' || (await getOption('termsAccepted', false))
if (tracking && termsAccepted) { if (tracking && termsAccepted) {
if (Object.keys(hostnameCache).length) { if (Object.keys(hostnameCache.hostnames).length) {
post('https://api.wappalyzer.com/ping/v1/', hostnameCache) post('https://api.wappalyzer.com/ping/v1/', hostnameCache.hostnames)
} }
if (adCache.length) { if (adCache.length) {
@ -404,16 +407,19 @@ wappalyzer.driver.ping = async (hostnameCache = {}, adCache = []) => {
url: `${wappalyzer.config.websiteURL}installed` url: `${wappalyzer.config.websiteURL}installed`
}) })
} else if (version !== previousVersion && upgradeMessage) { } else if (version !== previousVersion && upgradeMessage) {
openTab({ // openTab({
url: `${wappalyzer.config.websiteURL}upgraded?v${version}`, // url: `${wappalyzer.config.websiteURL}upgraded?v${version}`,
background: true // background: true
}) // })
} }
await setOption('version', version) await setOption('version', version)
// Hostname cache // Hostname cache
wappalyzer.hostnameCache = await getOption('hostnameCache', {}) wappalyzer.hostnameCache = await getOption('hostnameCache', {
expires: Date.now() + 1000 * 60 * 60 * 24,
hostnames: {}
})
// Run content script on all tabs // Run content script on all tabs
try { try {

@ -1,52 +1,54 @@
/* eslint-env browser */ /* eslint-env browser */
/* eslint-disable no-restricted-globals, no-prototype-builtins */ /* eslint-disable no-restricted-globals, no-prototype-builtins */
(() => { ;(() => {
try { try {
const detectJs = (chain) => { const detectJs = (chain) => {
const properties = chain.split('.'); const properties = chain.split('.')
let value = properties.length ? window : null; let value = properties.length ? window : null
for (let i = 0; i < properties.length; i += 1) { for (let i = 0; i < properties.length; i += 1) {
const property = properties[i]; const property = properties[i]
if (value && value.hasOwnProperty(property)) { if (value && value.hasOwnProperty(property)) {
value = value[property]; value = value[property]
} else { } else {
value = null; value = null
break; break
} }
} }
return typeof value === 'string' || typeof value === 'number' ? value : !!value; return typeof value === 'string' || typeof value === 'number'
}; ? value
: !!value
}
const onMessage = (event) => { const onMessage = (event) => {
if (event.data.id !== 'patterns') { if (event.data.id !== 'patterns') {
return; return
} }
removeEventListener('message', onMessage); removeEventListener('message', onMessage)
const patterns = event.data.patterns || {}; const patterns = event.data.patterns || {}
const js = {}; const js = {}
for (const appName in patterns) { for (const appName in patterns) {
if (patterns.hasOwnProperty(appName)) { if (patterns.hasOwnProperty(appName)) {
js[appName] = {}; js[appName] = {}
for (const chain in patterns[appName]) { for (const chain in patterns[appName]) {
if (patterns[appName].hasOwnProperty(chain)) { if (patterns[appName].hasOwnProperty(chain)) {
js[appName][chain] = {}; js[appName][chain] = {}
for (const index in patterns[appName][chain]) { for (const index in patterns[appName][chain]) {
const value = detectJs(chain); const value = detectJs(chain)
if (value && patterns[appName][chain].hasOwnProperty(index)) { if (value && patterns[appName][chain].hasOwnProperty(index)) {
js[appName][chain][index] = value; js[appName][chain][index] = value
} }
} }
} }
@ -54,11 +56,11 @@
} }
} }
postMessage({ id: 'js', js }, window.location.href); postMessage({ id: 'js', js }, window.location.href)
}; }
addEventListener('message', onMessage); addEventListener('message', onMessage)
} catch (e) { } catch (e) {
// Fail quietly // Fail quietly
} }
})(); })()

@ -70,6 +70,14 @@ function replaceDom(domTemplate) {
}) })
}) })
}) })
Array.from(document.querySelectorAll('a')).forEach((link) => {
link.addEventListener('click', () => {
browser.tabs.create({ url: link.href })
return false
})
})
} }
function replaceDomWhenReady(dom) { function replaceDomWhenReady(dom) {

@ -4,7 +4,7 @@
"author": "Wappalyzer", "author": "Wappalyzer",
"homepage_url": "https://www.wappalyzer.com", "homepage_url": "https://www.wappalyzer.com",
"description": "Identify web technologies", "description": "Identify web technologies",
"version": "5.10.1", "version": "5.10.2",
"default_locale": "en", "default_locale": "en",
"manifest_version": 2, "manifest_version": 2,
"icons": { "icons": {

@ -131,7 +131,10 @@ class Wappalyzer {
this.driver = {} this.driver = {}
this.jsPatterns = {} this.jsPatterns = {}
this.detected = {} this.detected = {}
this.hostnameCache = {} this.hostnameCache = {
expires: Date.now() + 1000 * 60 * 60 * 24,
hostnames: {}
}
this.adCache = [] this.adCache = []
this.config = { this.config = {
@ -347,10 +350,17 @@ class Wappalyzer {
* *
*/ */
ping() { ping() {
if (Object.keys(this.hostnameCache).length > 50) { if (
!this.hostnameCache.hostnames ||
Object.keys(this.hostnameCache.hostnames).length > 50 ||
this.hostnameCache.expires < Date.now()
) {
this.driver.ping(this.hostnameCache) this.driver.ping(this.hostnameCache)
this.hostnameCache = {} this.hostnameCache = {
expires: Date.now() + 1000 * 60 * 60 * 24,
hostnames: {}
}
} }
if (this.adCache.length > 50) { if (this.adCache.length > 50) {
@ -517,31 +527,34 @@ class Wappalyzer {
validation.hostname.test(url.hostname) && validation.hostname.test(url.hostname) &&
!validation.hostnameBlacklist.test(url.hostname) !validation.hostnameBlacklist.test(url.hostname)
) { ) {
if (!(hostname in this.hostnameCache)) { if (!(hostname in this.hostnameCache.hostnames)) {
this.hostnameCache[hostname] = { this.hostnameCache.hostnames[hostname] = {
applications: {}, applications: {},
meta: {} meta: {}
} }
} }
if (!(appName in this.hostnameCache[hostname].applications)) { if (
this.hostnameCache[hostname].applications[appName] = { !(appName in this.hostnameCache.hostnames[hostname].applications)
) {
this.hostnameCache.hostnames[hostname].applications[appName] = {
hits: 0 hits: 0
} }
} }
this.hostnameCache[hostname].applications[appName].hits += 1 this.hostnameCache.hostnames[hostname].applications[appName].hits += 1
if (apps[appName].version) { if (apps[appName].version) {
this.hostnameCache[hostname].applications[appName].version = this.hostnameCache.hostnames[hostname].applications[
app.version appName
].version = app.version
} }
} }
} }
}) })
if (hostname in this.hostnameCache) { if (hostname in this.hostnameCache.hostnames) {
this.hostnameCache[hostname].meta.language = language this.hostnameCache.hostnames[hostname].meta.language = language
} }
this.ping() this.ping()

Loading…
Cancel
Save