Skip to content

Commit

Permalink
Add delay option in tools
Browse files Browse the repository at this point in the history
Allow user to specify a delay in milliseconds before taking the
screenshot. The delay is an optional argument and defaults to 0.

Signed-off-by: Vinicius Tinti <viniciustinti@gmail.com>
  • Loading branch information
tinti authored and alekzonder committed Jan 4, 2018
1 parent 64e96e7 commit 7755165
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ docker run --shm-size 1G --rm -v /tmp/screenshots:/screenshots \
<screenshot,full_screenshot,screenshot_series,full_screenshot_series> 'https://www.google.com' 1366x768
```
### screenshot tools syntax
`<tool> <url> <width>x<height> [<delay_in_ms>]`
* `delay_in_ms`: is optional (defaults to `0`)
* Waits for `delay_in_ms` milliseconds before taking the screenshot
### `screenshot`
```bash
Expand Down
12 changes: 12 additions & 0 deletions tools/fullScreenshot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node

function sleep(ms) {
return new Promise(resolve => {if (ms > 0) {setTimeout(resolve,ms)}})
}

process.on('uncaughtException', (error) => {
console.error(error);
process.exit(1);
Expand Down Expand Up @@ -36,6 +40,12 @@ if (typeof process.argv[3] === 'string') {
var [width, height] = process.argv[3].split('x').map(v => parseInt(v, 10));
}

var delay = 0;

if (typeof process.argv[4] === 'string') {
delay = parseInt(process.argv[4], 10);
}

var isMobile = false;

let filename = `full_screenshot_${width}_${height}.png`;
Expand All @@ -59,6 +69,8 @@ let filename = `full_screenshot_${width}_${height}.png`;

await page.goto(url, {waitUntil: 'networkidle2'});

await sleep(delay);

await page.screenshot({path: `/screenshots/${filename}`, fullPage: true});

browser.close();
Expand Down
12 changes: 12 additions & 0 deletions tools/fullScreenshotSeries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node

function sleep(ms) {
return new Promise(resolve => {if (ms > 0) {setTimeout(resolve,ms)}})
}

process.on('uncaughtException', (error) => {
console.error(error);
process.exit(1);
Expand Down Expand Up @@ -36,6 +40,12 @@ if (typeof process.argv[3] === 'string') {
var [width, height] = process.argv[3].split('x').map(v => parseInt(v, 10));
}

var delay = 0;

if (typeof process.argv[4] === 'string') {
delay = parseInt(process.argv[4], 10);
}

var isMobile = false;

let filename = `${dateStr}_full_screenshot_${width}_${height}.png`;
Expand All @@ -59,6 +69,8 @@ let filename = `${dateStr}_full_screenshot_${width}_${height}.png`;

await page.goto(url, {waitUntil: 'networkidle2'});

await sleep(delay);

await page.screenshot({path: `/screenshots/${filename}`, fullPage: true});

browser.close();
Expand Down
12 changes: 12 additions & 0 deletions tools/screenshot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node

function sleep(ms) {
return new Promise(resolve => {if (ms > 0) {setTimeout(resolve,ms)}})
}

process.on('uncaughtException', (error) => {
console.error(error);
process.exit(1);
Expand Down Expand Up @@ -36,6 +40,12 @@ if (typeof process.argv[3] === 'string') {
var [width, height] = process.argv[3].split('x').map(v => parseInt(v, 10));
}

var delay = 0;

if (typeof process.argv[4] === 'string') {
delay = parseInt(process.argv[4], 10);
}

var isMobile = false;

let filename = `screenshot_${width}_${height}.png`;
Expand All @@ -59,6 +69,8 @@ let filename = `screenshot_${width}_${height}.png`;

await page.goto(url, {waitUntil: 'networkidle2'});

await sleep(delay);

await page.screenshot({path: `/screenshots/${filename}`, fullPage: false});

browser.close();
Expand Down
12 changes: 12 additions & 0 deletions tools/screenshotSeries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node

function sleep(ms) {
return new Promise(resolve => {if (ms > 0) {setTimeout(resolve,ms)}})
}

process.on('uncaughtException', (error) => {
console.error(error);
process.exit(1);
Expand Down Expand Up @@ -36,6 +40,12 @@ if (typeof process.argv[3] === 'string') {
var [width, height] = process.argv[3].split('x').map(v => parseInt(v, 10));
}

var delay = 0;

if (typeof process.argv[4] === 'string') {
delay = parseInt(process.argv[4], 10);
}

var isMobile = false;

let filename = `${dateStr}_screenshot_${width}_${height}.png`;
Expand All @@ -59,6 +69,8 @@ let filename = `${dateStr}_screenshot_${width}_${height}.png`;

await page.goto(url, {waitUntil: 'networkidle2'});

await sleep(delay);

await page.screenshot({path: `/screenshots/${filename}`, fullPage: false});

browser.close();
Expand Down

0 comments on commit 7755165

Please sign in to comment.