How to Use Mobile Proxies with Playwright

Playwright has a proxy option at launch that takes the server, the username and the password directly, so no extra authentication call is needed. The script below prints the address the IP page sees.

What do I need before I start?

Hostgw.mobileproxy.live
HTTP and HTTPS port9000
SOCKS5 port9100
Usernamemp4x9q2.mobile.us.sid-a1b2.rot-10
PasswordYOUR_PASSWORD (your own line password)
  • Node.js 18 or newer
  • Playwright (npm install playwright, then npx playwright install chromium)
  • Your username and password in your account under My lines. The username above is an example, and each part is explained in the username reference.

How do I set it up?

  1. Install the package and the browser with npm install playwright followed by npx playwright install chromium.
  2. Save the code below as check-ip.mjs.
  3. Replace YOUR_PASSWORD with your password.
  4. Run node check-ip.mjs and read the output.
  5. To use a different line per test, create a new browser context with its own proxy option.
  6. Close the browser at the end of every run so no sessions stay open.

What does the code look like?

check-ip.mjs
import { chromium } from "playwright";

const browser = await chromium.launch({
  proxy: {
    server: "http://gw.mobileproxy.live:9000",
    username: "mp4x9q2.mobile.us.sid-a1b2.rot-10",
    password: "YOUR_PASSWORD",
  },
});
const page = await browser.newPage();
await page.goto("https://ipinfo.io/json");
console.log(await page.textContent("body"));
await browser.close();

How do I check my IP?

The output is the JSON of https://ipinfo.io/json. Its ip and country must be those of your line.

https://ipinfo.io/json

On a mobile line you can ask for a fresh address at any time with your change-IP link, for example https://gw.mobileproxy.live/rotate/k7Qm2xV9. The real link for each line is in your account.

What if it does not work?

net::ERR_PROXY_CONNECTION_FAILED.

Verify the server value includes http:// and the HTTP port, and that your line is active.

A 407 error appears.

The username or password is wrong. Copy them again from your account.

The test is slow.

Block images and fonts in the test with page routing to save mobile data and time.

Frequently asked questions

Can I set a different proxy for each context?

Yes. Pass the same proxy option to browser.newContext() and every context gets its own line and its own username.

Does it work with Firefox or WebKit?

The proxy option works for all three engines that Playwright supports.

Can I use Playwright for Python?

Yes. The launch call takes the same proxy dictionary with server, username and password.

Related guides

Need a line to connect?

Create an account, top up your balance and your first line is ready to use with Playwright.

Create account