Proxy exits in 64 countries and 172 cities, sold per GB, IP, day or request.

Code and command line

Playwright proxy setup

Playwright takes proxy credentials as plain options, so there is no extension or prompt to deal with. You pass a server, a username and a password when the browser starts, or give each browser context its own set. The second pattern is the useful one for TopProxy: one context per country or per session, all inside a single browser process.

Examples are given for Node.js and Python. The option names are the same in both, only the casing of the methods changes.

What do you need before adding a proxy in Playwright?

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.

Requirements for Playwright
RequirementDetail
Playwright installednpm i playwright (or the test runner), or pip install playwright, then the browser download step.
Browsers downloadednpx playwright install chromium, or python -m playwright install chromium.
TopProxy loginA rotating login such as tp7k2m9_country-us or a sticky one with a session name.
Your passwordRead it from an environment variable in real code.

Where do the proxy host, port and login go in Playwright?

Work through the steps in order. Swap YOUR_PASSWORD for your proxy password and tp7k2m9 for your account name.

  1. Pass the proxy when the browser launches

    The proxy option takes the gateway address without credentials in server, and the login pair in username and password. Every page in this browser then goes through the gateway.

    const { chromium } = require('playwright');
    
    (async () => {
      const browser = await chromium.launch({
        proxy: {
          server: 'http://proxy.topproxy.shop:8080',
          username: 'tp7k2m9_country-us',
          password: process.env.TOPPROXY_PASSWORD || 'YOUR_PASSWORD',
        },
      });
      const page = await browser.newPage();
      await page.goto('https://ipinfo.io/json');
      console.log(await page.textContent('body'));
      await browser.close();
    })();
  2. Give each context its own login

    A browser context is an isolated profile with its own cookies and storage. Setting the proxy on the context lets you run several locations or sessions side by side without starting a new browser each time.

    const browser = await chromium.launch();
    for (const cc of ['us', 'de', 'jp']) {
      const ctx = await browser.newContext({
        proxy: {
          server: 'http://proxy.topproxy.shop:8080',
          username: 'tp7k2m9_country-' + cc,
          password: process.env.TOPPROXY_PASSWORD,
        },
        locale: cc === 'de' ? 'de-DE' : cc === 'jp' ? 'ja-JP' : 'en-US',
      });
      const page = await ctx.newPage();
      await page.goto('https://ipinfo.io/json');
      console.log(cc, await page.textContent('body'));
      await ctx.close();
    }

    Tip.Match locale and timezoneId on the context to the exit country, so the page sees a consistent visitor.

  3. Use the same settings in the test runner

    With @playwright/test, put the proxy under use in the config file. Every test then runs through the gateway, and you can override it per project to test several markets in one run.

    import { defineConfig } from '@playwright/test';
    
    export default defineConfig({
      use: {
        proxy: {
          server: 'http://proxy.topproxy.shop:8080',
          username: 'tp7k2m9_country-gb',
          password: process.env.TOPPROXY_PASSWORD ?? '',
        },
      },
    });
  4. Save bandwidth on metered products

    Residential and mobile traffic is billed per GB, and images, fonts and video are most of a page. Blocking them with a route handler often cuts traffic by more than half when you only need text.

    await page.route('**/*', (route) => {
      const t = route.request().resourceType();
      return ['image', 'media', 'font'].includes(t) ? route.abort() : route.continue();
    });

How can you confirm the proxy is active in Playwright?

Open ipinfo.io in the proxied page and parse the body. The country value should match the code in the login. A second run with the same rotating login normally shows a different ip.

await page.goto('https://ipinfo.io/json');
const info = JSON.parse(await page.textContent('body'));
console.log(info.ip, info.city, info.country);

The response shown here is shortened to the fields that matter. The region and time zone follow the exit, in this case United States.

GET https://ipinfo.io/json
{
  "ip": "198.51.100.47",
  "city": "Chicago",
  "region": "Illinois",
  "country": "US",
  "timezone": "America/Chicago"
}

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 Playwright?

A browser keeps connections open and reuses them, so even a rotating login can stay on one exit for a while inside one context. When a flow must keep one address from the first page to the last, such as a login followed by several clicks, add a session name and a life to the username for that context.

username: 'tp7k2m9_country-us'

How the login is put together

Every setting lives in the login, joined with underscores. Nothing else in Playwright changes when you switch location or session.

Parts of a TopProxy login
PartMeaningRule
tp7k2m9Your account nameAlways first. Yours is shown in your account and replaces tp7k2m9 in every example here.
_country-usExit countryTwo-letter code in lowercase. 64 countries to choose from.
_city-new-yorkExit city, optionalLowercase, spaces become hyphens. 172 cities in total.
_session-a1b2c3Session name, optionalLetters and digits you pick. Same name, same exit. New name, new exit.
_life-30Session life in minutesOnly 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 Playwright?

Change the country code or add a city in the username. Pair the location with locale and timezone settings on the context.

username: 'tp7k2m9_country-au'

Codes and city values for all 64 countries are listed on the proxy locations pages.

How do you fix proxy connection errors in Playwright?

Find the line that matches what you see. Most problems come down to the login, the port or the network you are on.

Playwright symptoms, causes and fixes
SymptomLikely causeFix
net::ERR_TUNNEL_CONNECTION_FAILEDThe gateway refused the login, often a wrong password or a login with a typo in the country code.Test the same login with cURL first, then copy it back into the options.
Browser does not support socks5 proxy authenticationThe SOCKS5 port was used with a username and password.Use http://proxy.topproxy.shop:8080 as the server.
Credentials ignored, exit is your own IPThe login was written into the server URL, which Playwright does not read for auth.Keep server as host and port only, and fill username and password.
Timeouts on heavy pagesDefault navigation waits for every resource through the proxy.Use waitUntil: 'domcontentloaded' and block media you do not need.

Still stuck? Run the same login through the cURL check. If cURL connects, the issue is in the Playwright settings. If it does not, write to support with the error text.

What kind of proxy pairs well with Playwright?

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.

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 Playwright users ask about proxies?

Is it better to set the proxy at launch or per context?

Per context when you need several locations or sessions in parallel, because contexts are cheap and isolated. At launch when the whole run uses one login. Both use the same server, username and password fields.

Does this work with Firefox and WebKit?

Yes. The proxy option is the same for all three engines. Only Chromium has had extra rules on some older versions about needing a proxy at launch to use per-context proxies, which current releases no longer require.

Can I run Playwright headless with a proxy?

Yes. Headless and headed modes use the same proxy settings. Some sites treat headless browsers differently, which is unrelated to the proxy.

How do I change the IP in the middle of a run?

Close the context and create a new one with a different session name in the username. Changing the proxy of an open context is not supported.

Will route blocking break page logic?

Blocking images, fonts and media rarely breaks text extraction. Do not block scripts or XHR on pages that load content with JavaScript, since that is where the data comes from.

Ready to connect Playwright?

Open an account, add $40 or more in crypto, and your login and password are waiting in the account area.