error catch for NoSuchSession
This commit is contained in:
@@ -2,6 +2,7 @@ const logger = require("logops")
|
||||
, { By, until } = require('selenium-webdriver')
|
||||
, captcha = require('../component/CaptchaComp')
|
||||
, poolingService = require('../service/PoolingService')
|
||||
const { NoSuchSessionError } = require("selenium-webdriver/lib/error")
|
||||
|
||||
|
||||
class SeleniumBrowser {
|
||||
@@ -19,6 +20,12 @@ class SeleniumBrowser {
|
||||
let html = await driver.get(uri)
|
||||
.then(() => driver.findElement(By.css('body')))
|
||||
.then(body => body.getAttribute('innerHTML'))
|
||||
.catch(e => {
|
||||
if (e instanceof NoSuchSessionError) {
|
||||
this.pool.destroy(driver)
|
||||
throw new NoSuchSessionError
|
||||
}
|
||||
})
|
||||
let p = captcha.isCaptchaPage(html) ? captcha.resolveCaptcha(driver, this.pool) : this.getHtml(driver, html, params)
|
||||
html = await p
|
||||
if (this.pool.isBorrowedResource(driver)) this.pool.release(driver)
|
||||
|
||||
@@ -29,11 +29,10 @@ class PoolingService {
|
||||
}
|
||||
|
||||
destroy(driver) {
|
||||
logger.info('Quitting driver')
|
||||
this.pool.release(driver)
|
||||
return driver.quit().catch(err => {
|
||||
logger.info('Quitting driver')
|
||||
return this.pool.release(driver).then(() => driver.quit().catch(err => {
|
||||
logger.debug({ message: err.message }, 'Quitting error')
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
validate(driver) {
|
||||
|
||||
Reference in New Issue
Block a user