How to Use a Proxy with Puppeteer in Node.js
A step-by-step guide to routing Puppeteer through a proxy in Node.js, including authentication, excluding hosts, verifying the IP and avoiding common mistakes.
9 min readUpdated Nov 13, 2026By XPASS Editorial Team

Puppeteer controls a Chromium-based browser from Node.js, and it is widely used for page rendering checks, screenshots and front-end testing. When a team needs to see how a public page appears to visitors connecting from another place, routing Puppeteer through a proxy is a straightforward way to start. The configuration is short, but it has a few quirks: credentials are handled separately from the address, per-context proxies depend on the version, and SOCKS has authentication limits. This guide explains each of them in order and ends with checks and a troubleshooting table.
Everything here assumes lawful use: QA, regional page checks, monitoring your own sites. Follow the terms and robots rules of every site you test, respect published rate limits, and comply with local law. A proxy changes the route your traffic takes, not what you are allowed to do.
What you need
You need Node.js, Puppeteer installed in your project, and the connection details from your proxy provider: a host or IP, a port, the protocol (HTTP or SOCKS) and usually a username and password. Find these on the plan page and in your account dashboard, and consult the provider's documentation for anything unclear.
Plan where the secrets will live before writing code. Environment variables are a reasonable starting point, and the article on storing proxy credentials securely goes into secret managers and rotation. Throughout this guide we assume PROXY_HOST, PROXY_PORT, PROXY_USER and PROXY_PASS are set in the environment.
If you already know the Python side, the concepts will feel familiar: using a proxy with Python Requests covers a plain HTTP client, while Puppeteer drives a full browser, which means more traffic, more hosts contacted per page, and more things that can go wrong.

