What is Puppeteer?

Puppeteer is a node library which provides us the feasibility to control the headless chrome or chromium. This is also an automation tool through which we can do whatever we want to do without opening the chrome.

Example of taking a screenshot using Puppeteer

In this example, we will see step by step how can we get the full page screenshot of a website without opening the chrome/chromium.

  1. First of all, we need to create a folder, named motorskills.
  2. Create an app.js file in that folder. You can create any filename.
  3. Open command prompt or terminal.
  4. Go to the project folder in terminal
  5. Type command npm init -y
    1. This will create the package.json file in the directory.
  6. Then run the command npm i puppeteer
    1. This will create the chrome and other dependency modules in the project.
  7. Then we will write our script to the app.js
// include the puppeteer library
const puppeteer = require('puppeteer');

// create and define the function named takeScreenshot 
const takeScreenshot = async()=>{

    // Launch puppeteer
    const browser = await puppeteer.launch({ args: [
        ] });

   // add new page in the chrome
    const page = await browser.newPage();
    // add the options
    const options = {
        path: 'images/website.png',
        fullPage: true,
        omitBackground: true

    // go to the url
    await page.goto('http://www.multidots.com/');

    //take screenshot
    await page.screenshot(options);

		    // close the tab
    await browser.close();

  1. Now run the app.js by running command node app.js

Reference Links:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s