From c1de3aec6068142c6c7fff7ace61c51bff8f7c3f Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Fri, 30 Nov 2018 13:52:00 +1100 Subject: [PATCH] NPM performance improvements --- src/drivers/npm/driver.js | 26 ++++++++++++++++++-------- src/drivers/npm/npm-shrinkwrap.json | 2 +- src/drivers/npm/package.json | 2 +- src/drivers/webextension/manifest.json | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/drivers/npm/driver.js b/src/drivers/npm/driver.js index aa9e6a78b..c934eb7f9 100644 --- a/src/drivers/npm/driver.js +++ b/src/drivers/npm/driver.js @@ -106,7 +106,8 @@ class Driver { this.wappalyzer.parseJsPatterns(); this.wappalyzer.driver.log = (message, source, type) => this.log(message, source, type); - this.wappalyzer.driver.displayApps = (detected, meta, context) => this.displayApps(detected, meta, context); + this.wappalyzer.driver + .displayApps = (detected, meta, context) => this.displayApps(detected, meta, context); process.on('uncaughtException', e => this.wappalyzer.log(`Uncaught exception: ${e.message}`, 'driver', 'error')); } @@ -282,17 +283,26 @@ class Driver { let html = ''; try { - html = browser.html() - .replace(new RegExp(`(.{${this.options.htmlMaxCols},}[^>]*>)<`, 'g'), (match, p1) => `${p1}\n<`) - .split('\n') - .slice(0, this.options.htmlMaxRows / 2) - .concat(html.slice(html.length - this.options.htmlMaxRows / 2)) - .map(line => line.substring(0, this.options.htmlMaxCols)) - .join('\n'); + html = browser.html(); } catch (error) { this.wappalyzer.log(error.message, 'browser', 'error'); } + const chunks = []; + const maxCols = this.options.htmlMaxCols; + const maxRows = this.options.htmlMaxRows; + const rows = html.length / maxCols; + + let i; + + 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'); + return html; } diff --git a/src/drivers/npm/npm-shrinkwrap.json b/src/drivers/npm/npm-shrinkwrap.json index ae0b7f7cc..f76d89198 100644 --- a/src/drivers/npm/npm-shrinkwrap.json +++ b/src/drivers/npm/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "wappalyzer", - "version": "5.5.5", + "version": "5.5.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/drivers/npm/package.json b/src/drivers/npm/package.json index 88df89fd2..0d4e60cec 100644 --- a/src/drivers/npm/package.json +++ b/src/drivers/npm/package.json @@ -2,7 +2,7 @@ "name": "wappalyzer", "description": "Uncovers the technologies used on websites", "homepage": "https://github.com/AliasIO/Wappalyzer", - "version": "5.5.3", + "version": "5.5.5", "author": "Elbert Alias", "license": "GPL-3.0", "repository": { diff --git a/src/drivers/webextension/manifest.json b/src/drivers/webextension/manifest.json index a17e6b097..41b1b0886 100644 --- a/src/drivers/webextension/manifest.json +++ b/src/drivers/webextension/manifest.json @@ -4,7 +4,7 @@ "author": "Elbert Alias", "homepage_url": "https://www.wappalyzer.com", "description": "Identify web technologies", - "version": "5.5.3", + "version": "5.5.5", "default_locale": "en", "manifest_version": 2, "icons": {