Scraping and automation libraries

How to use a proxy with Puppeteer

Puppeteer is the Node.js library from the Chrome team for controlling Chrome and Chromium. Chrome takes the proxy address as a launch flag but has no flag for a username and password, so Puppeteer adds them with page.authenticate on each page.

This guide shows the launch flag, the authenticate call, separate proxies per browser context, and what to do for SOCKS5, which Chrome supports only without credentials.

Updated 23 November 2026

What you need
Hostgate.firstproxy.shop
HTTP / HTTPS port8000
SOCKS5 port9000
Usernameuser-country-us
PasswordYOUR_TOKEN

Use the HTTP port 8000 with page.authenticate. Chrome cannot authenticate to SOCKS5, so SOCKS5 needs an IP allowlist or a local bridge. Your username and token appear on the Proxy setup page of your dashboard after your first order.

Setup

How do I connect Puppeteer to a proxy?

Follow the steps in order. Replace YOUR_TOKEN with the token from your dashboard and change the country, city or session in the username to suit the job.

  1. Install Puppeteer

    The puppeteer package downloads a matching Chrome for Testing build on install. Use puppeteer-core if you want to point it at an installed browser.

    npm i puppeteer
  2. Launch Chrome with the proxy and authenticate

    Pass the gateway in --proxy-server without credentials, then call page.authenticate before the first goto. Chrome ignores credentials written inside the flag.

    import puppeteer from 'puppeteer'
    
    const browser = await puppeteer.launch({
      args: ['--proxy-server=http://gate.firstproxy.shop:8000'],
    })
    const page = await browser.newPage()
    await page.authenticate({
      username: 'user-country-us',
      password: 'YOUR_TOKEN',
    })
    await page.goto('https://ipinfo.io/json', { waitUntil: 'domcontentloaded' })
    console.log(await page.evaluate(() => document.body.innerText))
    await browser.close()

    page.authenticate applies to one page. Call it again for every new page or tab, including popups opened by the site.

  3. Use a sticky session and a city

    Keep the IP for a login or checkout flow by adding a session and ttl. Every page that authenticates with the same username shares the IP until the ttl ends.

    const session = Math.random().toString(36).slice(2, 10)
    await page.authenticate({
      username: 'user-country-us-city-miami-session-' + session + '-ttl-30m',
      password: 'YOUR_TOKEN',
    })
  4. Run several proxies in one browser

    Since Puppeteer 22, browser.createBrowserContext accepts a proxyServer option. Each context is isolated like an incognito window, so you can give each its own country or session.

    const browser = await puppeteer.launch()
    
    for (const country of ['us', 'de', 'jp']) {
      const ctx = await browser.createBrowserContext({
        proxyServer: 'http://gate.firstproxy.shop:8000',
      })
      const page = await ctx.newPage()
      await page.authenticate({
        username: 'user-country-' + country + '-session-' + country + '1-ttl-20m',
        password: 'YOUR_TOKEN',
      })
      await page.goto('https://ipinfo.io/json')
      console.log(country, await page.evaluate(() => document.body.innerText))
      await ctx.close()
    }
    await browser.close()
  5. SOCKS5 through a local bridge

    Chrome speaks SOCKS5 but cannot send a username and password to it. The proxy-chain package starts a local proxy without authentication that forwards to the gateway with your credentials, and Chrome connects to that.

    // npm i proxy-chain
    import puppeteer from 'puppeteer'
    import { anonymizeProxy, closeAnonymizedProxy } from 'proxy-chain'
    
    const local = await anonymizeProxy('socks5://user-country-de:YOUR_TOKEN@gate.firstproxy.shop:9000')
    const browser = await puppeteer.launch({ args: ['--proxy-server=' + local] })
    const page = await browser.newPage()
    await page.goto('https://ipinfo.io/json')
    await browser.close()
    await closeAnonymizedProxy(local, true)
  6. Stop WebRTC from bypassing the proxy

    Chrome can send WebRTC traffic over UDP outside the proxy, which exposes your real IP to pages that look for it. This flag limits WebRTC to proxied connections.

    const browser = await puppeteer.launch({
      args: [
        '--proxy-server=http://gate.firstproxy.shop:8000',
        '--force-webrtc-ip-handling-policy=disable_non_proxied_udp',
      ],
    })
