The usefulness of headless browsing seems to come up frequently in my projects, although it is rarely a specified requirement upfront. Mostly this is because automating boring browser tasks tends to save both time and nerves, but also because there is an npm package that is both a pleasure to use, and simply just works very well.

After Chrome got its headless browsing mode out-of-the box, Google’s Puppeteer has quickly become the De Facto choice for all headless browsing projects. Its main advantage is that it removes the need to interact with Chrome DevTools directly, and it provides a high-level API compared to other headless browsers like PhantomJS and CasperJS.

You can literally be up and running with something useful in 15 minutes!

const puppeteer = require(‘puppeteer’);

puppeteer.launch().then(async browser => {

const page = await browser.newPage();

await page.setViewport({ width: 1280, height: 800 })

await page.goto(‘https://www.google.com’);

await page.screenshot({ path: ‘myscreenshot.png’, fullPage: true });

await browser.close();

});

Some obvious ways to utilize Puppeteer easily spring to mind, but there is a lot more to do than general web-scraping.