How to Use Stat Proxies with Playwright: Setup and Persistent Sessions
By Nicholas St. Germain. Published . Updated
Use Stat Proxies with Playwright by passing the HTTP proxy address, username, and password as separate fields in Playwright's proxy option. Keep the same assigned IP for a workflow that needs a consistent exit address. Saving browser storage is a separate step if you also need to reuse login cookies.
This guide covers browser automation, testing, and scraping. Stat supplies the proxy connection; the destination site still decides whether to accept a request or require a login or challenge.
What you need
- A Stat proxy IP, HTTP port, username, and password from your dashboard.
- Node.js and Playwright installed in your project.
- A page you want to open through that proxy.
Stat supports HTTP, HTTPS, and SOCKS5. For this Playwright example, use the authenticated HTTP endpoint. Playwright documents separate username and password fields for HTTP proxy authentication in its network guide and launch API reference.
Configure the proxy
Install the library and its Chromium browser:
npm install playwright
npx playwright install chromium
Set these environment variables using the values from your Stat dashboard:
| Variable | Value |
|---|---|
STAT_PROXY_SERVER |
http:// followed by your assigned proxy IP and HTTP port |
STAT_PROXY_USERNAME |
Your proxy username |
STAT_PROXY_PASSWORD |
Your proxy password |
The server field should contain only the scheme, host, and port. Do not put credentials in a Chromium --proxy-server flag. A management API bearer token also does not authenticate a proxy connection.
Save this as stat-playwright.cjs:
const { chromium } = require('playwright');
const fs = require('node:fs');
async function main() {
const server = process.env.STAT_PROXY_SERVER;
const username = process.env.STAT_PROXY_USERNAME;
const password = process.env.STAT_PROXY_PASSWORD;
if (!server || !username || !password) {
throw new Error('Set STAT_PROXY_SERVER, STAT_PROXY_USERNAME, and STAT_PROXY_PASSWORD.');
}
const endpoint = new URL(server);
if (endpoint.protocol !== 'http:' || endpoint.username || endpoint.password) {
throw new Error('Use an HTTP proxy address without embedded credentials.');
}
const statePath = '.auth/stat-playwright.json';
const browser = await chromium.launch({
headless: true,
proxy: { server, username, password },
});
try {
const context = await browser.newContext({
...(fs.existsSync(statePath) ? { storageState: statePath } : {}),
});
const page = await context.newPage();
const response = await page.goto('https://example.com', {
waitUntil: 'domcontentloaded',
timeout: 30000,
});
if (!response || !response.ok()) {
throw new Error('The destination did not return a successful HTTP response.');
}
console.log('Page title:', await page.title());
console.log('HTTP status:', response.status());
fs.mkdirSync('.auth', { recursive: true, mode: 0o700 });
await context.storageState({ path: statePath });
fs.chmodSync(statePath, 0o600);
await context.close();
} finally {
await browser.close();
}
}
main().catch((error) => {
console.error(error.message);
process.exitCode = 1;
});
Run it with node stat-playwright.cjs. The example opens a public demonstration page. Replace that URL with your destination and add the actions that your workflow needs. A successful HTTP response alone does not prove that a site returned the data you wanted; check the page content too.
Keep the IP and browser session consistent
A static IP and saved browser storage solve different problems:
- Static IP: reuse the same assigned proxy endpoint for subsequent runs. Stat does not automatically rotate it between requests.
- Browser storage: the example saves cookies and local storage and reloads them on the next run. It does not log you into a site automatically. Perform your login workflow before saving state when authentication is needed.
- Separate accounts: use a different storage file and browser context for each account. Assign the intended proxy to each context if you need different exit addresses within one browser.
Storage files may contain login credentials in the form of cookies. Add .auth/ to your project's .gitignore and keep these files private. Storage state is not a complete browser profile, and this example does not persist session storage. See Playwright's authentication guide.
Check the connection before scaling up
Start with one proxy and one browser context. To verify egress, visit an IP-check endpoint you trust through the same page and compare the reported address with the assigned proxy. Then test a small representative set of your destination pages and inspect their content.
| Symptom | What to check |
|---|---|
| Proxy authentication failure or 407 | Confirm the proxy username and password, and keep them in separate fields. Check that you copied the HTTP port. |
| Connection timeout | Check the IP and port, connectivity from the machine running Playwright, and any outbound firewall rules. |
| Destination returns 403 or a challenge | The destination may be rejecting the request. Check its response and your browser workflow; network uptime does not imply target-site acceptance. |
| Destination returns 429 | Reduce request rate and follow any retry guidance in the response. Unlimited bandwidth does not remove a destination's rate limits. |
| Login disappears between runs | Check that the correct storage file is loaded and that the login has not expired. Reusing an IP alone does not preserve cookies. |
| SOCKS5 authentication fails | Use Stat's authenticated HTTP endpoint for this example. SOCKS5 support at the proxy server does not establish support in the browser client. |
For more authentication details, see Playwright proxy authentication troubleshooting. For product specifications and order minimums, see ISP proxies and pricing.
Frequently asked questions
Can I use Stat Proxies with Playwright?
Yes. Configure the assigned HTTP proxy address and supply its username and password separately in Playwright's proxy option.
Do Stat proxies rotate automatically?
No. Stat provides static US proxy IPs. You can choose among the IPs you have purchased in your own application, but that is not an automatically rotating residential service.
Does unlimited bandwidth guarantee successful scraping?
No. Unlimited bandwidth describes the proxy plan's traffic allowance. Destination sites can still rate-limit, require authentication, or block requests.
Does saving storage keep an account logged in forever?
No. Saved cookies and local storage can restore a session, but the destination controls session expiry and may require authentication again.