Playwright proxy integration

Playwright proxy setup with isolated contexts and explicit session policy

Configure proxy credentials before navigation, align locale and timezone with the requested market, and validate the final page instead of treating a successful connection as a successful workflow.

proxy-session.log

$ configure route

country=US mode=rotating timeout=15s

$ validate response

route

matched

status

200

bytes

tracked

✓ bounded retry policy active

Playwright proxy patterns for independent and stateful jobs

Keep secrets in environment variables and choose session behavior from the page flow.

rotating.ts
import { chromium } from 'playwright';

const browser = await chromium.launch();
const context = await browser.newContext({
  proxy: {
    server: 'http://p1.bytesflows.com:8001',
    username: process.env.BF_ROTATING_USER,
    password: process.env.BF_PROXY_PASS,
  },
  locale: 'en-US',
});
const page = await context.newPage();
await page.goto('https://example.com', { timeout: 30_000 });
console.log({ url: page.url(), title: await page.title() });
await context.close();
await browser.close();

Create a new context for unrelated jobs and classify the page before extraction.

Choose Playwright session behavior from the workflow

Rotation and stickiness solve different problems and neither replaces page validation.

Feature
Rotating context
Sticky context
Independent URL checks
Adds unnecessary coupling
Multi-step public flow
Network identity can change
Preserves route temporarily
Cookie and local-storage continuity
Use separate contexts
Same context and route
High-volume stateless pages
Reduces route flexibility
Guarantee a usable target page
Validation required
Validation still required

Playwright proxy FAQ

Can the proxy be changed after a context starts?+

Treat proxy configuration as part of context creation. Create a new context when the route policy changes so cookies and network identity stay aligned.

Why does authentication fail with a valid password?+

Check endpoint, port, username format, URL encoding, and whether the client supports authenticated proxies. Separate proxy 407 responses from target 401 or 403 responses.

How should timeouts be set?+

Use separate budgets for browser launch, connection, navigation, and element waits. A single large timeout hides which stage is failing.

Should contexts be reused?+

Reuse only within one declared stateful workflow. Close contexts between unrelated jobs to prevent cookie, storage, and session leakage.

Controlled evaluation

Validate your Playwright route with one controlled script

Confirm authentication, observed market, page markers, session behavior, and bytes before moving the configuration into a worker pool.