Proxy setup in Playwright

Proxies in Playwright with the username and password in the proxy option: Chromium, Firefox and WebKit, a proxy per context, and SOCKS5 limits.

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 go into server, the username and password into username and password
  • For a username with a password - HTTP; the country changes in username, server stays the same
  • The correct result - the proxy IP in the script output; with several contexts each has its own address
Proxies in Playwright: a short video guide · 0:35 · Open the video page
Video transcript

Prokso proxies in Playwright.

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

In Playwright, the proxy is set when you launch the browser: server, username and password go into one proxy option.

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 Playwright. It takes a few minutes.

Step 1. Split the line into server, username and password for the proxy option

Playwright does not accept a proxy line as a whole: the proxy option takes server, username and password separately, plus bypass with a list of domains that go direct, if needed. So the host:port:username:password format in the dashboard generator is handy: the host and port go into server, the rest into the other two fields.

According to the Playwright documentation, server can look like http://gw.prokso.com:823 or socks5://gw.prokso.com:824, and an entry without a scheme is treated as an HTTP proxy. The documentation describes the username and password for an HTTP proxy, so for a script with a username choose the HTTP(S) protocol in the generator.

The mode in the "IP address" field depends on the task. "Rotating (new IP per request)" (port 823) suits data collection, where each page can come from a different address. "Sticky session" gives ports 10000-20000, which keep one address for 1 to 120 minutes: use it when the script signs in to an account or goes through several pages in a row. The country is written in the username, for example username__cr.ua, so it changes in the username field, while server stays the same.

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. Set the proxy in the launch options

Playwright takes the proxy together with the username and password in the proxy option - no separate authentication needed. Works for Chromium, Firefox and WebKit.

Step 3. Run the example

The code below opens a page and prints the proxy IP. In Python the syntax is the same: chromium.launch(proxy={...}).

import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: { server: "http://gw.prokso.com:823", username: "USERNAME", password: "PASSWORD" },
});
const page = await browser.newPage();
await page.goto("https://api.ipify.org");
console.log(await page.textContent("body"));
await browser.close();

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

Step 4. Different IPs for different contexts

You can also set a proxy per context: browser.newContext({ proxy }). That way one browser runs several profiles on different sticky ports.

Step 5. Read the IP that the Playwright script printed

The example from step 3 opens https://api.ipify.org in the browser that Playwright controls and prints the page content to the console. It should show one IP address, and it must not match your computer's address. Run the script twice: on port 823 the addresses differ, on a sticky port they stay the same until the session duration runs out.

If the proxy is set per context, as in step 4, open the same address in each context and print the result next to the port number. Different sticky ports should give different IPs. Identical addresses mean the contexts got the same server.

A regular browser on your computer knows nothing about the script's settings, so the My IP page in it will show your address. Look only at the output of the script itself, and if an error appears instead of an IP, find it in the "If the page does not open" section below.

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

A proxy per context: several IPs in one browser

A context in Playwright is an isolated profile with its own cookies. By giving each context its own sticky port, you get several independent sessions in one browser:

const browser = await chromium.launch();

for (const port of [10001, 10002]) {
  // each context has its own cookies and its own sticky IP
  const context = await browser.newContext({
    proxy: { server: `http://gw.prokso.com:${port}`, username: "USERNAME", password: "PASSWORD" },
  });
  const page = await context.newPage();
  await page.goto("https://prokso.com/ip");
  console.log(port, await page.textContent("body"));
  await context.close();
}
await browser.close();

This saves memory compared with a separate browser for each session.

How to cut traffic use

Cancel the loading of heavy resources through route. Images, video, and fonts make up most of a page's volume and are not needed for data collection:

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

If the page does not open

  • net::ERR_PROXY_CONNECTION_FAILED. The browser could not reach the proxy: check the server field.
  • net::ERR_TUNNEL_CONNECTION_FAILED. The proxy refused the connection: check the username, the password, and the remaining traffic.
  • Navigation timeout. The default 30 seconds can be too short for residential addresses. Increase the timeout in page.goto().
  • SOCKS5 with a password in Chromium. The Chromium documentation says Chrome has no authentication for SOCKSv5. Use HTTP or access by IP.

More about the codes is on the proxy error codes page.

If the proxy does not work

FAQ

Does the proxy work the same in Chromium, Firefox, and WebKit?

The proxy option is the same for all three engines: the same fields server, username, password and bypass. For an HTTP proxy with a username and password this is enough. SOCKS5 with a password is not supported in Chromium, so it needs the IP whitelist.

How do I set a proxy in Playwright Test tests?

In the configuration file, in the use section, specify the same proxy object with the server, username, and password fields.

Can I send some addresses past the proxy?

Yes, the proxy object has a bypass field that takes a comma-separated list of domains.

Was this guide helpful?

Proxy not working? Check it in 6 steps

Install the Prokso app