Code and command line
Puppeteer proxy setup
Puppeteer drives Chrome through the DevTools protocol, and Chrome reads its proxy from a command-line switch. The switch only carries the host and port. The login and password are answered separately, page by page, with page.authenticate.
Because the proxy belongs to the whole browser process, the clean pattern is one browser per login. The steps below show that pattern, a helper that hides the details, and how to rotate or hold an address between runs.
What do you need before adding a proxy in Puppeteer?
Tick these off before the first step. Your login and password appear in your account once the first top-up of $40 or more has been credited.
| Requirement | Detail |
|---|---|
| Node.js 18 or newer | Current Puppeteer releases require a supported Node.js version. |
| puppeteer | npm i puppeteer downloads a matching Chrome build. |
| TopProxy login and password | For example tp7k2m9_country-us. |
| Async code | Every call returns a promise, so use an async function or top-level await in an ES module. |
Where do the proxy host, port and login go in Puppeteer?
Work through the steps in order. Swap YOUR_PASSWORD for your proxy password and tp7k2m9 for your account name.
Launch Chrome with the gateway
Add
--proxy-serverto the launch arguments with the scheme, host and port. Do not put the login in this value: Chrome ignores credentials inside the switch.import puppeteer from 'puppeteer'; const browser = await puppeteer.launch({ args: ['--proxy-server=http://proxy.topproxy.shop:8080'], });Answer the login challenge on each page
Call
page.authenticateright after creating a page and before the first navigation. Puppeteer then replies to the proxy challenge for every request that page makes.const page = await browser.newPage(); await page.authenticate({ username: 'tp7k2m9_country-us', password: process.env.TOPPROXY_PASSWORD ?? 'YOUR_PASSWORD', }); await page.goto('https://ipinfo.io/json', { waitUntil: 'domcontentloaded' }); console.log(await page.evaluate(() => document.body.innerText)); await browser.close();Tip.Popups and pages opened by links are new pages. Call authenticate on them too, or listen for the targetcreated event and do it there.
Wrap it in a helper
A small function that takes a country, city and session keeps the login format out of your scraping code and makes sure every browser closes.
import puppeteer from 'puppeteer'; export async function withProxy({ country = 'us', city, session, life = 30 }, job) { let username = 'tp7k2m9_country-' + country; if (city) username += '_city-' + city; if (session) username += '_session-' + session + '_life-' + life; const browser = await puppeteer.launch({ args: ['--proxy-server=http://proxy.topproxy.shop:8080'] }); try { const page = await browser.newPage(); await page.authenticate({ username, password: process.env.TOPPROXY_PASSWORD }); return await job(page); } finally { await browser.close(); } }Cut traffic with request interception
Metered products are billed per GB. Interception lets you drop images and media before they are fetched. Turn it on after
authenticateso the two features work together.await page.setRequestInterception(true); page.on('request', (req) => { if (['image', 'media', 'font'].includes(req.resourceType())) req.abort(); else req.continue(); });
How can you confirm the proxy is active in Puppeteer?
Load ipinfo.io in a page that went through the helper. The returned address should differ from your own, and the country should match the login.
const info = await withProxy({ country: 'us' }, async (page) => {
await page.goto('https://ipinfo.io/json');
return JSON.parse(await page.evaluate(() => document.body.innerText));
});
console.log(info.ip, info.country);The response shown here is shortened to the fields that matter. The region and time zone follow the exit, in this case Canada.
{
"ip": "198.51.100.47",
"city": "Toronto",
"region": "Ontario",
"country": "CA",
"timezone": "America/Toronto"
}198.51.100.47 is an address reserved for documentation. A live check prints a real exit.
How do you switch between rotating and held IPs in Puppeteer?
Each new browser on a rotating login starts on a new exit. Inside one browser, Chrome reuses connections, so pages may share an address for a while. To guarantee one address through a multi-step flow, pass a session name. To guarantee a new one, start a new browser or use a new session name.
await withProxy({ country: 'us' }, job);How the login is put together
Every setting lives in the login, joined with underscores. Nothing else in Puppeteer changes when you switch location or session.
| Part | Meaning | Rule |
|---|---|---|
| tp7k2m9 | Your account name | Always first. Yours is shown in your account and replaces tp7k2m9 in every example here. |
| _country-us | Exit country | Two-letter code in lowercase. 64 countries to choose from. |
| _city-new-york | Exit city, optional | Lowercase, spaces become hyphens. 172 cities in total. |
| _session-a1b2c3 | Session name, optional | Letters and digits you pick. Same name, same exit. New name, new exit. |
| _life-30 | Session life in minutes | Only with a session. Residential 1 to 120 minutes, mobile 1 to 60 minutes, long session ISP up to 12 hours (life 720). |
All parts togethertp7k2m9_country-us_city-new-york_session-a1b2c3_life-30
How do you choose an exit country or city in Puppeteer?
Pass the country code and, optionally, a city value. The helper turns it into tp7k2m9_country-es_city-barcelona.
await withProxy({ country: 'es' }, job);Codes and city values for all 64 countries are listed on the proxy locations pages.
How do you fix proxy connection errors in Puppeteer?
Find the line that matches what you see. Most problems come down to the login, the port or the network you are on.
| Symptom | Likely cause | Fix |
|---|---|---|
net::ERR_INVALID_AUTH_CREDENTIALS | The page navigated before authenticate finished, or the password is wrong. | Await page.authenticate before page.goto and check the password. |
net::ERR_PROXY_CONNECTION_FAILED | Chrome cannot reach the gateway: wrong host, wrong port or a blocked network. | Use http://proxy.topproxy.shop:8080 exactly and test the network with cURL. |
| Auth works on the first page but not in popups | New tabs are separate pages without credentials. | Authenticate new pages from the targetcreated event. |
Login appears inside --proxy-server and fails | Chrome does not read credentials from the switch. | Leave only scheme, host and port in the switch and use authenticate. |
Still stuck? Run the same login through the cURL check. If cURL connects, the issue is in the Puppeteer settings. If it does not, write to support with the error text.
What kind of proxy pairs well with Puppeteer?
All products sit behind the same gateway and share one prepaid balance, so moving from one to another means buying the other product and changing the login, nothing more.
- Rotating Residential ProxiesHousehold exits for crawling pages that need a real browser.$0.23 per GB
- Dedicated ISP ProxiesFast fixed addresses for headless jobs that log in and should not change IP.$0.33 per IP per month
- Unmetered Residential ProxiesDaily pricing keeps the cost flat when pages are heavy and runs are long.$11.90 per day
Calling pages from code at scale? The TopProxy API docs cover the Scraping API, which renders pages and retries on its own.
What else do Puppeteer users ask about proxies?
Can two pages in one Puppeteer browser use different countries?
Not reliably. The proxy server is set for the whole Chrome process, and the login is checked per connection, so pages sharing connections can end up on the same exit. Start one browser per location instead.
Does page.authenticate work in headless mode?
Yes. It answers the proxy challenge through the DevTools protocol, which is the same in headless and headed Chrome.
Why not use the SOCKS5 port with Puppeteer?
Chrome supports SOCKS5 only without a username and password. TopProxy logins need both, so the HTTP port 8080 is the one that works.
Is there a package that handles this for me?
Some community packages run a local proxy that adds the login for you. They are not needed with TopProxy, since --proxy-server and page.authenticate already cover every case.
How do I reduce GB usage with Puppeteer?
Block images, fonts and media with request interception, wait for domcontentloaded instead of networkidle, and reuse one page for several URLs on the same site.
Related setup guides
- PlaywrightProxy server, username and password at launch or per context, in Node.js and Python, with one location per context.
- Node.jsfetch with an undici ProxyAgent, axios with https-proxy-agent, and SOCKS5 through socks-proxy-agent.
- SeleniumChrome cannot take a proxy password from a flag. Two working routes: a small auth extension, or Selenium Wire.
- Google ChromeA separate Chrome profile launched with --proxy-server, the sign-in prompt, and when to use system settings instead.
Ready to connect Puppeteer?
Open an account, add $40 or more in crypto, and your login and password are waiting in the account area.