> ## 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:

<Frame>
  <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1261772402/4e911749a4fdff8f98950402e69a/P1.png" alt="Terminal showing the installed Node.js version number" />
</Frame>

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

<Steps>
  <Step title="Download Node.js">
    Go to the [Node.js official website](https://nodejs.org/) and download the **LTS version** for your operating system.

    <Frame>
      <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262091895/b76446d0a9be50485468c46a4b07/p2.png" alt="Node.js download page with the LTS version highlighted" />
    </Frame>
  </Step>

  <Step title="Install Node.js">
    Run the installer you downloaded and follow the installation wizard.

    <Frame>
      <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262100674/0ba754241356dc33c8e967cb50e1/p3.png" alt="Node.js installation wizard" />
    </Frame>
  </Step>
</Steps>

## Step 2: Create a project directory

<Steps>
  <Step title="Create the directory">
    Open a terminal and create a directory for your project:

    ```bash theme={null}
    mkdir puppeteer-nodemaven-proxy
    ```
  </Step>

  <Step title="Go to the directory">
    ```bash theme={null}
    cd puppeteer-nodemaven-proxy
    ```
  </Step>

  <Step title="Initialize the project">
    ```bash theme={null}
    npm init -y
    ```

    <Note>
      This command creates a `package.json` file in your project directory.
    </Note>

    <Frame>
      <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262107801/6c51ef8d8f50ce431d2ef5ea38ce/p4.png" alt="Terminal output from npm init showing the created package.json" />
    </Frame>
  </Step>
</Steps>

## Step 3: Install Puppeteer

Install Puppeteer with:

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

<Frame>
  <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262115091/03b0a8129cde7504b7cd244b83d7/p5.png" alt="Terminal output from installing Puppeteer with npm" />
</Frame>

## 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](/residential-mobile/authentication).

<CodeGroup>
  ```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();
      }
  })();
  ```
</CodeGroup>

For the whitelisted IP method, see [IP whitelist](/residential-mobile/ip-whitelist).

## 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.

<Frame>
  <img src="https://downloads.intercomcdn.com/i/o/yvkc0rpk/1262294140/44ec33816f94450d9f9c08e49d5d/p7.png" alt="Terminal showing the page title logged by the Puppeteer script" />
</Frame>

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.