# Configure TrueProxies with Playwright

> Configure TrueProxies in Playwright for Chromium or Firefox, with HTTP authentication, SOCKS5 trusted IP guidance and proxies for individual browser contexts.

Source: https://docs.trueproxies.com/integrations/playwright/

> **Use your own endpoints**
>
> The examples below use placeholders. Copy the connection host, ports, username, and proxy password from the **Username and password** tab of your service in the dashboard. See [How to connect](https://docs.trueproxies.com/proxy-instructions/how-to-connect/#connection-host-and-ports).

## Basic usage

**Chromium**

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

const browser = await chromium.launch({
  proxy: {
    server: 'http://YOUR_HOST:YOUR_HTTP_PORT',
    username: 'your_username',
    password: 'your_password',
  },
});

const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
console.log(await page.textContent('body'));
await browser.close();
```

**Firefox**

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

const browser = await firefox.launch({
  proxy: {
    server: 'http://YOUR_HOST:YOUR_HTTP_PORT',
    username: 'your_username',
    password: 'your_password',
  },
});

const page = await browser.newPage();
await page.goto('https://httpbin.org/ip');
console.log(await page.textContent('body'));
await browser.close();
```

## SOCKS5

Playwright’s browsers do not send a username and password to a SOCKS5 proxy; passing them fails with “Browser does not support socks5 proxy authentication”. To use SOCKS5, add the machine’s public address as a [trusted IP](https://docs.trueproxies.com/proxy-instructions/trusted-ips/) and connect without credentials. For username and password authentication, use the HTTP proxy shown above.

```javascript
const browser = await chromium.launch({
  proxy: {
    server: 'socks5://YOUR_HOST:YOUR_SOCKS_PORT',
  },
});
```

## Residential IPv4 country targeting

```javascript
const browser = await chromium.launch({
  proxy: {
    server: 'http://YOUR_HOST:YOUR_HTTP_PORT',
    username: 'your_username-country-us',
    password: 'your_password',
  },
});
```

## Residential IPv4 per-context proxies

Use different proxies per browser context:

```javascript
const browser = await chromium.launch();

const context = await browser.newContext({
  proxy: {
    server: 'http://YOUR_HOST:YOUR_HTTP_PORT',
    username: 'your_username-country-de',
    password: 'your_password',
  },
});

const page = await context.newPage();
await page.goto('https://httpbin.org/ip');
console.log(await page.textContent('body'));

await context.close();
await browser.close();
```

## Python

```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": "http://YOUR_HOST:YOUR_HTTP_PORT",
        "username": "your_username",
        "password": "your_password",
    })

    page = browser.new_page()
    page.goto("https://httpbin.org/ip")
    print(page.text_content("body"))
    browser.close()
```

## Related guides

- [Connection and username format](https://docs.trueproxies.com/proxy-instructions/how-to-connect/)
- [HTTP CONNECT and SOCKS5](https://docs.trueproxies.com/proxy-instructions/proxy-protocols/)
- [Trusted IPs](https://docs.trueproxies.com/proxy-instructions/trusted-ips/)
- [Troubleshooting checklist](https://docs.trueproxies.com/support/)
