headless-screenshot is a high-level on top of headless embedded chromium browser (puppeteer). It provides safe & easy to use interface for taking screenshot of websites.
Built with ❤️
headless-screenshot depends on puppeteer, ensure its installed globally or locally before using this library.
npm i puppeteer headless-screenshot
Usage:
const HeadShot = require('headless-screenshot');
const Promise = require('bluebird');
const writeFile = Promise.promisify(require('fs').writeFile);
let hc = new HeadShot() // browser instance
hc.setup() // launches embedded chromium instance
.then(() =>
hc.getScreenshot('https://example.com')
.then( res => {
console.log(`resolvedUrl: ${res.resolvedUrl}, originalUrl: ${res.url}, isReachable: ${res.isReachable}`);
writeFile('./example.png',res.data).then(() => console.log('file is written'));
}).finally(() => hc.destroy())
For reference look at test cases.