Proxies for Playwright
Playwright is the leading browser automation framework for E2E testing and web scraping. Its built-in proxy support makes it straightforward to route all browser traffic through Hex Proxies — enabling geo-targeted testing, distributed scraping, and realistic multi-location QA.
Basic Proxy Configuration (TypeScript)
import { chromium } from 'playwright';
const browser = await chromium.launch({
proxy: {
server: 'http://gate.hexproxies.com:8080',
username: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
},
});
const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
const content = await page.textContent('body');
console.log('Proxy IP:', content);
await browser.close();Geo-Targeted Testing
import { chromium, Browser } from 'playwright';
async function testFromCountry(url: string, country: string): Promise<{
country: string;
title: string;
status: number;
}> {
const browser = await chromium.launch({
proxy: {
server: 'http://gate.hexproxies.com:8080',
username: `YOUR_USERNAME-country-${country.toLowerCase()}`,
password: 'YOUR_PASSWORD',
},
});
const page = await browser.newPage();
const response = await page.goto(url, { waitUntil: 'domcontentloaded' });
const title = await page.title();
await browser.close();
return { country, title, status: response?.status() ?? 0 };
}
// Test from multiple countries
const countries = ['US', 'GB', 'DE', 'JP', 'BR'];
const results = await Promise.all(
countries.map(c => testFromCountry('https://yoursite.com', c))
);
console.table(results);Python Playwright with Proxy
from playwright.sync_api import sync_playwright
def scrape_with_proxy(url: str, username: str, password: str) -> str:
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "http://gate.hexproxies.com:8080",
"username": username,
"password": password,
})
page = browser.new_page()
page.goto(url, wait_until="domcontentloaded")
content = page.content()
browser.close()
return contentSticky Sessions for Multi-Page Flows
When testing login flows or multi-step processes that need the same IP:
const browser = await chromium.launch({
proxy: {
server: 'http://gate.hexproxies.com:8080',
username: 'YOUR_USERNAME-session-checkout-test-1',
password: 'YOUR_PASSWORD',
},
});
const context = await browser.newContext();
const page = await context.newPage();
// Multi-step checkout test with consistent IP
await page.goto('https://shop.example.com/cart');
await page.click('[data-testid="checkout"]');
await page.fill('#email', 'test@example.com');
await page.click('[data-testid="continue"]');
// Same IP throughout the flowParallel Geo-Testing in Playwright Test Runner
import { test, expect } from '@playwright/test';
const countries = ['US', 'GB', 'DE', 'JP'];
for (const country of countries) {
test(`pricing page shows correct content for ${country}`, async () => {
const browser = await chromium.launch({
proxy: {
server: 'http://gate.hexproxies.com:8080',
username: `YOUR_USERNAME-country-${country.toLowerCase()}`,
password: 'YOUR_PASSWORD',
},
});
const page = await browser.newPage();
await page.goto('https://yoursite.com/pricing');
// Assert country-specific content
const content = await page.textContent('body');
expect(content).toBeTruthy();
await browser.close();
});
}Performance Notes
Playwright adds browser rendering overhead on top of network latency. With Hex Proxies ISP proxies adding only 10-30ms to each request, the proxy layer is negligible compared to page render time. For scraping-focused use cases, consider using Playwright's request interception to skip unnecessary assets and reduce page load time.