From bb9afa157a67ba17327ecbbb62634887d46728d3 Mon Sep 17 00:00:00 2001 From: Andrea D Date: Thu, 6 Dec 2018 10:14:59 +0100 Subject: [PATCH 01/13] Clean up path string and title --- index.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 40f5b02..6b87785 100755 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ program if (program.url) urlvalue = program.url else process.exit(console.log("Please add --url parameter. Something like this: $ screenshoteer --url http:www.example.com")); -!program.fullpage ? fullPage = true : fullPage = JSON.parse(program.fullpage); +!program.fullpage ? fullPage = true : fullPage = JSON.parse(program.fullpage); console.log(urlvalue); console.log(fullPage); @@ -37,28 +37,22 @@ console.log(fullPage); async function execute() { const browser = await puppeteer.launch() const page = await browser.newPage() - const d = new Date() + 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]); await page.goto(urlvalue) - const title = await page.title() - const t = title.replace(/[/\\?%*:|"<>]/g, '-') + const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-') if (program.waitfor) await page.waitFor(Number(program.waitfor)) if (program.el) { const el = await page.$(program.el); - await el.screenshot({ - path: `${t} ${program.emulate} ${program.el} ${d.getTime()}.png` - }); + await el.screenshot({path: `${title} ${program.emulate} ${program.el} ${timestamp}.png`}); } else { - await page.screenshot({path: t + " " + program.emulate + " " + d.getTime() + '.png', fullPage: fullPage}) + await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: fullPage}) } await page.emulateMedia('screen') - if (program.pdf) await page.pdf({ path: t + " " + program.emulate + " " + d.getTime() + '.pdf' }) - console.log(t) + if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`}) + console.log(title) await browser.close() } })() - - - From 166f6658cbe5e42c131aeee70e014c36f3a1de6d Mon Sep 17 00:00:00 2001 From: Pavel Malitov Date: Thu, 6 Dec 2018 12:32:21 +0200 Subject: [PATCH 02/13] Added basic HTTP authentication --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index 40f5b02..a786e87 100755 --- a/index.js +++ b/index.js @@ -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, '-') From 1996ff0dff9bba2ddc78ea151f55191ebad686be Mon Sep 17 00:00:00 2001 From: Pavel Malitov Date: Thu, 6 Dec 2018 12:49:21 +0200 Subject: [PATCH 03/13] Updated readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 760d500..d0fb030 100644 --- a/README.md +++ b/README.md @@ -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

@@ -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 + ```

List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js

From 782268e4e3405e4fa5bd1c8ff3f6e96251ab6129 Mon Sep 17 00:00:00 2001 From: Vladimir Carrer Date: Thu, 6 Dec 2018 12:39:27 +0100 Subject: [PATCH 04/13] change : to ; --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a786e87..e1e6f90 100755 --- a/index.js +++ b/index.js @@ -42,7 +42,7 @@ console.log(fullPage); 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(':'); + const [username, password] = program.auth.split(';'); await page.authenticate({username:username, password:password}); } await page.goto(urlvalue) From a37815f4f19cc5d17eba43702440d8d1798410c2 Mon Sep 17 00:00:00 2001 From: Vladimir Carrer Date: Thu, 6 Dec 2018 12:40:04 +0100 Subject: [PATCH 05/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d0fb030..3ede8d6 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ 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 +screenshoteer --url https:/site.com --auth username;password ```

List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js From df9dc6cb28ddd0e076aa10c09caf9d529d66793c Mon Sep 17 00:00:00 2001 From: Vladimir Carrer Date: Thu, 6 Dec 2018 12:41:07 +0100 Subject: [PATCH 06/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ede8d6..52892d7 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Parameters: --w - width of the Web Page in px --h - height of the Web Page in px --waitfor - wait time for the page load in milliseconds ---el - css selector document.querySelector +--el - css selector document.querySelector --auth - basic http authentication

From 920236282bad079f2960de6535008210c757fb7b Mon Sep 17 00:00:00 2001 From: Vladimir Carrer Date: Thu, 6 Dec 2018 12:47:13 +0100 Subject: [PATCH 07/13] Version 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 68e484f..af3d2ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "screenshoteer", - "version": "1.0.3", + "version": "1.0.4", "description": "Make screenshots and device emulations form your terminal", "main": "index.js", "scripts": { From ce7ebb00e0e1a3bd74560f77e9e5ca392168399f Mon Sep 17 00:00:00 2001 From: ZYSzys <17367077526@163.com> Date: Thu, 6 Dec 2018 22:14:16 +0800 Subject: [PATCH 08/13] fix path when no emulate --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 96b0336..90e2ea3 100755 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const puppeteer = require('puppeteer') const devices = require('puppeteer/DeviceDescriptors') const program = require('commander') -var urlvalue, emulate = ""; +let urlvalue; program .option('--url, [url]', 'The url') @@ -40,7 +40,10 @@ console.log(fullPage); const page = await browser.newPage() 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.emulate) + await page.emulate(devices[program.emulate]); + else + program.emulate = ''; if (program.auth) { const [username, password] = program.auth.split(';'); await page.authenticate({username:username, password:password}); From b6b664d993cbca74e716f996b191a51c835323c8 Mon Sep 17 00:00:00 2001 From: ZYSzys <17367077526@163.com> Date: Thu, 6 Dec 2018 22:41:47 +0800 Subject: [PATCH 09/13] clear up the codebase --- index.js | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 90e2ea3..d822bbb 100755 --- a/index.js +++ b/index.js @@ -1,10 +1,8 @@ #!/usr/bin/env node -const puppeteer = require('puppeteer') -const devices = require('puppeteer/DeviceDescriptors') -const program = require('commander') - -let urlvalue; +const puppeteer = require('puppeteer'); +const devices = require('puppeteer/DeviceDescriptors'); +const program = require('commander'); program .option('--url, [url]', 'The url') @@ -18,13 +16,16 @@ program .option('--auth, [auth]', 'Basic HTTP authentication') .parse(process.argv); -if (program.url) urlvalue = program.url -else process.exit(console.log("Please add --url parameter. Something like this: $ screenshoteer --url http:www.example.com")); +if (!program.url) { + 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(fullPage); +console.log(program.url); +console.log(program.fullPage); (async () => { @@ -36,31 +37,31 @@ console.log(fullPage); } async function execute() { - const browser = await puppeteer.launch() - const page = await browser.newPage() - const timestamp = new Date().getTime() - if (program.w && program.h) await page.setViewport({width: Number(program.w), height: Number(program.h)}) + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + 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]); else program.emulate = ''; if (program.auth) { const [username, password] = program.auth.split(';'); - await page.authenticate({username:username, password:password}); + await page.authenticate({ username, password }); } - await page.goto(urlvalue) - const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-') - if (program.waitfor) await page.waitFor(Number(program.waitfor)) + await page.goto(program.url); + const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-'); + if (program.waitfor) await page.waitFor(Number(program.waitfor)); if (program.el) { const el = await page.$(program.el); await el.screenshot({path: `${title} ${program.emulate} ${program.el} ${timestamp}.png`}); } else { - await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: fullPage}) + await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: program.fullPage}); } - await page.emulateMedia('screen') - if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`}) - console.log(title) - await browser.close() + await page.emulateMedia('screen'); + if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`}); + console.log(title); + await browser.close(); } })() From f2b7a944ea6b0850ebe543d4fdbeb15f7367a43c Mon Sep 17 00:00:00 2001 From: Lane Goldberg Date: Thu, 6 Dec 2018 11:45:38 -0500 Subject: [PATCH 10/13] fix typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d822bbb..ba8b31f 100755 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ program if (!program.url) { console.log('Please add --url parameter.\n' + - 'Something like this: $ screenshoteer --url http:www.example.com'); + 'Something like this: $ screenshoteer --url http://www.example.com'); process.exit(); } From 0698430a68c2b6cb2e9aeb056723402a396b282d Mon Sep 17 00:00:00 2001 From: Kai Neuwerth Date: Fri, 7 Dec 2018 13:51:23 +0100 Subject: [PATCH 11/13] Fix missing slash in url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52892d7..e10a987 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ 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 +screenshoteer --url https://site.com --auth username;password ```

List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js From 64d2194e7d08a2920b5aeec83af819dfc9ed201a Mon Sep 17 00:00:00 2001 From: Kai Neuwerth Date: Fri, 7 Dec 2018 15:57:50 +0100 Subject: [PATCH 12/13] Add quotes around auth parameter --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e10a987..60e1e45 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ 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 +screenshoteer --url https://site.com --auth "username;password" ```

List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js From eafb818e1304df28970c809ec990da443ff78007 Mon Sep 17 00:00:00 2001 From: Vladimir Carrer Date: Fri, 7 Dec 2018 16:44:49 +0100 Subject: [PATCH 13/13] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 60e1e45..6b771e2 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ npm i -g screenshoteer ```shell 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 ```

And with the help of puppeteer(Headless Chrome) it will generate screenshot of the entire web page.

@@ -55,6 +60,7 @@ screenshoteer --url https://news.ycombinator.com/item?id=18598672 --el ".fatite screenshoteer --url https://site.com --auth "username;password" +screenshoteer --url file:///Users/../index.html ```

List of of supported mobile devices: https://github.com/GoogleChrome/puppeteer/blob/master/DeviceDescriptors.js