Skip to content

Instantly share code, notes, and snippets.

@embiem
Last active September 19, 2017 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save embiem/d0f32e495aa9c6e12597a9c5f8f204fe to your computer and use it in GitHub Desktop.
Save embiem/d0f32e495aa9c6e12597a9c5f8f204fe to your computer and use it in GitHub Desktop.
Create a full-height screenshot of a website using [puppeteer](https://github.com/GoogleChrome/puppeteer)
const puppeteer = require('puppeteer');
const width = 1200;
const url = process.argv.length > 2 ? process.argv[2] : 'https://ea.com';
const screenshotPath = process.argv.length > 3 ? process.argv[3] : 'screenshot.png';
console.log(`${url} --> ${screenshotPath}`);
(async () => {
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
// pre-set the width, otherwise it will be 800px by default.
await page.setViewport({ width, height: 600 });
// go to the url & get the height of entire site
await page.goto(url);
const height = await page.evaluate(() => {
return document.body.clientHeight
});
console.log(`Dimensions: ${width} x ${height}`);
// set the final dimensions
await page.setViewport({ width, height });
// take the screenshot and save it to the given path
await page.screenshot({path: screenshotPath});
console.log('screenshot saved to ', screenshotPath);
} catch (err) {
console.error(err);
} finally {
await browser.close();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment