Merge pull request #14 from malitov/basic-http-authentication

Added basic HTTP authentication
This commit is contained in:
Vladimir Carrer 2018-12-06 12:40:29 +01:00 committed by GitHub
commit c82034ddcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -30,6 +30,7 @@ Parameters:
--h - height of the Web Page in px
--waitfor - wait time for the page load in milliseconds
--el - css selector document.querySelector
--auth - basic http authentication
<p>
@ -52,6 +53,8 @@ screenshoteer --url https://lobste.rs --w 500
screenshoteer --url https://news.ycombinator.com/item?id=18598672 --el ".fatitem"
screenshoteer --url https:/site.com --auth username;password
```
<p> List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js
</p>

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 timestamp = new Date().getTime()
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()).replace(/[/\\?%*:|"<>]/g, '-')
if (program.waitfor) await page.waitFor(Number(program.waitfor))