Proxy setup in Puppeteer

Proxies in Puppeteer: the --proxy-server flag, credentials via page.authenticate(), a separate sticky port for each browser, and saving traffic.

Updated · Prokso editorial team

Markdown, ready to paste into ChatGPT or another AI assistant
Connection details
Host
gw.prokso.com
Port
823 HTTP · 824 SOCKS5 - new IP per request · 10000–20000 sticky session, HTTP(S) and SOCKS5
Username and password
in your dashboard, on the plan page

Your dashboard generates ready-made lines in the format you need: choose the country, IP type and protocol.

Key takeaways
  • Generator format - host:port:username:password: the host and port in --proxy-server, the username and password in page.authenticate()
  • HTTP protocol: Chromium does not support SOCKS5 with a password
  • The correct result - the proxy IP that the script printed from api.ipify.org
Proxies in Puppeteer: a short video guide · 0:35 · Open the video page
Video transcript

Prokso proxies in Puppeteer.

First, get your proxy details from the dashboard: host, port, username and password. They are on the plan page, in the Access block.

In Puppeteer, pass the proxy address when you launch the browser, and the username and password with the authenticate method on the page.

Run the example: the output should show the proxy IP, not yours. On port 823, every run gets a new address.

The full guide with examples is on the Prokso website.

A step-by-step guide to connecting Prokso proxies in Puppeteer. It takes a few minutes.

Step 1. Split the line: host and port for --proxy-server, username for page.authenticate()

In Puppeteer the proxy details go to two different places. The host and port are set when the browser is launched with the --proxy-server argument, and the username and password are passed later with the page.authenticate() method. The Chromium documentation says directly that the browser does not use credentials written into the proxy settings, so a line with the username inside the address will not work here.

So the host:port:username:password format in the dashboard generator is handy: the first two parts go into the launch argument, the last two into authenticate(). The protocol is HTTP(S), because Chromium does not support SOCKS5 with a username and password.

Choose the port for the scenario. 823 gives a new IP for every request, and while loading one page the browser can reach the site from several addresses. To sign in to an account, take "Sticky session": a port from the 10000-20000 range keeps one address for 1 to 120 minutes. The country is set by part of the username, for example username__cr.ua, and it goes into page.authenticate(), not into the launch argument.

The “Access” block on the plan page: host, ports, username and password for the proxy line
The “Access” block on the plan page: host, ports, username and password for the proxy line

Step 2. Pass the proxy at launch

Chromium in Puppeteer takes the proxy from the --proxy-server argument. Give only the host and port - no username or password.

Step 3. Authenticate on the page

Pass the username and password with page.authenticate() before the first navigation. The example below opens a page showing your IP.

import puppeteer from "puppeteer";

const browser = await puppeteer.launch({ args: ["--proxy-server=http://gw.prokso.com:823"] });
const page = await browser.newPage();
await page.authenticate({ username: "USERNAME", password: "PASSWORD" });
await page.goto("https://api.ipify.org");
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();

Save it as check.mjs and run node check.mjs.

Step 4. One IP per session

For account work, launch each browser on its own sticky port 10000-20000 so cookies and IPs don't mix.

Step 5. Print the IP from the Puppeteer browser

The example from step 3 goes to https://api.ipify.org and prints the page text through page.evaluate(). The console should show the proxy IP, not your computer's address. If several browsers have different sticky ports, print the IP from each one: the addresses should differ.

If the script stops with the net::ERR_INVALID_AUTH_CREDENTIALS error instead of an IP, check that page.authenticate() is called before the first page.goto() in this tab. Other errors are covered in the "If the page does not open" section below.

Your regular Chrome on the computer knows nothing about Puppeteer's launch arguments, so the My IP page in it will show your address.

Example run: the output shows the proxy IP, not yours. On port 823 every run gets a new address
Example run: the output shows the proxy IP, not yours. On port 823 every run gets a new address

How to cut traffic use

A browser loads everything: images, fonts, video, ads. For data collection that is unnecessary. Request interception lets you cancel what you do not need:

await page.setRequestInterception(true);
page.on("request", (req) => {
  // skip heavy resources: they are not needed for data collection
  const skip = ["image", "media", "font"].includes(req.resourceType());
  skip ? req.abort() : req.continue();
});

On pages with a lot of images, this cuts the volume several times over. It is better not to block styles: without them some sites render the page differently, and the elements you need may not appear.

A separate IP for each browser

The --proxy-server argument is set at launch and applies to the whole browser. You cannot change the proxy of a running browser. To get a different IP, launch another browser with a different sticky port or restart the current one.

For accounts, add a separate profile folder to the proxy through userDataDir: then each account has its own cookies and its own IP.

If the page does not open

  • net::ERR_PROXY_CONNECTION_FAILED. The browser could not reach the proxy: check the host and port in the launch argument.
  • net::ERR_TUNNEL_CONNECTION_FAILED. The proxy refused the connection: the username and password are wrong or the traffic has run out.
  • net::ERR_INVALID_AUTH_CREDENTIALS. page.authenticate() was called after navigation or with a typo. Call it before the first page.goto().
  • Navigation timeout. Pages load more slowly through residential addresses. Increase the timeout in page.goto().

A breakdown of the first two errors is on the ERR_PROXY_CONNECTION_FAILED and ERR_TUNNEL_CONNECTION_FAILED pages.

If the proxy does not work

FAQ

Do I need to call page.authenticate() for every tab?

Yes. Authentication is set per page, so call it for every new tab before navigation.

How do I work with Puppeteer without page.authenticate()?

Add the IP of your computer or server to the IP whitelist on the plan page, up to 5 addresses. Then the proxy lets you in without a password, and page.authenticate() is not needed.

Does --proxy-server work in Puppeteer headless mode?

Yes, the launch argument works the same with a window and without one.

Was this guide helpful?

Proxy not working? Check it in 6 steps

Install the Prokso app