Added basic HTTP authentication

This commit is contained in:
Pavel Malitov 2018-12-06 12:32:21 +02:00
parent a0e425353a
commit 166f6658cb

View file

@ -15,6 +15,7 @@ program
.option('--h, [h]', 'height')
.option('--waitfor, [waitfor]', 'Wait time in milliseconds')
.option('--el, [el]', 'element css selector')
.option('--auth, [auth]', 'Basic HTTP authentication')
.parse(process.argv);
if (program.url) urlvalue = program.url
@ -40,6 +41,10 @@ console.log(fullPage);
const d = new Date()
if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)})
if (program.emulate) await page.emulate(devices[program.emulate]);
if (program.auth) {
const [username, password] = program.auth.split(':');
await page.authenticate({username:username, password:password});
}
await page.goto(urlvalue)
const title = await page.title()
const t = title.replace(/[/\\?%*:|"<>]/g, '-')