diff --git a/src/component/SeleniumBrowser.js b/src/component/SeleniumBrowser.js index 3b5dcaf..82bef9d 100644 --- a/src/component/SeleniumBrowser.js +++ b/src/component/SeleniumBrowser.js @@ -14,16 +14,17 @@ class SeleniumBrowser { } this.capabilities = Capabilities.chrome() this.sleep = m => new Promise(r => setTimeout(r, m)) - // this.pool = pool.createPool({ - // create: () => { - // return this.getDriver(); - // }, - // destroy: function (driver) { - // driver.quit(); - // } - // }, { - // max: 10, min: 1 - // }); + this.pool = pool.createPool({ + create: () => { + return this.getDriver(); + }, + destroy: function (driver) { + driver.close() + driver.quit() + } + }, { + max: 10, min: 1 + }); } getDriver() { @@ -41,15 +42,15 @@ class SeleniumBrowser { let uri = params.uri logger.info('URL %s', uri) if (uri.indexOf('://') > 3) { - // return this.pool.acquire() - return this.getDriver() + return this.pool.acquire() + // return this.getDriver() .then(async driver => { let html = await driver.get(uri) .then(() => driver.findElement(By.css('body'))) .then(body => body.getAttribute('innerHTML')) let htmlPromise = this.isCaptchaPage(html) ? this.resolveCaptcha(driver) : this.getHtml(driver, html, params) html = await htmlPromise - // this.pool.release(driver) + this.pool.destroy(driver) driver.quit() return html }) @@ -122,14 +123,9 @@ class SeleniumBrowser { } async close() { - // this.pool.drain().then(function () { - // this.pool.clear(); - // }) - } - - loggingChrome() { - let logPath = __dirname + '/storage/chrome-logs.txt' - logger.info('Chrome logging into %s', logPath) + this.pool.drain().then(function () { + this.pool.clear(); + }) } }