Skip to main content
The Center's Directory
Code examples

Use a proxy with Playwright

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

Maintained by the ZZHTTP engineering teamUpdated September 20, 2026

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.

Did this answer your question?

Feedback is used only to improve the public documentation and does not submit accounts or request information.