Developer Guide · Python · Node.js · Playwright

How to Use Mobile Proxieswith Playwright

Playwright has built-in proxy support with authentication — no extensions or workarounds needed. This guide covers Python and Node.js examples, per-context proxies for multi-account setups, and IP rotation via API.

Apr 8, 2026
7 min read

Python Example

Install Playwright for Python:

pip install playwright
playwright install chromium

Pass proxy credentials directly to browser.launch(). Playwright handles authentication natively:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(proxy={
        "server": "http://HOSTNAME:HTTP_PORT",
        "username": "USERNAME",
        "password": "PASSWORD",
    })
    page = browser.new_page()
    page.goto("https://httpbin.org/ip")
    print(page.content())
    browser.close()

No workarounds needed: Unlike Selenium, Playwright sends proxy credentials through its internal connection handler. You do not need selenium-wire, browser extensions, or any third-party libraries.

Node.js Example

Install Playwright for Node.js:

npm install playwright

The proxy configuration is identical in structure. Pass server, username, and password to chromium.launch():

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

(async () => {
  const browser = await chromium.launch({
    proxy: {
      server: 'http://HOSTNAME:HTTP_PORT',
      username: 'USERNAME',
      password: 'PASSWORD',
    },
  });
  const page = await browser.newPage();
  await page.goto('https://httpbin.org/ip');
  console.log(await page.content());
  await browser.close();
})();

SOCKS5 support: Change the server to socks5://HOSTNAME:SOCKS5_PORT to use SOCKS5 instead of HTTP. Playwright supports both protocols with the same authentication fields.

Per-Context Proxy for Multi-Account

Playwright lets you assign a different proxy to each browser context. This is ideal for managing multiple accounts where each account needs its own IP address. Launch the browser without a proxy, then set the proxy at the context level:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    # Launch browser WITHOUT a global proxy
    browser = p.chromium.launch()

    # Account 1: US proxy
    context_us = browser.new_context(proxy={
        "server": "http://US_HOSTNAME:HTTP_PORT",
        "username": "US_USERNAME",
        "password": "US_PASSWORD",
    })
    page_us = context_us.new_page()
    page_us.goto("https://httpbin.org/ip")
    print("Account 1 IP:", page_us.content())

    # Account 2: UK proxy
    context_uk = browser.new_context(proxy={
        "server": "http://UK_HOSTNAME:HTTP_PORT",
        "username": "UK_USERNAME",
        "password": "UK_PASSWORD",
    })
    page_uk = context_uk.new_page()
    page_uk.goto("https://httpbin.org/ip")
    print("Account 2 IP:", page_uk.content())

    context_us.close()
    context_uk.close()
    browser.close()

Isolation: Each context has its own cookies, local storage, and proxy. Sessions never leak between contexts, making this the cleanest approach for multi-account management.

IP Rotation via API

Trigger an IP change mid-session using the mobileproxies.org rotation API. This works from both Python and Node.js:

Python

import time
import requests

API_KEY = 'YOUR_API_KEY'
SLOT_ID = 'YOUR_SLOT_ID'

# Trigger IP rotation
resp = requests.post(
    f'https://buy.mobileproxies.org/api/v1/proxies/{SLOT_ID}/switch',
    headers={'Authorization': f'Bearer {API_KEY}'}
)
print('Rotation status:', resp.status_code)

# Wait for the modem to reconnect
time.sleep(15)

Node.js

const API_KEY = 'YOUR_API_KEY';
const SLOT_ID = 'YOUR_SLOT_ID';

const resp = await fetch(
  `https://buy.mobileproxies.org/api/v1/proxies/${SLOT_ID}/switch`,
  {
    method: 'POST',
    headers: { Authorization: `Bearer ${API_KEY}` },
  }
);
console.log('Rotation status:', resp.status);

// Wait for the modem to reconnect
await new Promise(r => setTimeout(r, 15000));

After rotation: You do not need to reconfigure the proxy or restart the browser. The same hostname and port will resolve to the new IP once the modem reconnects. Just wait and continue.

Why Playwright for Proxies

Native authentication

Playwright handles proxy auth internally. No need for selenium-wire, browser extensions, or custom Chrome plugins. Pass username and password directly and it works.

Per-context proxy assignment

One browser instance, many proxies. Each context is fully isolated with its own network route, cookies, and storage. Puppeteer and Selenium require separate browser instances for different proxies.

Cross-browser, cross-language

The same proxy config works across Chromium, Firefox, and WebKit, and across Python, Node.js, Java, and .NET. Write once, run on any browser engine.

Ready to automate with mobile proxies?

Get proxy credentials with HTTP and SOCKS5 endpoints, IP rotation API access, and carrier-grade IPs that pass anti-bot detection.