|
|
@ -9,17 +9,6 @@ const Content = {
|
|
|
|
async init() {
|
|
|
|
async init() {
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
|
|
|
|
|
|
|
|
|
|
// Enable messaging to and from driver.js
|
|
|
|
|
|
|
|
Content.port = chrome.runtime.connect({ name: 'content.js' })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Content.port.onMessage.addListener(({ func, args }) => {
|
|
|
|
|
|
|
|
const onFunc = `on${func.charAt(0).toUpperCase() + func.slice(1)}`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Content[onFunc]) {
|
|
|
|
|
|
|
|
Content[onFunc](args)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// HTML
|
|
|
|
// HTML
|
|
|
|
let html = new XMLSerializer().serializeToString(document)
|
|
|
|
let html = new XMLSerializer().serializeToString(document)
|
|
|
@ -43,13 +32,15 @@ const Content = {
|
|
|
|
document.documentElement.getAttribute('lang') ||
|
|
|
|
document.documentElement.getAttribute('lang') ||
|
|
|
|
document.documentElement.getAttribute('xml:lang') ||
|
|
|
|
document.documentElement.getAttribute('xml:lang') ||
|
|
|
|
(await new Promise((resolve) =>
|
|
|
|
(await new Promise((resolve) =>
|
|
|
|
chrome.i18n.detectLanguage(html, ({ languages }) =>
|
|
|
|
chrome.i18n.detectLanguage
|
|
|
|
resolve(
|
|
|
|
? chrome.i18n.detectLanguage(html, ({ languages }) =>
|
|
|
|
languages
|
|
|
|
resolve(
|
|
|
|
.filter(({ percentage }) => percentage >= 75)
|
|
|
|
languages
|
|
|
|
.map(({ language: lang }) => lang)[0]
|
|
|
|
.filter(({ percentage }) => percentage >= 75)
|
|
|
|
)
|
|
|
|
.map(({ language: lang }) => lang)[0]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
: resolve()
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
// Script tags
|
|
|
|
// Script tags
|
|
|
@ -72,22 +63,41 @@ const Content = {
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
Content.port.postMessage({
|
|
|
|
Content.driver('onContentLoad', [
|
|
|
|
func: 'onContentLoad',
|
|
|
|
location.href,
|
|
|
|
args: [location.href, { html, scripts, meta }, language]
|
|
|
|
{ html, scripts, meta },
|
|
|
|
})
|
|
|
|
language
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
Content.port.postMessage({ func: 'getTechnologies' })
|
|
|
|
Content.onGetTechnologies(await Content.driver('getTechnologies'))
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
Content.port.postMessage({ func: 'error', args: [error, 'content.js'] })
|
|
|
|
Content.driver('error', error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
driver(func, args, callback) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
source: 'content.js',
|
|
|
|
|
|
|
|
func,
|
|
|
|
|
|
|
|
args: args ? (Array.isArray(args) ? args : [args]) : []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
(response) => {
|
|
|
|
|
|
|
|
chrome.runtime.lastError
|
|
|
|
|
|
|
|
? reject(new Error(chrome.runtime.lastError.message))
|
|
|
|
|
|
|
|
: resolve(response)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Callback for getTechnologies
|
|
|
|
* Callback for getTechnologies
|
|
|
|
* @param {Object} technologies
|
|
|
|
* @param {Array} technologies
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onGetTechnologies(technologies) {
|
|
|
|
onGetTechnologies(technologies = []) {
|
|
|
|
|
|
|
|
console.log({ technologies })
|
|
|
|
// Inject a script tag into the page to access methods of the window object
|
|
|
|
// Inject a script tag into the page to access methods of the window object
|
|
|
|
const script = document.createElement('script')
|
|
|
|
const script = document.createElement('script')
|
|
|
|
|
|
|
|
|
|
|
@ -99,7 +109,8 @@ const Content = {
|
|
|
|
|
|
|
|
|
|
|
|
window.removeEventListener('message', onMessage)
|
|
|
|
window.removeEventListener('message', onMessage)
|
|
|
|
|
|
|
|
|
|
|
|
Content.port.postMessage({
|
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
|
|
|
|
source: 'content.js',
|
|
|
|
func: 'analyzeJs',
|
|
|
|
func: 'analyzeJs',
|
|
|
|
args: [location.href, data.wappalyzer.js]
|
|
|
|
args: [location.href, data.wappalyzer.js]
|
|
|
|
})
|
|
|
|
})
|
|
|
|