The essential points from this guide -- each one is explained in detail below.
Playwright supports authenticated proxies natively through the proxy option on browser.launch() or browser.newContext().
Per-context proxy config lets you run multiple proxy identities in a single browser instance.
Both Python and Node.js Playwright APIs use the same proxy option structure.
Combine proxy config with Playwright's built-in stealth features for effective anti-bot bypass.
The simplest Playwright proxy setup applies to the entire browser instance through the launch options. All pages and contexts created from this browser use the same proxy. This is suitable for straightforward scraping where every request should exit through the same proxy provider.
# Python
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
'server': 'http://gw.knoxproxy.com:7000',
'username': 'USER',
'password': 'PASS',
})
page = browser.new_page()
page.goto('https://httpbin.org/ip')
print(page.content())
browser.close()// Node.js
const { chromium } = require('playwright');
const browser = await chromium.launch({
proxy: {
server: 'http://gw.knoxproxy.com:7000',
username: 'USER',
password: 'PASS',
},
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
console.log(await page.textContent('body'));
await browser.close();Playwright handles the 407 Proxy-Authenticate challenge internally, so authenticated proxies work without any extensions or workarounds. This is a significant advantage over Selenium.
Playwright can assign different proxies to different browser contexts within the same browser instance. This is powerful for multi-account management, geo-targeted scraping, or A/B testing from different IP ranges without launching multiple browsers.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
# US context
us_context = browser.new_context(proxy={
'server': 'http://gw.knoxproxy.com:7000',
'username': 'USER-country-us',
'password': 'PASS',
})
us_page = us_context.new_page()
us_page.goto('https://httpbin.org/ip')
# UK context
uk_context = browser.new_context(proxy={
'server': 'http://gw.knoxproxy.com:7000',
'username': 'USER-country-gb',
'password': 'PASS',
})
uk_page = uk_context.new_page()
uk_page.goto('https://httpbin.org/ip')
browser.close()Each context maintains its own cookies, storage, and proxy connection, so sessions do not leak between contexts. The browser launch must not include a proxy option when using per-context proxies -- otherwise the browser-level proxy takes precedence.
Playwright's async API enables concurrent page operations with proxied connections. Combined with a backconnect gateway that rotates IPs per connection, you can scrape many pages in parallel with each getting a different exit IP.
import asyncio
from playwright.async_api import async_playwright
async def scrape_url(browser, url):
context = await browser.new_context(proxy={
'server': 'http://gw.knoxproxy.com:7000',
'username': 'USER',
'password': 'PASS',
})
page = await context.new_page()
await page.goto(url, wait_until='domcontentloaded')
content = await page.content()
await context.close()
return content
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
urls = ['https://example.com/1', 'https://example.com/2']
results = await asyncio.gather(*[scrape_url(browser, u) for u in urls])
await browser.close()
asyncio.run(main())Creating a new context per URL ensures each request gets a fresh proxy connection and a different exit IP. Close contexts after use to free resources. Limit concurrency to 5-15 parallel contexts to avoid overwhelming the browser process.
Playwright includes built-in features that reduce detection compared to Selenium. Combine these with residential proxies for the most effective anti-bot bypass. Set a realistic viewport, user agent, locale, and timezone that match the proxy's geographic location.
context = browser.new_context(
proxy={
'server': 'http://gw.knoxproxy.com:7000',
'username': 'USER-country-us',
'password': 'PASS',
},
viewport={'width': 1920, 'height': 1080},
locale='en-US',
timezone_id='America/New_York',
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
)Mismatched fingerprints are a common detection vector. A US residential IP with a German locale and Tokyo timezone raises flags. Always align your browser fingerprint with the proxy's exit location. KnoxProxy's geo-targeting lets you specify country and city in the username, so match your context settings accordingly.
Ready to put this into practice? Browse Residential Proxies
KnoxProxy Research Team · Technical Content
Network engineers and proxy infrastructure specialists with 10+ years in anti-bot systems, web scraping, and IP routing.
90.4M+ ethically sourced residential IPs across 195 countries. Start free -- no credit card required.