# Proxy in Puppeteer, Playwright, Selenium and curl: code examples

Ready-made examples for browser automation and the command line. In the examples, `HOST`, `PORT`, `USER` and `PASS` are the data from “My proxies” in the ProxyZen dashboard. Every ProxyZen IPv4 and IPv6 proxy supports **HTTP and SOCKS5**.

## curl

```
# HTTP proxy
curl -x http://USER:PASS@HOST:PORT https://api.ipify.org

# SOCKS5, DNS resolved on the proxy side
curl -x socks5h://USER:PASS@HOST:PORT https://api.ipify.org

# login and password separately
curl -x http://HOST:PORT -U USER:PASS https://api.ipify.org
```

`socks5h` instead of `socks5` means website names are resolved by the proxy, not by your computer. If the password contains special characters (`@`, `:`, `#`), URL-encode them or pass them with `-U`.

## Puppeteer (Node.js)

Chrome does not accept a password in `--proxy-server`, so the login is passed with `page.authenticate`:

```js
const puppeteer = require('puppeteer');

const browser = await puppeteer.launch({
  args: ['--proxy-server=http://HOST:PORT'],
});
const page = await browser.newPage();
await page.authenticate({ username: 'USER', password: 'PASS' });
await page.goto('https://api.ipify.org');
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();
```

For SOCKS5 with a password in Chrome, use an HTTP proxy instead: Chrome does not support SOCKS5 authentication.

## Playwright (Node.js and Python)

Playwright accepts the login and password directly:

```js
const { chromium } = require('playwright');

const browser = await chromium.launch({
  proxy: { server: 'http://HOST:PORT', username: 'USER', password: 'PASS' },
});
const page = await browser.newPage();
await page.goto('https://api.ipify.org');
console.log(await page.textContent('body'));
await browser.close();
```

```python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": "http://HOST:PORT", "username": "USER", "password": "PASS",
    })
    page = browser.new_page()
    page.goto("https://api.ipify.org")
    print(page.inner_text("body"))
    browser.close()
```

You can also set a different proxy for each context: `browser.new_context(proxy={...})` — convenient for several accounts in one process.

## Selenium (Python)

Chrome in Selenium does not support a proxy password by itself. The simplest way is the `selenium-wire` package:

```python
from seleniumwire import webdriver

options = {
    "proxy": {
        "http": "http://USER:PASS@HOST:PORT",
        "https": "http://USER:PASS@HOST:PORT",
    }
}
driver = webdriver.Chrome(seleniumwire_options=options)
driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)
driver.quit()
```

## Scrapy and BeautifulSoup

BeautifulSoup only parses HTML; the proxy is set in the library that downloads the page (`requests`, `httpx`). Examples: [“How to use proxies in Python and Node.js”](https://proxyzen.net/en/blog/proxy-in-python-nodejs). In Scrapy, set `request.meta["proxy"] = "http://USER:PASS@HOST:PORT"`.

## Common errors

- **407 Proxy Authentication Required** — login or password not passed. See [this guide](https://proxyzen.net/en/blog/proxy-requires-username-password).
- **ERR_NO_SUPPORTED_PROXIES** in Chrome — SOCKS5 with a password. Use HTTP.
- **Timeouts** — check the proxy in the [proxy checker](https://proxyzen.net/en/tools/proxy-checker) and the port in the [port check](https://proxyzen.net/en/tools/port-check).
- **403 and CAPTCHAs** — too many requests from one IP. See [“Proxies for web scraping”](https://proxyzen.net/en/blog/proxies-for-web-scraping).

Proxies can also be bought and renewed automatically through the [ProxyZen API](https://proxyzen.net/en/api). Private IPv4 from **$0.60**, residential from **$1.59** per GB. [Buy proxies](https://proxyzen.net/cabinet/buy).

*Originally published on the [ProxyZen blog](https://proxyzen.net/en/blog/proxy-puppeteer-playwright-curl).*

