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.
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
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.
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.
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 puppeteerPass 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.
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',
})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()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)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',
],
})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))){
"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.
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.
| Part | Format | Example | Rule |
|---|---|---|---|
| Country | -country-{cc} | -country-us | Required. Two-letter country code in lowercase. 64 countries are available. |
| City | -city-{city} | -city-new-york | Optional. City name in lowercase, spaces become hyphens. 172 cities are available. |
| Session | -session-{id} | -session-a1b2c3 | Optional. 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-30m | Used with a session. Residential 1 to 120 minutes, mobile 1 to 60, long-acting ISP up to 720 (12 hours). |
user-country-us-city-new-york-session-a1b2c3-ttl-30mFind country codes and city values on the proxy locations page.
The problems people run into most often with Puppeteer, with the message you are likely to see and how to solve it.
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.
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.
Use waitUntil: "domcontentloaded" instead of the network idle options, raise page.setDefaultNavigationTimeout(60000), and intercept requests to skip images and fonts.
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.
Add --force-webrtc-ip-handling-policy=disable_non_proxied_udp to the launch args and test again on a WebRTC leak page.
All products share one account, one prepaid balance and the same gateway, so you can switch type by changing the product, not the code.
From $0.23 per GB
Realistic home IPs for headless Chrome, sticky up to 120 minutes per context.
View residential proxiesFrom $0.13 per GB
Up to 12 hours on one fast ISP IP for long browser sessions with many concurrent pages.
View long-acting isp proxiesFrom $0.72 per 1,000 requests
Let our side run the browser and return rendered HTML when you would rather not maintain Chrome.
View web scraper apiBuilding a scraper? The web scraping use case covers request rates, retries and product choice in more depth.
Short answers to what people ask most about using a proxy with 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.
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.
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.
No. Proxies work with plain Puppeteer. Stealth plugins change browser fingerprints, which is a separate concern from the IP address.
Launch or context-level proxy with username and password, one IP per browser context.
Programming languagesNode.js proxy setupfetch with undici ProxyAgent, axios with https-proxy-agent, and SOCKS5 agents.
Scraping and automation librariesSelenium proxy setupAuthenticated proxies with selenium-wire, or an IP allowlist with --proxy-server.
Web browsersGoogle Chrome proxy setupSystem proxy on Windows and macOS, a separate proxied profile, and WebRTC protection.
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.