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

# Using with Puppeteer

> Set up Stat Proxies with Puppeteer for browser automation.

Puppeteer is a Node.js library for controlling headless Chrome. This guide shows how to route all of its traffic through Stat Proxies.

## Basic setup

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

(async () => {
  const browser = await puppeteer.launch({
    args: ['--proxy-server=http://192.168.1.1:3128']
  });

  const page = await browser.newPage();

  // Authenticate with the proxy
  await page.authenticate({
    username: 'myuser',
    password: 'mypass'
  });

  await page.goto('https://httpbin.org/ip');
  const content = await page.content();
  console.log(content);

  await browser.close();
})();
```

## Key steps

<Steps>
  <Step title="Pass the proxy server on launch">
    Use the `--proxy-server` flag in the `args` array when launching the browser. This sets the proxy at the browser level.
  </Step>

  <Step title="Authenticate on the page">
    Call `page.authenticate()` with your proxy username and password **before** navigating to any page.
  </Step>

  <Step title="Navigate normally">
    All requests from this browser instance will now route through your proxy.
  </Step>
</Steps>

## Rotating through multiple proxies

To use different proxies for different tasks, launch separate browser instances:

```javascript theme={null}
const proxies = [
  { host: '192.168.1.1:3128', user: 'user1', pass: 'pass1' },
  { host: '192.168.1.2:3128', user: 'user2', pass: 'pass2' },
];

for (const proxy of proxies) {
  const browser = await puppeteer.launch({
    args: [`--proxy-server=http://${proxy.host}`]
  });
  const page = await browser.newPage();
  await page.authenticate({ username: proxy.user, password: proxy.pass });

  // Your automation logic here
  await page.goto('https://example.com');

  await browser.close();
}
```

<Info>
  Each browser instance maintains its own proxy connection. Close the browser and launch a new one to switch proxies.
</Info>

## Headless vs headful

```javascript theme={null}
// Headless (default) — faster, no visible window
const browser = await puppeteer.launch({
  headless: true,
  args: ['--proxy-server=http://192.168.1.1:3128']
});

// Headful — useful for debugging
const browser = await puppeteer.launch({
  headless: false,
  args: ['--proxy-server=http://192.168.1.1:3128']
});
```

## Common issues

<AccordionGroup>
  <Accordion title="ERR_PROXY_CONNECTION_FAILED">
    Verify that your proxy host and port are correct. Ensure the proxy is active in your dashboard.
  </Accordion>

  <Accordion title="407 Proxy Authentication Required">
    Make sure you call `page.authenticate()` before navigating to any URL.
  </Accordion>

  <Accordion title="Page loads but shows real IP">
    The `--proxy-server` flag only accepts `host:port`. Authentication must be done separately via `page.authenticate()`.
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Making Your First Request" icon="code" href="/articles/first-request">
    Quick start code examples in multiple languages
  </Card>

  <Card title="Connection Errors" icon="wrench" href="/articles/connection-errors">
    Diagnose and fix common proxy issues
  </Card>
</CardGroup>
