# Use a proxy with Playwright

Configure the accounting proxy at browser startup, isolate the context and verify the exit IP and region.

Playwright natively supports providing a proxy server, username, and password when the browser starts. Different proxy identities should use different browser instances.

## Playwright

```javascript
import { chromium } from 'playwright';

const browser = await chromium.launch({
  proxy: {
    server: 'http://us.zzhttp.com:7878',
    username: process.env.PROXY_USERNAME,
    password: process.env.PROXY_PASSWORD,
  },
});

const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://ipinfo.io/json');
console.log(await page.textContent('body'));
await browser.close();
```

## Configuration

- Accounting proxy server uses fixed values `us.zzhttp.com:7878`.
- The username must be the full service-side generated value.
- The password is read from the environment variable.

## Segregation

- Different tasks create separate BrowserContexts.
- Different proxy identities do not share the same browser process.
- Cleans cookies, cache and download directories by task.

## Verification

- Open the test page and check the response `ip`, `country` and `region`; The geographical location is an estimate from a third-party database.
- Then visit the business page that allows automation.

## Security and Compliance

- Do not write credentials to the trace, snapshot file name, or log.
- Comply with automation and access rules for target sites.

html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}