Test

How do I check that the proxy works?

Read the body of ipinfo.io/json from the authenticated page. If you see your own IP, the page was opened before authenticate or in a context without the proxy.

A working proxy returns a response like the one shown, trimmed to the main fields. The IP belongs to the exit, the city and country follow your username, and the time zone is where that IP is located, here United States.

await page.goto('https://ipinfo.io/json')
console.log(JSON.parse(await page.evaluate(() => document.body.innerText)))
ipinfo.io/json response
{
  "ip": "203.0.113.24",
  "city": "New York",
  "country": "US",
  "timezone": "America/New_York"
}

203.0.113.24 is a documentation address. Your result shows a real exit IP.

Targeting

How do I set country, city and session in the username?

All targeting is written into the username, so Puppeteer needs no extra settings to change location. Parts are joined with hyphens in this order after your proxy user. The password is always your token.

Proxy username parts
PartFormatExampleRule
Country-country-{cc}-country-usRequired. Two-letter country code in lowercase. 64 countries are available.
City-city-{city}-city-new-yorkOptional. City name in lowercase, spaces become hyphens. 172 cities are available.
Session-session-{id}-session-a1b2c3Optional. Any letters and digits you choose. The same id keeps the same IP, a new id gets a new IP.
Session length-ttl-{minutes}m-ttl-30mUsed with a session. Residential 1 to 120 minutes, mobile 1 to 60, long-acting ISP up to 720 (12 hours).
Full usernameuser-country-us-city-new-york-session-a1b2c3-ttl-30m

Find country codes and city values on the proxy locations page.

Troubleshooting

Puppeteer proxy errors and fixes

The problems people run into most often with Puppeteer, with the message you are likely to see and how to solve it.

net::ERR_TUNNEL_CONNECTION_FAILED

Usually a 407 from the gateway. Make sure page.authenticate runs before goto on that exact page and that the token was copied without spaces.

net::ERR_NO_SUPPORTED_PROXIES or a login dialog

Credentials were placed inside --proxy-server. Remove them from the flag and use page.authenticate. In headful mode a login dialog means the page has no credentials set.

Navigation timeout of 30000 ms exceeded

Use waitUntil: "domcontentloaded" instead of the network idle options, raise page.setDefaultNavigationTimeout(60000), and intercept requests to skip images and fonts.

New tabs show my real IP or fail

Pages opened by window.open or target=_blank links are new pages. Listen for browser.on("targetcreated") and call authenticate on each new page, or keep the flow in one tab.

WebRTC leak test shows my home IP

Add --force-webrtc-ip-handling-policy=disable_non_proxied_udp to the launch args and test again on a WebRTC leak page.

FAQ

Puppeteer proxy questions

Short answers to what people ask most about using a proxy with Puppeteer.

How do I use a proxy with authentication in Puppeteer?

Launch Chrome with --proxy-server=http://gate.firstproxy.shop:8000, then call page.authenticate({ username, password }) on each page before page.goto. Chrome does not accept credentials in the flag itself.

Can I set a different proxy for each page in Puppeteer?

Pages in one context share the proxy server, but each page can authenticate with a different username, which means a different country or session. For a different proxy server, use createBrowserContext with proxyServer.

Does Puppeteer work with SOCKS5 proxies?

Chrome supports socks5:// in --proxy-server but cannot authenticate to it. Use an IP allowlist in the dashboard, or a local bridge such as proxy-chain that adds the credentials for you.

Do I need puppeteer-extra or a stealth plugin for proxies?

No. Proxies work with plain Puppeteer. Stealth plugins change browser fingerprints, which is a separate concern from the IP address.

Get your token and run the first Puppeteer request

Create an account, top up from $40 with crypto, and copy the gateway, username and token from the dashboard.