Playwright's native proxy support makes it ideal for web automation. Configure SOCKS5 or HTTP proxies with authentication for Chromium, Firefox, and WebKit.
import { chromium } from 'playwright';
const browser = await chromium.launch({
proxy: {
server: 'socks5://proxy.proxies.sx:10001',
username: 'your_username',
password: 'your_password'
}
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
console.log(await page.textContent('body'));
await browser.close();import { chromium, Browser, BrowserContext } from 'playwright';
// Launch browser without proxy
const browser: Browser = await chromium.launch({ headless: true });
// Create contexts with different proxies
const usContext: BrowserContext = await browser.newContext({
proxy: {
server: 'socks5://proxy.proxies.sx:10001', // US port
username: 'your_username',
password: 'your_password'
}
});
const ukContext: BrowserContext = await browser.newContext({
proxy: {
server: 'socks5://proxy.proxies.sx:10002', // UK port
username: 'your_username',
password: 'your_password'
}
});
// Use different contexts for different regions
const usPage = await usContext.newPage();
const ukPage = await ukContext.newPage();
await usPage.goto('https://amazon.com');
await ukPage.goto('https://amazon.co.uk');
await browser.close();import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(
proxy={
"server": "socks5://proxy.proxies.sx:10001",
"username": "your_username",
"password": "your_password"
}
)
page = await browser.new_page()
await page.goto("https://httpbin.org/ip")
ip_info = await page.text_content("body")
print(f"Current IP: {ip_info}")
await browser.close()
asyncio.run(main())from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": "socks5://proxy.proxies.sx:10001",
"username": "your_username",
"password": "your_password"
},
headless=True
)
context = browser.new_context(
viewport={"width": 1920, "height": 1080},
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64)..."
)
page = context.new_page()
page.goto("https://example.com")
page.screenshot(path="screenshot.png")
browser.close()import { chromium } from 'playwright';
// HTTP proxy format
const browser = await chromium.launch({
proxy: {
server: 'http://proxy.proxies.sx:10001',
username: 'your_username',
password: 'your_password'
}
});
// Or with inline credentials (not recommended for production)
const browserAlt = await chromium.launch({
proxy: {
server: 'http://user:pass@proxy.proxies.sx:10001'
}
});import { chromium } from 'playwright';
const browser = await chromium.launch({
proxy: {
server: 'socks5://proxy.proxies.sx:10001',
username: 'your_username',
password: 'your_password'
},
headless: true,
args: [
'--disable-blink-features=AutomationControlled',
'--disable-features=IsolateOrigins,site-per-process'
]
});
const context = await browser.newContext({
viewport: { width: 1920, height: 1080 },
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36',
locale: 'en-US',
timezoneId: 'America/New_York',
geolocation: { longitude: -73.935242, latitude: 40.730610 },
permissions: ['geolocation']
});
// Override navigator properties
await context.addInitScript(() => {
Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
});
const page = await context.newPage();Create new contexts for different proxy configurations instead of launching new browsers. Faster and more resource-efficient.
Set timezoneId and geolocation to match your proxy location. Sites check for consistency between IP and browser settings.
Implement retry logic with proxy rotation. If a page fails to load, switch to a different proxy port and retry.
SOCKS5 proxies support all TCP traffic including WebSocket connections. HTTP proxies may not work with all web features.
Get mobile proxies for reliable cross-browser automation.