> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nodemaven.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Puppeteer

> Set up Puppeteer with NodeMaven proxies using username and password or IP whitelisting.

Puppeteer is a Node.js library that provides a high-level API for controlling headless or full browsers like Google Chrome or Chromium. Puppeteer enables web automation, scraping, testing, and performance monitoring, so you can simulate user actions, extract data, and generate PDFs or screenshots.

You can find out more about Puppeteer on the [official Puppeteer page](https://pptr.dev/guides/what-is-puppeteer).

## Check whether Node.js is installed

Before anything, check whether Node.js is installed. Open a terminal (Command Prompt or shell) and run:

```bash theme={null}
node -v
```

If you get a version number, Node.js is already installed. The version number looks like this:

![Terminal showing the installed Node.js version number](https://downloads.intercomcdn.com/i/o/yvkc0rpk/1261772402/4e911749a4fdff8f98950402e69a/P1.png)

In that case, skip ahead to Step 2 and create a project directory.

If Node.js is not installed on your system, you get this error instead:

```text theme={null}
'node' is not recognized as an internal or external command
```

If that is your case, continue with the steps below.

## Step 1: Install Node.js

**1. Download Node.js**

Go to the [Node.js official website](https://nodejs.org/) and download the **LTS version** for your operating system.

![Node.js download page with the LTS version highlighted](https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262091895/b76446d0a9be50485468c46a4b07/p2.png)

**2. Install Node.js**

Run the installer you downloaded and follow the installation wizard.

![Node.js installation wizard](https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262100674/0ba754241356dc33c8e967cb50e1/p3.png)

## Step 2: Create a project directory

**1. Create the directory**

Open a terminal and create a directory for your project:

```bash theme={null}
mkdir puppeteer-nodemaven-proxy
```

**2. Go to the directory**

```bash theme={null}
cd puppeteer-nodemaven-proxy
```

**3. Initialize the project**

```bash theme={null}
npm init -y
```

> [!NOTE]
>
> This command creates a `package.json` file in your project directory.

![Terminal output from npm init showing the created package.json](https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262107801/6c51ef8d8f50ce431d2ef5ea38ce/p4.png)

## Step 3: Install Puppeteer

Install Puppeteer with:

```bash theme={null}
npm install puppeteer
```

![Terminal output from installing Puppeteer with npm](https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262115091/03b0a8129cde7504b7cd244b83d7/p5.png)

## Step 4: Set up Puppeteer with a NodeMaven proxy

Create a new file called `index.js` in your project directory using your preferred text editor, then add the code for your [authentication method](https://docs.nodemaven.com/residential-mobile/authentication.md).

```javascript Username and password theme={null}
const puppeteer = require('puppeteer');

(async () => {
    // Launch Puppeteer with a proxy
    const browser = await puppeteer.launch({
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--proxy-server=http://gate.nodemaven.com:8080'
        ],
    });

    const page = await browser.newPage();

    // Authenticate with the proxy
    await page.authenticate({
        username: 'REPLACE THIS WITH YOUR NODEMAVEN PROXY USERNAME',
        password: 'REPLACE THIS WITH YOUR NODEMAVEN PROXY PASSWORD'
    });

    try {
        // Navigate to a website
        await page.goto('https://nodemaven.com/');
        console.log('Page title:', await page.title());
    } catch (err) {
        console.error('Error navigating to the page:', err);
    } finally {
        // Close the browser
        await browser.close();
    }
})();
```

```javascript Whitelisted IP theme={null}
const puppeteer = require('puppeteer');

(async () => {
    // Launch Puppeteer in headless mode with a proxy
    const browser = await puppeteer.launch({
        headless: true, // Default is true, so no visible browser
        args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--proxy-server=http://gate.nodemaven.com:8405' // Replace with your IP whitelisting proxy
        ],
    });

    const page = await browser.newPage();

    try {
        // Navigate to the website
        await page.goto('https://nodemaven.com/');
        // Get the page title
        const title = await page.title();
        console.log('Page title:', title);
    } catch (err) {
        console.error('Error navigating to the page:', err);
    } finally {
        // Close the browser
        await browser.close();
    }
})();
```

For the whitelisted IP method, see [IP whitelist](https://docs.nodemaven.com/residential-mobile/ip-whitelist.md).

## Step 5: Run the script

Use the following command in the terminal:

```bash theme={null}
node index.js
```

If everything is set up correctly, the script logs the title of the page at `https://nodemaven.com` to the console.

![Terminal showing the page title logged by the Puppeteer script](https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262294140/44ec33816f94450d9f9c08e49d5d/p7.png)

You are now ready to personalize your script and start using Puppeteer with NodeMaven proxies.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.