Skip to content
Nefo

Playwright

How to Use Residential Proxies with Playwright

Pass Nefo credentials straight into Playwright's proxy option, run several countries or sticky sessions in one browser, and keep authentication out of your page code.

Before you start

Nefo offers residential proxies in 227 countries over HTTP, HTTPS, and SOCKS5 with username/password auth. Generate credentials in the dashboard proxy generator; that step is free and only routed traffic uses your prepaid bandwidth (from 5 GB for $4.50, non-expiring on flexible plans).

Playwright accepts proxy credentials directly in the launch options, so no separate authentication event handler is needed.

  • Node.js 18+ with @playwright/test or playwright installed
  • Browsers installed via npx playwright install
  • A Nefo account with prepaid bandwidth
  • A username/password from /dashboard/generator
  • The country token for your target region

Playwright proxy example

Set the proxy on the launch call:

You can also scope proxies per context with browser.newContext({ proxy: {...} }), which lets one browser run several geo profiles side by side just by changing the username token.

shell
import { chromium } from 'playwright';

const browser = await chromium.launch({
  proxy: {
    server: 'http://gw.nefo.net:9000',
    username: 'USERNAME-country-us',
    password: 'PASSWORD',
  },
});
const page = await browser.newPage();
await page.goto('https://api.ipify.org');

Playwright rotating vs sticky proxy sessions

Rotating sessions give a new residential IP per request on HTTP port 9000, ideal for high-volume, distributed crawling.

Sticky sessions pin one IP from 1 minute to 24 hours on HTTP port 10000. Use a token like USERNAME-country-us-session-shop1-lifetime-60 to keep the same IP for a 60-minute session. Playwright supports authenticated HTTP proxies, so prefer the HTTP ports when you need username/password auth.

Geo-targeting in the Playwright proxy username

Targeting lives in the username: country for 227 countries, US state and city, or ASN/ISP within a country. Change only the username to move exits between regions without touching your code paths.

Collect data responsibly, honor site terms of service, and respect applicable laws and reasonable request rates.

Frequently asked questions

Yes. Pass a proxy object to browser.newContext() and change the username token per context. One browser can then run several countries or sticky sessions side by side.

Start with 5 GB. Keep what you don't use.

Residential bandwidth from $0.53/GB that never expires. Card, PayPal, Apple Pay, Google Pay, Alipay and crypto.