mirror of
https://github.com/vladocar/screenshoteer.git
synced 2024-11-16 17:08:33 +01:00
back merging against latest master
This commit is contained in:
commit
a8db83b311
3 changed files with 43 additions and 31 deletions
11
README.md
11
README.md
|
@ -15,6 +15,11 @@ npm i -g screenshoteer
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
screenshoteer --url https://www.example.com
|
screenshoteer --url https://www.example.com
|
||||||
|
|
||||||
|
or .html localy copy the url path from the browser
|
||||||
|
|
||||||
|
screenshoteer --url file:///Users/../index.html
|
||||||
|
screenshoteer --url file:///C:/Users/../Random-HTML-file.html
|
||||||
```
|
```
|
||||||
|
|
||||||
<p>And with the help of puppeteer(Headless Chrome) it will generate screenshot of the entire web page.</p>
|
<p>And with the help of puppeteer(Headless Chrome) it will generate screenshot of the entire web page.</p>
|
||||||
|
@ -29,7 +34,8 @@ Parameters:
|
||||||
--w - width of the Web Page in px
|
--w - width of the Web Page in px
|
||||||
--h - height of the Web Page in px
|
--h - height of the Web Page in px
|
||||||
--waitfor - wait time for the page load in milliseconds
|
--waitfor - wait time for the page load in milliseconds
|
||||||
--el - css selector document.querySelector
|
--el - css selector document.querySelector
|
||||||
|
--auth - basic http authentication
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
|
@ -52,6 +58,9 @@ screenshoteer --url https://lobste.rs --w 500
|
||||||
|
|
||||||
screenshoteer --url https://news.ycombinator.com/item?id=18598672 --el ".fatitem"
|
screenshoteer --url https://news.ycombinator.com/item?id=18598672 --el ".fatitem"
|
||||||
|
|
||||||
|
screenshoteer --url https://site.com --auth "username;password"
|
||||||
|
|
||||||
|
screenshoteer --url file:///Users/../index.html
|
||||||
```
|
```
|
||||||
<p> List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js
|
<p> List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js
|
||||||
</p>
|
</p>
|
||||||
|
|
61
index.js
61
index.js
|
@ -1,10 +1,8 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const puppeteer = require('puppeteer')
|
const puppeteer = require('puppeteer');
|
||||||
const devices = require('puppeteer/DeviceDescriptors')
|
const devices = require('puppeteer/DeviceDescriptors');
|
||||||
const program = require('commander')
|
const program = require('commander');
|
||||||
|
|
||||||
var urlvalue, emulate = "";
|
|
||||||
|
|
||||||
program
|
program
|
||||||
.option('--url, [url]', 'The url')
|
.option('--url, [url]', 'The url')
|
||||||
|
@ -15,15 +13,19 @@ program
|
||||||
.option('--h, [h]', 'height')
|
.option('--h, [h]', 'height')
|
||||||
.option('--waitfor, [waitfor]', 'Wait time in milliseconds')
|
.option('--waitfor, [waitfor]', 'Wait time in milliseconds')
|
||||||
.option('--el, [el]', 'element css selector')
|
.option('--el, [el]', 'element css selector')
|
||||||
|
.option('--auth, [auth]', 'Basic HTTP authentication')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
if (program.url) urlvalue = program.url
|
if (!program.url) {
|
||||||
else process.exit(console.log("Please add --url parameter. Something like this: $ screenshoteer --url http:www.example.com"));
|
console.log('Please add --url parameter.\n' +
|
||||||
|
'Something like this: $ screenshoteer --url http://www.example.com');
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
!program.fullpage ? fullPage = true : fullPage = JSON.parse(program.fullpage);
|
!program.fullpage ? program.fullPage = true : program.fullPage = JSON.parse(program.fullpage);
|
||||||
|
|
||||||
console.log(urlvalue);
|
console.log(program.url);
|
||||||
console.log(fullPage);
|
console.log(program.fullPage);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|
||||||
|
@ -35,35 +37,36 @@ console.log(fullPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function execute() {
|
async function execute() {
|
||||||
const browser = await puppeteer.launch()
|
const browser = await puppeteer.launch();
|
||||||
const page = await browser.newPage()
|
const page = await browser.newPage();
|
||||||
const d = new Date()
|
const timestamp = new Date().getTime();
|
||||||
if (program.w || program.h) {
|
if (program.w || program.h) {
|
||||||
const newWidth = !program.w?600:program.w
|
const newWidth = !program.w?600:program.w
|
||||||
const newHeight = !program.h?'0':program.h
|
const newHeight = !program.h?'0':program.h
|
||||||
if (program.h && !program.fullpage) fullPage = false;
|
if (program.h && !program.fullpage) fullPage = false;
|
||||||
await page.setViewport({width: Number(newWidth), height: Number(newHeight)})
|
await page.setViewport({width: Number(newWidth), height: Number(newHeight)})
|
||||||
}
|
}
|
||||||
if (program.emulate) await page.emulate(devices[program.emulate]);
|
if (program.emulate)
|
||||||
await page.goto(urlvalue)
|
await page.emulate(devices[program.emulate]);
|
||||||
const title = await page.title()
|
else
|
||||||
const t = title.replace(/[/\\?%*:|"<>]/g, '-')
|
program.emulate = '';
|
||||||
if (program.waitfor) await page.waitFor(Number(program.waitfor))
|
if (program.auth) {
|
||||||
|
const [username, password] = program.auth.split(';');
|
||||||
|
await page.authenticate({ username, password });
|
||||||
|
}
|
||||||
|
await page.goto(program.url);
|
||||||
|
const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-');
|
||||||
|
if (program.waitfor) await page.waitFor(Number(program.waitfor));
|
||||||
if (program.el) {
|
if (program.el) {
|
||||||
const el = await page.$(program.el);
|
const el = await page.$(program.el);
|
||||||
await el.screenshot({
|
await el.screenshot({path: `${title} ${program.emulate} ${program.el} ${timestamp}.png`});
|
||||||
path: `${t} ${program.emulate} ${program.el} ${d.getTime()}.png`
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
await page.screenshot({path: t + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage})
|
await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: program.fullPage});
|
||||||
}
|
}
|
||||||
await page.emulateMedia('screen')
|
await page.emulateMedia('screen');
|
||||||
if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' })
|
if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`});
|
||||||
console.log(t)
|
console.log(title);
|
||||||
await browser.close()
|
await browser.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "screenshoteer",
|
"name": "screenshoteer",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"description": "Make screenshots and device emulations form your terminal",
|
"description": "Make screenshots and device emulations form your terminal",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Reference in a new issue