Unverified Commit 7c529842 authored by Isabella Sko艡epov谩's avatar Isabella Sko艡epov谩
Browse files

Add option to specify chromium opts and move timeout to index 馃敠

parent bf14f266
......@@ -32,6 +32,5 @@ async function bot(travian) {
.join('\n ')}`,
)
}
await timeout(1000)
}
module.exports.bot = bot
......@@ -8,6 +8,15 @@ async function readCredentials() {
return JSON.parse(await promisify(fs.readFile)('creds.json', 'utf-8'))
}
async function readChromiumOpts() {
try {
const data = await promisify(fs.readFile)('chromium-opts.json', 'uft-8')
return JSON.parse(data)
} catch (e) {
return undefined
}
}
function timeout(ms) {
return new Promise(res => setTimeout(res, ms))
}
......@@ -17,6 +26,7 @@ console.log('starting')
const args = await Travian.generateArgs({
headless: true,
server: 'https://ts5.travian.cz/',
opts: await readChromiumOpts(),
})
const impl = Travian.travianImpl
const travian = impl(...args)
......@@ -29,6 +39,7 @@ console.log('starting')
try {
// eslint-disable-next-line global-require
await require('./bot').bot(require('./travian').travianImpl(...args))
await timeout(1000)
} catch (e) {
console.error('Detected problem while running bot...')
console.error(e)
......
......@@ -143,7 +143,10 @@ const generateArgs = async _opts => {
..._opts,
}
if (!opts.server) throw new Error('You have to specify server')
const browser = await puppeteer.launch({ headless: opts.headless })
const browser = await puppeteer.launch({
headless: opts.headless,
opts: opts.opts,
})
try {
const page = await browser.newPage()
const state = {}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment