Skip to main content

12 min read

Playwright Proxy Setup With Residential Proxies

Set up a Playwright proxy with residential IPs: launch vs per-context proxies, country targeting, sticky sessions, bandwidth-saving routes and error fixes.

Theatre stage with three spotlit browser windows representing Playwright contexts using residential proxies

Quick answer

To use a Playwright proxy, pass a proxy setting with the server, username and password either when you launch the browser or when you create a browser context. With residential proxies, set it per context: each context gets its own exit IP, country, sticky session, locale and cookies, so one browser can check several markets at once without them mixing. Verify each route, block heavy media to save bandwidth, and use sticky sessions for any multi-page flow.

Key takeaways

  • Two places to set a proxy: at launch for the whole browser, or per context for separate identities. Per context is usually the better choice.
  • One context, one consistent visitor: pair each context’s proxy location with a matching locale and time zone.
  • Use the HTTP endpoint for authenticated proxies: Playwright documents username and password for HTTP proxies.
  • Block what you do not need: aborting images, media and fonts can cut residential bandwidth sharply.
  • Sticky sessions for flows, rotation for single pages: the same rule as everywhere else, now applied per context.

Why Playwright and residential proxies work well together

Playwright drives real browsers, Chromium, Firefox and WebKit, which makes it the right tool for JavaScript-heavy pages, single-page applications and anything that only shows its content after scripts run. A plain HTTP client sees an empty shell on those pages. Playwright sees what a visitor sees.

Residential proxies complete the picture. A real browser on a datacenter IP still looks like a server, and it cannot show you what visitors in another country see. Routing Playwright through residential proxies gives each browser session a household IP in the location you choose, so the page, prices, language and ads match what local visitors get.

This guide uses Playwright for Python, in keeping with our Python Requests guide. The same options exist in Playwright for Node.js, Java and .NET under similar names.

What you need

  • Python 3 with Playwright installed (pip install playwright, then playwright install chromium).
  • Your QuickProxy gateway (gate.quickproxy.io:8000), username and password from the dashboard.
  • Your credentials stored as environment variables, here QP_USER and QP_PASS, so they never appear in your code.
  • A target you are allowed to automate, such as your own website or public pages whose terms permit it.

QuickProxy sets targeting in the username. The examples use -cc-de for a German exit and -session-label for a sticky session. Check your dashboard for the exact syntax of region, city and ISP parameters.

Launch-level vs context-level proxies

Playwright’s documentation says a proxy can be set globally for the browser or individually for each browser context. A context is an isolated browser profile with its own cookies, storage and settings, and it is cheap to create.

Approach How it works Best for Limitation
Launch-level proxy Every page in the browser uses one proxy setting Simple scripts with one location and one identity Switching location means restarting the browser
Context-level proxy Each context has its own proxy, cookies and locale Several markets, several sessions, or parallel work in one browser Slightly more setup per context

Step 1: The simplest setup, a proxy at launch

Start by confirming the route works. This script launches Chromium through a German residential exit and prints the IP details the browser sees.

import os

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": "http://gate.quickproxy.io:8000",
        "username": f"{os.environ['QP_USER']}-cc-de",
        "password": os.environ["QP_PASS"],
    })
    page = browser.new_page()
    page.goto("https://ipinfo.io/json", timeout=60000)
    print(page.inner_text("body"))
    browser.close()

The output should show a country of DE. If it shows your own location, or the request fails, fix that before going further. The troubleshooting table at the end of this guide covers the common errors.

Step 2: One browser, several countries, with per-context proxies

This is where Playwright shines with residential proxies. Each context gets its own exit country, sticky session, locale and time zone, so it behaves like a separate, consistent local visitor. Here the script screenshots a page you own as visitors in Germany, Japan and Brazil see it.

import os

from playwright.sync_api import sync_playwright

GATEWAY = "http://gate.quickproxy.io:8000"
PAGE = "https://www.example.com/pricing"  # A page you own or may test

MARKETS = {
    "de": {"locale": "de-DE", "timezone_id": "Europe/Berlin"},
    "jp": {"locale": "ja-JP", "timezone_id": "Asia/Tokyo"},
    "br": {"locale": "pt-BR", "timezone_id": "America/Sao_Paulo"},
}


def proxy_for(country, session):
    return {
        "server": GATEWAY,
        "username": f"{os.environ['QP_USER']}-cc-{country}-session-{session}",
        "password": os.environ["QP_PASS"],
    }


with sync_playwright() as p:
    browser = p.chromium.launch()
    for country, settings in MARKETS.items():
        context = browser.new_context(proxy=proxy_for(country, f"qa{country}"), **settings)
        page = context.new_page()
        page.goto(PAGE, wait_until="domcontentloaded", timeout=60000)
        page.screenshot(path=f"pricing-{country}.png", full_page=True)
        print(country, page.url, page.title())
        context.close()
    browser.close()

Matching the locale and time zone to the exit matters. A German IP with an English browser and a US time zone is an inconsistent visitor, which can change the content you get and raise a site’s suspicion. Our guide to geo-targeted residential proxies explains why consistency matters.

Step 3: Keep one IP through a multi-step flow

Logins, baskets and checkouts expect the same visitor from start to finish. Rotating the IP between steps breaks the session. Give the context a sticky session label and do the whole flow inside it. QuickProxy sticky sessions last up to 30 minutes, which covers most flows.

import os

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    context = browser.new_context(
        proxy={
            "server": "http://gate.quickproxy.io:8000",
            "username": f"{os.environ['QP_USER']}-cc-gb-session-checkout01",
            "password": os.environ["QP_PASS"],
        },
        locale="en-GB",
        timezone_id="Europe/London",
    )
    page = context.new_page()

    # Test flow on your own store: product page, basket, delivery options
    page.goto("https://shop.example.com/product/123", timeout=60000)
    page.click("text=Add to basket")
    page.goto("https://shop.example.com/basket")
    print(page.inner_text("#delivery-options"))

    context.close()
    browser.close()

Use a new session label for each independent flow, such as checkout01, checkout02, so flows do not share an IP unless you want them to.

Step 4: Block heavy resources to save bandwidth

Residential proxies are usually billed per gigabyte, and browsers download everything: images, video, fonts and third-party scripts. If you only need the page’s text or data, abort the rest. Playwright’s routing lets you do this per context by checking each request’s resource type.

BLOCKED_TYPES = {"image", "media", "font"}


def block_heavy(route):
    if route.request.resource_type in BLOCKED_TYPES:
        return route.abort()
    return route.continue_()


# Apply to a context before opening pages
context.route("**/*", block_heavy)

Keep images enabled when they are what you are checking, for example in ad verification or visual QA. For a full picture of where bandwidth goes, see how much proxy bandwidth do you need?

Step 5: Handle timeouts and retry with a fresh IP

Residential exits can be slower than datacenter servers, and an individual IP can drop. Set realistic timeouts, and when a page fails, retry in a new context with a new session label so you get a different IP. Cap the number of attempts and pause between them.

import os
import time

from playwright.sync_api import TimeoutError as PlaywrightTimeout
from playwright.sync_api import sync_playwright


def fetch_title(browser, url, country, attempts=3):
    for attempt in range(1, attempts + 1):
        context = browser.new_context(proxy={
            "server": "http://gate.quickproxy.io:8000",
            "username": f"{os.environ['QP_USER']}-cc-{country}-session-r{attempt}",
            "password": os.environ["QP_PASS"],
        })
        try:
            page = context.new_page()
            page.goto(url, wait_until="domcontentloaded", timeout=45000)
            return page.title()
        except PlaywrightTimeout:
            print(f"Attempt {attempt} timed out, retrying with a new IP")
            time.sleep(5 * attempt)
        finally:
            context.close()
    return None


with sync_playwright() as p:
    browser = p.chromium.launch()
    print(fetch_title(browser, "https://www.example.com/", "fr"))
    browser.close()

If retries keep failing on one site, the IP is probably not the problem. Our guide on why residential proxies get blocked walks through the other causes.

Scaling up: running several contexts in parallel

Once a single context works, the natural next step is to run several at once. Contexts are lightweight compared with full browsers, so one browser can host many of them, each with its own proxy and session. A few rules keep parallel work stable:

  • Start small and measure. Begin with two or three contexts at a time, watch success rates and page load times, and increase only while both stay healthy.
  • Give every parallel task its own session label. Two tasks sharing one sticky label share one IP, which defeats the purpose of running them separately.
  • Prefer more contexts over more browsers. Each extra browser process uses far more memory than an extra context.
  • Spread load across targets and time. Ten contexts hitting the same small website at once looks like a burst, not ten visitors. Stagger start times and mix targets.
  • Consider the async API for larger jobs. Playwright’s async interface lets one Python process manage many contexts efficiently, with a limit on how many run at the same time.
  • Keep an eye on bandwidth. Parallel browsers consume residential bandwidth quickly, so resource blocking matters even more at scale.

Parallelism multiplies both your throughput and your mistakes. Get one context right, then scale.

Choosing session settings for Playwright tasks

Task Proxy setting Context strategy
Single page check per market Rotating or a short sticky session One context per check, closed afterwards
Multi-page browsing as one visitor Sticky session One context for the whole visit
Login, basket or checkout testing Sticky session with its own label One context per flow
Comparing several countries One country parameter per context Several contexts in one browser, with matching locales
Retrying after a failure New session label A fresh context so cookies and IP both reset
Long jobs over 30 minutes Sticky sessions renewed in the same location Plan for the session to change and keep state in your own code

Troubleshooting Playwright proxy errors

Error messages differ between Chromium, Firefox and WebKit, but the causes are the same.

Symptom Likely cause Fix
HTTP 407 or an authentication prompt Wrong username or password, or credentials not passed Check the environment variables and the username parameters
net::ERR_PROXY_CONNECTION_FAILED in Chromium Wrong gateway host or port, or a firewall blocking the connection Confirm gate.quickproxy.io:8000 and test with cURL
net::ERR_TUNNEL_CONNECTION_FAILED The proxy could not reach the target through that exit Retry with a new session label; check the targeting parameters
Timeouts on goto Slow exit, heavy page or waiting for the wrong load state Use domcontentloaded, block heavy resources, raise the timeout
The IP check shows your own location The proxy setting is not applied to that context Pass proxy to the context you are actually using
Wrong country or language on the page Locale, time zone or cookies disagree with the exit Match the locale and time zone and use a fresh context per market
Authentication fails with a socks5:// server Playwright documents username and password for HTTP proxies Use the HTTP endpoint for authenticated residential proxies
Logged out halfway through a flow The IP rotated mid-session Use a sticky session label for the whole flow

For proxy errors outside Playwright, see our list of the 10 most common proxy errors.

Common mistakes

  • Hard-coding credentials: keep them in environment variables or a secrets manager, never in scripts or screenshots.
  • One context for every market: cookies and storage carry over, so a previous country’s choices leak into the next check.
  • Waiting for networkidle on busy pages: pages with constant background requests may never become idle. Wait for the element you need instead.
  • Loading every resource by default: images and video can multiply your bandwidth usage without improving your data.
  • Running too many contexts at once: high concurrency raises block rates and resource use. Scale gradually. See concurrent connections explained.
  • Forgetting to close contexts: open contexts keep memory and sessions alive. Close them when each task ends.

Best practices

  1. Verify every new route with an IP lookup before running real work.
  2. Treat each context as one visitor: one location, one locale, one session.
  3. Use the lightest tool that works: if a page does not need JavaScript, a plain HTTP client is faster and far cheaper.
  4. Automate responsibly: test your own properties freely, respect other sites’ terms, robots.txt and rate limits, and do not automate logins to accounts you are not authorised to use.
  5. Log the context details with every result: country, session label, time and outcome.

When to use QuickProxy residential proxies

QuickProxy fits Playwright projects that need a real local view: localisation QA, regional pricing checks, ad and landing page verification, and testing JavaScript-heavy pages in several markets. Targeting by country, region, city and ISP is set in the proxy username, so each Playwright context can have its own location and sticky session without any dashboard changes. Every plan includes unlimited threads and HTTP, HTTPS and SOCKS5 support.

Start with the trial to verify your routes and measure your bandwidth, then choose a package on the pricing page.

FAQ

How do I set a proxy in Playwright?

Pass a proxy dictionary with server, and optionally username and password, to launch() for the whole browser or to new_context() for a single context.

Can I use a different proxy for each Playwright context?

Yes. Playwright supports setting a proxy individually for each browser context, so one browser can run several contexts with different exit countries and sessions.

Does Playwright support SOCKS5 proxies?

Yes, the server can be a socks5:// address. Playwright’s documentation describes username and password authentication for HTTP proxies, so use the HTTP endpoint when your residential proxy requires credentials.

How do I rotate proxies in Playwright?

Create a new context with a different session label, or with rotating settings, for each task. Closing the old context and opening a new one resets both the IP and the cookies.

How can I reduce bandwidth when using Playwright with proxies?

Use context.route() to abort requests whose resource type is image, media or font, wait for domcontentloaded rather than full idle, and use a plain HTTP client for pages that do not need JavaScript.

Why does my Playwright proxy show the wrong location?

Either the proxy is not applied to the context you are using, or the page is following your locale, time zone or cookies instead of the IP. Verify the exit with an IP lookup and align the locale and time zone with the market.

Should I use Playwright or Python Requests with proxies?

Use Requests for pages and APIs that return their content without JavaScript, because it is faster and uses far less bandwidth. Use Playwright when content only appears after scripts run, or when you need screenshots and real browser behaviour.

Conclusion

Playwright and residential proxies are a strong pair for anything that needs a real browser and a real local view. Set the proxy per context, keep each context consistent with its location, use sticky sessions for flows, block resources you do not need, and retry failures with a fresh IP. With those habits, one script can check many markets reliably and economically.

Try QuickProxy residential proxies with the examples in this guide, starting with the route check in Step 1.

Related reading

Put the article into practice.

Spin up real residential IPs in 150+ countries. Pay once or subscribe — from $11.