Step 1: launch the browser through a proxy
Chromium reads its proxy from a command-line switch, which Puppeteer lets you pass through the args option.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch({
args: [`--proxy-server=http://${process.env.PROXY_HOST}:${process.env.PROXY_PORT}`],
});
const page = await browser.newPage();
await page.goto('https://example.com/', { waitUntil: 'domcontentloaded', timeout: 30000 });
console.log(await page.title());
await browser.close();
The switch accepts an address with an optional scheme such as http://, https://, socks4:// or socks5://. Use whatever your provider specifies. The browser then handles HTTPS sites by asking the proxy to open a tunnel, a mechanism described in the MDN article on proxy servers and tunneling, so the proxy sees the host name but not the content.
Notice the explicit navigation timeout. Without one, a wrong address can leave your script waiting for a long time before it reports a failure. Always pick a limit that suits your workflow.
Step 2: add authentication
Chromium does not accept user:pass@ inside the --proxy-server value. When the proxy asks for credentials, Puppeteer lets you answer with page.authenticate, which must be called before navigation.
const page = await browser.newPage();
await page.authenticate({
username: process.env.PROXY_USER,
password: process.env.PROXY_PASS,
});
await page.goto('https://example.com/');
Each new page needs its own call. A helper that creates pages and authenticates them saves repeated lines and avoids the common bug where a second tab fails with a 407 response.
Keep the values out of logs. Do not print the options object after you have assembled it, and be careful with screenshots or traces that might capture an authentication dialog or a URL with embedded credentials.
Step 3: exclude local and internal hosts
By default everything the browser requests goes through the proxy. That is usually wrong for a local development server or an internal API: the proxy cannot reach your private network, and sending internal host names to a third party is something to avoid. Add a bypass list.
const browser = await puppeteer.launch({
args: [
`--proxy-server=http://${process.env.PROXY_HOST}:${process.env.PROXY_PORT}`,
'--proxy-bypass-list=localhost;127.0.0.1;*.internal.example',
],
});
Chromium uses a semicolon-separated format for this list, and patterns such as a leading *. match subdomains. Test the list by loading a bypassed address and confirming it succeeds, then loading a public address and confirming the proxy is used.
Step 4: different proxies for different contexts
Sometimes a single run needs to compare two routes. Recent Puppeteer versions let you create a browser context with its own proxy option.
const context = await browser.createBrowserContext({
proxyServer: 'http://endpoint-b.example.net:8080',
});
const page = await context.newPage();
await page.authenticate({
username: process.env.B_USER,
password: process.env.B_PASS,
});
Method and option names have changed across releases; older versions used a different method name for incognito-style contexts and some had no per-context proxy at all. Read the documentation for the version you installed instead of copying a snippet from an old post. If your version lacks the feature, the simple fallback is to launch two browser instances, each with its own --proxy-server flag.
The same idea exists in other tools. If your team is deciding between libraries, the guide to setting up a proxy in Playwright for website testing shows how a different tool handles contexts, and the equivalent in Selenium is covered in the article on setting up a proxy in Selenium for QA.
Step 5: SOCKS and its limits
For SOCKS, use a socks5:// address in the same switch.
args: ['--proxy-server=socks5://proxy.example.net:1080']
Chromium does not support username and password authentication for SOCKS proxies in the way it does for HTTP proxies, and page.authenticate does not apply to SOCKS. If your provider requires credentials, use an HTTP-type endpoint or authorise by IP address if the provider offers that option. The SOCKS5 protocol is defined in RFC 1928, which also describes authentication methods, but browser support is narrower than the protocol itself.
With SOCKS5 in Chromium, host name resolution can be handled by the proxy, but you should verify rather than assume. A browser performs many lookups, and the guide to checking for DNS leaks in a proxy setup explains how to test where they happen.
Step 6: verify the proxy is in use
Add a small check at the start of the run.
await page.goto('https://api.ipify.org/', { waitUntil: 'domcontentloaded' });
const ip = (await page.evaluate(() => document.body.innerText)).trim();
console.log('Public IP seen by sites:', ip);
Run it once without the proxy flag and once with it. The two addresses should differ. For a fixed endpoint, repeated runs should return the same value; for a rotating endpoint, expect variation as described by your provider. Treat the echo page as a diagnostic and do not call it in a tight loop.
Then check a real target page, preferably one you operate or that explicitly allows automated checks. Confirm the content you expect is present, and save a screenshot for human review.
Step 7: certificates, errors and clean-up
Puppeteer has an option to ignore HTTPS errors. Leave it off for public sites. If a certificate error appears only when the proxy is active, the reasons are discussed in the article on certificate cautions when using a proxy with HTTPS: an inspection layer, an outdated browser build, or a wrong clock. Turning verification off hides the real cause and exposes anything you send.
Handle failures explicitly and always close the browser, even when something throws.
let browser;
try {
browser = await puppeteer.launch({ args });
const page = await browser.newPage();
await page.authenticate({ username, password });
await page.goto(url, { timeout: 30000 });
} catch (err) {
console.error('Run failed:', err.message);
} finally {
if (browser) await browser.close();
}
Printing only err.message avoids dumping a full options object that might contain secrets. Unclosed browsers keep connections open and use memory, which is a frequent cause of slow, flaky CI jobs.
Common problems and quick fixes
| Symptom | Likely cause | What to try |
|---|---|---|
| ERR_PROXY_CONNECTION_FAILED | Wrong host, port or scheme | Re-check the details on the plan page |
| ERR_NO_SUPPORTED_PROXIES | Unsupported scheme in the flag | Use http://, https:// or socks5:// as provider specifies |
| 407 on the second tab | authenticate not called on that page | Authenticate every new page |
| Local server unreachable | Requests sent to the proxy | Add the host to the bypass list |
| Certificate error only with proxy | Inspection layer or old browser | Inspect the issuer; update the browser |
| Hangs on navigation | No timeout or dead endpoint | Set timeouts; run the IP check first |
Limits and what to watch for
- The proxy changes the IP address only. Language, time zone, cookies and browser characteristics also shape what a site shows, so a regional check is an approximation.
- Do not target protective measures. Using automation to defeat challenges or to hammer a page is outside lawful testing and usually breaks site terms.
- Mind concurrency. Many parallel pages through one endpoint multiply load. Check the plan page for what is included, and keep the number of tabs reasonable.
- Browser versions change behaviour. Pin versions in CI and review release notes when you upgrade, because proxy handling and API names evolve.
- Keep secrets out of artefacts. Screenshots, traces and logs can reveal URLs and headers; review them before sharing.
- Reuse is cheaper than relaunching. Opening a fresh browser per URL adds overhead. Reuse a browser for a batch and close it at the end.
Wrapping it into a reusable launcher
Once the pieces work, put them in a single module that every script imports. A shared launcher is the place to read environment variables, validate that they exist, build the argument list and apply defaults for timeouts. When the provider changes a hostname or you rotate a password, you edit one file instead of hunting through a dozen scripts.
export async function launchWithProxy() {
const { PROXY_HOST, PROXY_PORT } = process.env;
if (!PROXY_HOST || !PROXY_PORT) throw new Error('Proxy settings are missing');
return puppeteer.launch({
args: [`--proxy-server=http://${PROXY_HOST}:${PROXY_PORT}`],
});
}
A few practical habits go with this. Fail early and clearly when configuration is missing, because a silent fallback to a direct connection can make a test appear to pass while measuring the wrong thing. Log the host and port, never the credentials. Keep a short smoke test, run after every credential change and every Puppeteer upgrade, that loads the IP echo page and one harmless page on a site you operate. If the smoke test fails, the cause is almost always the address, the credentials or a browser version change, and you have found it before a long job starts.
Think also about pacing. Rendering a full page triggers dozens of sub-requests, so the load a browser puts on a site is larger than the number of URLs suggests. Add pauses between pages, keep batches modest, and stop if the site signals that you are asking too much. Scheduling a daily check is usually enough to catch a broken template, and it is considerate to the site and to your provider.
Finally, document what the script does for the next person: which endpoint it uses, which hosts bypass the proxy and which Puppeteer version it was tested with. A few lines in the repository README prevent a lot of guesswork later.
Summary
To use a proxy with Puppeteer, pass --proxy-server in the launch arguments, authenticate each page with page.authenticate, and read credentials from environment variables. Add --proxy-bypass-list for local and internal hosts, and check your Puppeteer version before relying on per-context proxies. Remember that Chromium has limits with authenticated SOCKS, verify the public IP at the start of each run, keep certificate checks on, and always close the browser. Treat results as one input among many, and keep every test lawful, polite and within the terms of the target site.
When you are ready to try a real endpoint, the options are described on the proxy page.
Frequently asked questions
How do I make Puppeteer use a proxy?
Pass the --proxy-server argument in the launch options, for example --proxy-server=http://host:port. Every page opened by that browser instance then sends its traffic through the proxy.
How do I supply a proxy username and password?
Chromium does not accept credentials in the proxy-server flag. Call page.authenticate with the username and password before navigating, and read both values from environment variables.
Can different pages use different proxies?
Newer Puppeteer versions let you create a browser context with its own proxy server option, so contexts in the same browser can use different proxies. Check the documentation for the version you installed, since method names have changed between releases.
How do I keep some addresses off the proxy?
Add the --proxy-bypass-list argument with a semicolon-separated list of hosts, such as localhost and your internal domains, so those requests connect directly.
How do I know the proxy is working?
Open a page that echoes your public IP address, once without the proxy and once with it, and compare. Make this a small check at the start of every run.
References
About the author

Bob Kanokphon Thongdee
- Founder of XPASS VPN
- Co-founder of eSIMonline.asia
- More than 7 years in online marketing
- Founder of Cojourney Visa and Cojourney Travel
Need a proxy for this?
XPASS Proxy sells residential proxy traffic by the gigabyte, with the price shown before you pay.
See proxy plansKeep reading

Proxy Guides
How to Set Up a Proxy in Playwright for Website Testing
Learn where Playwright accepts proxy settings, how to pass credentials safely, how to exclude hosts, and how to confirm a test really runs through the proxy.
9 min read

Proxy Guides
How to Set Up a Proxy in Selenium for QA Work
A practical guide to routing Selenium WebDriver sessions through a proxy for regional and environment testing, with Chrome and Firefox examples and a verification routine.
9 min read

Proxy Guides
How to Use a Proxy with Python Requests, Step by Step
A practical walk-through of configuring a proxy in Python Requests, from a single call to a reusable session, plus how to verify it works and debug common errors.
9 min read