From b2b8a6a03527126d4e080f15560e2ac3913cbfd4 Mon Sep 17 00:00:00 2001 From: Sven Paulus Date: Sat, 15 Dec 2018 12:20:12 +0100 Subject: [PATCH 1/2] add new option --file to specify the name of the generate output image file --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7b03cea..b8f3d60 100755 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ program .option('--auth, [auth]', 'Basic HTTP authentication') .option('--no, [no]', 'Exclude') .option('--click, [click]', 'Click') + .option('--file, [file]', 'Output file') .parse(process.argv); if (!program.url) { @@ -69,11 +70,12 @@ console.log(program.fullPage); const title = (await page.title()).replace(/[/\\?%*:|"<>]/g, '-'); if (program.waitfor) await page.waitFor(Number(program.waitfor)); if (program.click) await page.click(program.click); + const file = program.file ? program.file : `${title} ${program.emulate} ${program.el} ${timestamp}.png`; if (program.el) { const el = await page.$(program.el); - await el.screenshot({path: `${title} ${program.emulate} ${program.el} ${timestamp}.png`}); + await el.screenshot({path: file}); } else { - await page.screenshot({path: `${title} ${program.emulate} ${timestamp}.png`, fullPage: program.fullPage}); + await page.screenshot({path: file, fullPage: program.fullPage}); } await page.emulateMedia('screen'); if (program.pdf) await page.pdf({path: `${title} ${program.emulate} ${timestamp}.pdf`}); From 84dbc48b7b2cb7793ccb9a7341ff6074f2f13f15 Mon Sep 17 00:00:00 2001 From: Sven Paulus Date: Sat, 15 Dec 2018 12:28:07 +0100 Subject: [PATCH 2/2] add --file to documentation --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e57b3b7..87a2385 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Parameters: --auth - basic http authentication --no - exclude "image", "stylesheet", "script", "font" --click - example: ".selector>a" excellent way to close popups or to click some buttons on the page. - +--file - output file name (optional, otherwise based on page title and timestamp)

Example:

@@ -70,6 +70,8 @@ screenshoteer --url https://www.nytimes.com --no "script" screenshoteer --url https://www.economist.com/ --click ".ribbon__close-button" screenshoteer --url file:///Users/../index.html + +screenshoteer --url https://www.slashdot.org --file /tmp/slashdot.png ```

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