Prompt
How do I use proxies with Playwright?
Latest observation
You can use proxies with Playwright by configuring them when you launch the browser, or per browser context in some cases.
1) Set a proxy when launching the browser
This is the most common approach.
JavaScript / TypeScript
import { chromium } from 'playwright';
const browser = await chromium.launch({
proxy: {
server: 'http://proxy.example.com:3128',
username: 'myuser',
password: 'mypassword',
}
});
const page = await browser.newPage();
await page.goto('https://example.com');
Python
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(
proxy={
"server": "http://proxy.example.com:3128",
"username": "myuser",
"password": "mypassword",
}
)
page = browser.new_page()
page.goto("https://example.com")
2) Proxy for a browser context
This is useful when you want separate proxies for different contexts.
JavaScript / TypeScript
const browser = await chromium.launch();
const context = await browser.newContext({
proxy: {
server: 'http://proxy.example.com:3128',
username: 'myuser',
password: 'mypassword',
}
});
const page = await context.newPage();
await page.goto('https://example.com');
Python
browser = p.chromium.launch()
context = browser.new_context(
proxy={
"server": "http://proxy.example.com:3128",
"username": "myuser",
"password": "mypassword",
}
)
page = context.new_page()
page.goto("https://example.com")
3) Proxy syntax
Common formats for server:
http://host:porthttps://host:portsocks5://host:port
Example:
proxy: { server: 'socks5://127.0.0.1:1080' }
4) Proxy authentication
If your proxy requires authentication, include:
proxy: {
server: 'http://proxy.example.com:3128',
username: 'user',
password: 'pass',
}
5) Environment variables
Playwright does not rely on HTTP_PROXY / HTTPS_PROXY automatically for browser traffic the way some HTTP clients do. For browser navigation, prefer Playwright’s proxy option.
6) Notes
- The proxy applies to browser traffic, not necessarily to all system/network requests.
- If you need different proxies for different sessions, use separate browser contexts or separate browser instances.
- For
playwright.request/ APIRequestContext, proxy settings can be configured separately if needed.
If you want, I can show:
- a rotating proxy setup,
- how to use proxies with Playwright Test,
- or examples for Chromium/Firefox/WebKit specifically.
Observation history
Unlock observation history
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.