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