Puppeteer Guide · 2 min read

Puppeteer proxy setup with authentication

Puppeteer takes the proxy server as a launch flag, but the username and password go somewhere else entirely — through page.authenticate(). Here is the correct pattern for authenticated s4m proxies, with full Node code.

Why the flag alone is not enough

Chromium — the browser Puppeteer drives — accepts a proxy through the --proxy-server command-line flag. The catch is that Chromium's flag format does not accept credentials inline: you cannot write --proxy-server=http://USER:PASS@host:3128 and expect it to work. When the proxy challenges for authentication, Chromium raises a native auth prompt that a headless browser cannot answer on its own.

Puppeteer's answer is page.authenticate({ username, password }). You pass the bare host and port to the launch flag, then hand the credentials to the page, and Puppeteer responds to the proxy's 407 Proxy Authentication Required challenge for you. With s4m that means launching with --proxy-server=http://proxy.s4m.online:3128 and authenticating with your USER:PASS. The HTTP endpoint (port 3128) is the right one here — Chromium's proxy flag speaks HTTP and SOCKS, but authenticated SOCKS5 with a browser is fiddly, so HTTP is the reliable choice. See the proxy overview and the proxy authentication guide.

Authenticated Puppeteer launch

The proxy host goes in the launch flag; USER:PASS goes through page.authenticate(). Replace credentials before running.

javascript
// npm install puppeteer
const puppeteer = require("puppeteer");

const HOST = "proxy.s4m.online";
const PORT = 3128;             // HTTP proxy endpoint
const USER = "USER";
const PASS = "PASS";

(async () => {
  const browser = await puppeteer.launch({
    headless: "new",
    args: [
      `--proxy-server=http://${HOST}:${PORT}`,
      // credentials are NOT allowed here — see page.authenticate below
      "--no-sandbox",
    ],
  });

  const page = await browser.newPage();

  // This answers the proxy's 407 challenge:
  await page.authenticate({ username: USER, password: PASS });

  await page.goto("https://api.ipify.org?format=json", {
    waitUntil: "networkidle0",
    timeout: 30000,
  });
  console.log("Exit IP:", await page.evaluate(() => document.body.innerText));

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

Things that trip people up

The mistakes that turn into a blank page or a 407.

Credentials go to the page

Never put USER:PASS in --proxy-server; Chromium ignores it. Always call page.authenticate() before your first navigation, once per page.

Use the HTTP endpoint

Authenticated SOCKS5 in a browser is unreliable. Point --proxy-server at http://proxy.s4m.online:3128 and let page.authenticate handle the login.

Authenticate before goto

Call page.authenticate() before page.goto(), otherwise the first request hits the proxy without credentials and returns 407.

One context, one identity

Each browser context carries its own auth. For multiple identities, launch separate contexts rather than re-authenticating a shared page.

Blocks, fingerprints and honesty

A proxy hides your IP; it does not hide that you are automating a browser. Modern anti-bot systems also look at navigator properties, timing, and TLS fingerprints. If a target flags headless Chromium, a proxy alone will not fix it — you may need realistic viewport and User-Agent settings and human-like pacing, and even then some sites are simply off-limits to automation.

Be honest about the proxy type, too: s4m proxies are datacenter, which is perfect for testing, monitoring and moderately defended sites, but heavily defended targets may block datacenter ranges. When you need one stable exit for a login or an allowlist, add a dedicated personal IP. Prefer Playwright? The pattern is nearly identical — see the Playwright proxy guide. Verify your exit with the tools and prototype against the free proxy list.

FAQ

Questions, answered

Why does my Puppeteer request return 407?

Because the proxy is challenging for authentication and you have not answered it. Call page.authenticate({ username, password }) before your first page.goto() — credentials in the --proxy-server flag are ignored by Chromium.

Can Puppeteer use a SOCKS5 proxy?

Chromium's proxy flag can point at SOCKS, but authenticated SOCKS5 in a browser is unreliable. Use the HTTP endpoint on port 3128 with page.authenticate() for a dependable setup.

Do I need to authenticate every page?

Yes — call page.authenticate() once per page (or per browser context) before navigating. Each context carries its own credentials.

Will a proxy stop me being detected as a bot?

No. A proxy only changes your IP. Anti-bot systems also inspect browser fingerprints and behaviour, so a proxy is necessary but not sufficient against aggressive detection.

Run headless Chrome behind a proxy

Authenticated datacenter proxies on proxy.s4m.online, ready for Puppeteer's page.authenticate(). Metered pay-as-you-go, with an optional dedicated IP for stable logins.

People found this page by searching for

Real search phrases this page answers — the linked ones open the page that covers them in depth.