figured out what is until
This commit is contained in:
2
index.js
2
index.js
@@ -63,7 +63,7 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
|
|||||||
* request handler
|
* request handler
|
||||||
*/
|
*/
|
||||||
app.post('/', async (req, res, next) => {
|
app.post('/', async (req, res, next) => {
|
||||||
const requestPage = () => browser.real(req.body.url).then(html => res.send(html)).catch(e => {
|
const requestPage = () => browser.get(req.body.uri, req.body.waitElement).then(html => res.send(html)).catch(e => {
|
||||||
if(e instanceof NoSuchSessionError) {
|
if(e instanceof NoSuchSessionError) {
|
||||||
browser.reset()
|
browser.reset()
|
||||||
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
|
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
|
||||||
|
|||||||
@@ -35,15 +35,29 @@ class SeleniumBrowser {
|
|||||||
return new Builder().forBrowser(this.config.browser).setChromeOptions(opts).build();
|
return new Builder().forBrowser(this.config.browser).setChromeOptions(opts).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
async request(uri) {
|
request(uri, waitElement) {
|
||||||
if (this.isRecaptchaReseponseEmpty) {
|
if (this.isRecaptchaReseponseEmpty) {
|
||||||
return ''
|
return ''
|
||||||
} else {
|
} else {
|
||||||
logger.info('URL %s', uri)
|
logger.info('URL %s', uri)
|
||||||
if (uri.indexOf('://') > 3) {
|
if (uri.indexOf('://') > 3) {
|
||||||
return this.driver.get(uri).then(d => this.driver.findElement(By.css('body')).getAttribute('innerHTML'))
|
return this.driver.get(uri)
|
||||||
|
// .then(() => {
|
||||||
|
// if (waitElement) {
|
||||||
|
// return this.driver.wait(until.elementIsVisible(this.driver.findElement(By.css(waitElement))), 5 * 1000)
|
||||||
|
// }
|
||||||
|
// return true
|
||||||
|
// })
|
||||||
|
.then(() => this.driver.findElement(By.css('body')))
|
||||||
|
.then(body => body.getAttribute('innerHTML'))
|
||||||
.then(html => this.getHtml(html))
|
.then(html => this.getHtml(html))
|
||||||
}else {
|
// .catch(error => {
|
||||||
|
// logger.error({ message: error.message }, 'No image element')
|
||||||
|
// return this.driver.findElement(By.css('body'))
|
||||||
|
// .then(body => body.getAttribute('innerHTML'))
|
||||||
|
// .then(html => this.getHtml(html))
|
||||||
|
// })
|
||||||
|
} else {
|
||||||
logger.info('URL %s is not valid', uri)
|
logger.info('URL %s is not valid', uri)
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ class HeadlessService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
real(url) {
|
get(uri, waitElement) {
|
||||||
return browser.request(url)
|
return browser.request(uri, waitElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
|
|||||||
Reference in New Issue
Block a user