Compare commits
10 Commits
dd6d5b1100
...
c3d8116db2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3d8116db2 | ||
|
|
4db81f2251 | ||
|
|
78c0d08fa8 | ||
|
|
8a2473d62d | ||
|
|
55f3ea9f33 | ||
|
|
eb376638cd | ||
|
|
7ee8c2c9a0 | ||
|
|
ba64a18e18 | ||
|
|
eacfb5ebf0 | ||
|
|
116e3e5878 |
@@ -5,7 +5,7 @@ class Config {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.options = {}
|
this.options = {}
|
||||||
this.requires = ['env', 'gateway', 'quix24']
|
this.requires = []
|
||||||
this.init()
|
this.init()
|
||||||
this.validate()
|
this.validate()
|
||||||
this.finalize()
|
this.finalize()
|
||||||
|
|||||||
4
index.js
4
index.js
@@ -26,7 +26,7 @@ var app = express();
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(expressLogging(logger));
|
app.use(expressLogging(logger));
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
logger.info({ app: 'Headless browser' }, 'Startup');
|
logger.info('Browser service started');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ process.on('SIGTERM', exitHandler.bind(null, { cleanup: true }));
|
|||||||
*/
|
*/
|
||||||
app.post('/', async (req, res, next) => {
|
app.post('/', async (req, res, next) => {
|
||||||
browser.get(req.body).then(result => {
|
browser.get(req.body).then(result => {
|
||||||
typeof html == 'string' ? res.send(result) : res.json(result)
|
typeof result == 'string' ? res.send(result) : res.json(result)
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
logger.error({ message: e.message, info: e.info }, 'Browser error')
|
logger.error({ message: e.message, info: e.info }, 'Browser error')
|
||||||
res.status(500).send({ code: 500, message: e.message })
|
res.status(500).send({ code: 500, message: e.message })
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class NavigateService {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.config = {
|
this.config = {
|
||||||
browser: 'chrome',
|
browser: 'chrome',
|
||||||
hub: 'http://spiduler-chrome:4444/wd/hub',
|
hub: 'http://bro-chrome:4444/wd/hub',
|
||||||
capabilities: Capabilities.chrome(),
|
capabilities: Capabilities.chrome(),
|
||||||
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage']
|
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage']
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,14 @@ class NavigateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
page(params) {
|
page(params) {
|
||||||
return this._getDriver(params).then(driver => driver.findElement(By.css('body')).then(body => body.getAttribute('innerHTML')))
|
return this._getDriver(params)
|
||||||
|
.then(driver => {
|
||||||
|
return driver.get(params.uri).then(() => driver.findElement(By.css('body'))
|
||||||
|
.then(body => {
|
||||||
|
console.log(body.getTagName())
|
||||||
|
return body.getAttribute('innerHTML')
|
||||||
|
}))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
login(params) {
|
login(params) {
|
||||||
@@ -31,12 +38,10 @@ class NavigateService {
|
|||||||
driver.actions().move({ origin: username }).perform()
|
driver.actions().move({ origin: username }).perform()
|
||||||
await username.sendKeys(params.key.username)
|
await username.sendKeys(params.key.username)
|
||||||
await password.sendKeys(params.key.password)
|
await password.sendKeys(params.key.password)
|
||||||
// logger.info({ currentUrl: await driver.getCurrentUrl(), sessionId: await driver.getSession() }, 'aaaaa')
|
// return submit.click().then(() => driver.findElement(By.css('body')))
|
||||||
// return submit.click()
|
return submit.click()
|
||||||
// WebElement
|
|
||||||
return submit.click().then(() => driver.findElement(By.css('body')))
|
|
||||||
}).then(async body => {
|
}).then(async body => {
|
||||||
return body.getAttribute('innerHTML')
|
// return body.getAttribute('innerHTML')
|
||||||
return { currentUrl: await driver.getCurrentUrl(), sessionId: await driver.getSession() }
|
return { currentUrl: await driver.getCurrentUrl(), sessionId: await driver.getSession() }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -47,7 +52,7 @@ class NavigateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _getDriverExists(params) {
|
async _getDriverExists(params) {
|
||||||
return new WebDriver(new Session(params.sessionId, this.config.capabilities), new _http.Executor(Promise.resolve(this.config.hub)
|
return new WebDriver(params.sessionId, new _http.Executor(Promise.resolve(this.config.hub)
|
||||||
.then(url => new _http.HttpClient(url, null, null))))
|
.then(url => new _http.HttpClient(url, null, null))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class PoolingService {
|
|||||||
this.config = {
|
this.config = {
|
||||||
pool: { max: 10, min: 1, testOnBorrow: true },
|
pool: { max: 10, min: 1, testOnBorrow: true },
|
||||||
browser: 'chrome',
|
browser: 'chrome',
|
||||||
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage', '--proxy-server=spiduler-tor:8118']
|
browserArgs: ['--no-sandbox', '--headless', '--disable-dev-shm-usage', '--proxy-server=bro-tor:8118']
|
||||||
}
|
}
|
||||||
this.pool = this.createPool()
|
this.pool = this.createPool()
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ class PoolingService {
|
|||||||
let capabilities = Capabilities.chrome()
|
let capabilities = Capabilities.chrome()
|
||||||
opts.addArguments(this.config.browserArgs)
|
opts.addArguments(this.config.browserArgs)
|
||||||
return new Builder()
|
return new Builder()
|
||||||
.usingServer('http://spiduler-chrome:4444/wd/hub')
|
.usingServer('http://bro-chrome:4444/wd/hub')
|
||||||
.withCapabilities(capabilities)
|
.withCapabilities(capabilities)
|
||||||
.forBrowser(this.config.browser)
|
.forBrowser(this.config.browser)
|
||||||
.setChromeOptions(opts)
|
.setChromeOptions(opts)
|
||||||
|
|||||||
Reference in New Issue
Block a user