How To Take Screenshots with Puppeteer?

In this article, I’m going to explain the solution to hung node.js service problem while trying to run Puppeteer under IIS Server or as a windows service.

I built a small Node.js application to generate screenshots for HTML Pages using puppeteer.

When I tried to run this application directly from the command line, everything works perfect. But when I try to run it under IIS with iisnode or as a windows service, it hangs without returning any response or any error message.

To fix this issue, you only need to add one argument while launching puppeteer “–no-sandbox”. This may sound bizarre but some research pointed to a possible deadlock in Chromium as cause of the hung service and this switch somehow prevents this from happening. click here to learn more about Chromium command line switches.

puppeteer.launch({ args: [“–no-sandbox”]})

My environment:

  • Puppeteer version: 1.14.0
  • Platform / OS version: Windows 10
  • Node.js version: v8.9.4

Here is a code example:

const puppeteer = require(‘puppeteer’);

(async () => {
const browser = await puppeteer.launch({ args: [“–no-sandbox”]});
const page = await browser.newPage();
await page.goto(‘’);
await page.evaluateHandle(‘document.fonts.ready’);
await page.screenshot({path: ‘kuikaBoost.png’});
await browser.close();

I added page.evaluateHandle to wait for the web fonts to be loaded before taking the screenshot.

Enjoy running Puppeteer as a windows service with great screenshots! 🙂

This post originally published on Medium by Rama Mousali

Leave a Comment

Your email address will not be published. Required fields are marked *