v1.10.90-0e025b8
Skip to main content
Back to Hex Proxies

Proxies for Playwright

Last updated: April 2026

By Hex Proxies Engineering Team

Learn how to integrate proxy infrastructure into Playwright for geo-targeted testing, authenticated scraping, and distributed browser automation.

intermediate15 minutesdeveloper-qa

Prerequisites

  • Node.js 18+ or Python 3.10+
  • Playwright installed
  • Hex Proxies account

Steps

1

Install Playwright

Set up Playwright with browser binaries and configure your project for TypeScript or Python.

2

Configure proxy settings

Pass Hex Proxies credentials to the browser launch configuration for automatic proxy routing.

3

Implement geo-targeted tests

Create test functions that launch browsers through country-specific proxy configurations.

4

Add sticky sessions for flows

Use session-tagged proxy usernames for multi-page tests that require consistent IP identity.

5

Integrate with test runner

Wire proxy-based tests into the Playwright test runner for parallel geo-testing execution.

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 content ```

Sticky 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 flow ```

Parallel 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.

Tips

  • Use headless mode for CI/CD and headed mode for local debugging of proxy-related issues.
  • Playwright natively supports proxy auth — no need for browser extensions or manual header injection.
  • Use sticky sessions for any test that spans multiple page navigations.
  • Block unnecessary assets (images, fonts, analytics) with route interception to speed up proxied scraping.
  • ISP proxies add minimal latency — prefer them for speed-sensitive E2E test suites.

Ready to Get Started?

Put this guide into practice with Hex Proxies.