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
|
||||
*/
|
||||
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) {
|
||||
browser.reset()
|
||||
logger.error({ reason: e.message, url: req.url }, 'Browser session expired')
|
||||
|
||||
@@ -35,14 +35,28 @@ class SeleniumBrowser {
|
||||
return new Builder().forBrowser(this.config.browser).setChromeOptions(opts).build();
|
||||
}
|
||||
|
||||
async request(uri) {
|
||||
request(uri, waitElement) {
|
||||
if (this.isRecaptchaReseponseEmpty) {
|
||||
return ''
|
||||
} else {
|
||||
logger.info('URL %s', uri)
|
||||
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))
|
||||
// .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)
|
||||
return ''
|
||||
|
||||
@@ -8,8 +8,8 @@ class HeadlessService {
|
||||
|
||||
}
|
||||
|
||||
real(url) {
|
||||
return browser.request(url)
|
||||
get(uri, waitElement) {
|
||||
return browser.request(uri, waitElement)
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
Reference in New Issue
Block a user