Preloader
Others
  • Estimated reading time: 9 Minutes

Testing Mobile Web Pages From Real Carrier IPs With Playwright Device Emulation

Testing Mobile Web Pages From Real Carrier IPs With Playwright Device Emulation

Playwright makes it almost too easy to pretend you're on a phone. Pick a device from the built-in registry and your test gets a phone user agent, a small viewport and touch support. The page reflows, the hamburger menu shows up, and your mobile layout tests go green.

There's one thing the device registry can't change, though: the network. Every request still leaves from your laptop, your office connection or a CI runner in a cloud region. To the server, that "iPhone" is visiting from a data center or a corporate fiber line, and some sites notice.

This article looks at why that gap matters and where real carrier IPs fit in. It also covers adding them to Playwright without making a mess of your suite. There's no code below, just the decisions and option names you'll need. The ideas apply whether you use Playwright Test or the library API directly.

What Device Emulation Actually Covers

Device emulation in Playwright is really a bundle of browser context settings. A device descriptor sets the user agent, viewport, device scale factor, and the isMobile and hasTouch flags. The isMobile flag makes the browser respect the page's meta viewport tag, and hasTouch turns on touch events.

On top of that, you can set locale, timezoneId, geolocation and colorScheme for each context. These change what JavaScript on the page sees and what the browser tells the server about language. They're great for testing responsive layouts, touch handlers, date formatting and dark mode.

What none of these settings touch is the IP address. The geolocation option, for instance, only answers the browser's location API, and only after the permission is granted. A server that looks up the IP behind the request will still see wherever your test is actually running.

Why the IP Address Changes What a Mobile Page Shows

Many sites make decisions on the server before any of your front-end code runs. The IP address is one of the cheapest signals they have. A lookup against an IP database can return a country, a city, the network operator and sometimes a connection type.

That data can drive a surprising amount of what a mobile visitor sees. A few common examples:

  • Regional redirects. A visitor may be sent to a country subdomain, a localized path or a different language version of the page.
  • Local prices and availability. Product pages may show a regional price, currency or stock message based on where the request seems to come from.
  • Carrier-aware content. Some campaigns and landing pages show different offers or banners depending on the visitor's mobile network.
  • Consent and legal banners. Cookie notices and age gates often vary by region, and they can push your whole above-the-fold layout around.
  • Ad delivery. Ad networks can target by location and network type, so the ads on a mobile page may change with the connection.

There's also the question of how a site treats your traffic overall. IP databases commonly label data center ranges as hosting, and some sites handle hosting traffic more cautiously. You might get an extra challenge page, a generic version of the content, or fewer ads than a real visitor would see.

Mobile carrier IPs are a different case again. Carriers often use carrier-grade NAT, so many subscribers can share one public address at the same time. Sites tend to treat those addresses differently, because blocking one could affect lots of real people at once.

The Mismatch Problem

Picture a typical CI run. Your test claims to be a Pixel phone with a US English locale. The request arrives from a cloud region, on a hosting IP, with the time zone left at UTC.

Each setting is fine on its own, but together they don't describe any real visitor. A site that compares signals may treat the session with suspicion or simply fall back to defaults. Either way, your test isn't seeing the page a phone user in that market would get.

The fix is to make the network agree with the device. If you emulate a phone in Lyon, route that context through a French mobile IP and set locale and timezoneId to match. Now the layout, the language and the server-side decisions all line up.

How Playwright Handles Proxies

Playwright supports HTTP, HTTPS and SOCKS5 proxies out of the box. You pass a proxy object with a server address and, for HTTP proxies, an optional username and password. A bypass list lets chosen hosts skip the proxy entirely.

You can set the proxy at two levels. Set it when launching the browser and every context shares one exit. Set it per browser context with newContext, and things get much more interesting for mobile testing.

Per-context proxies let a single browser instance run several isolated "phones" side by side. One context can emulate an iPhone on a UK network while another emulates an Android phone in Germany. Each keeps its own cookies, storage, device settings and network exit.

In Playwright Test, the same proxy option lives in the use block. You can set it globally and override it per project. That maps nicely onto a projects list where each project is a pairing of device and market.

Building a Device and Carrier Matrix

A clean way to organize this is to treat each project as three things: a device, a market and a network. For example, you might run a mid-range Android phone in Brazil and an iPhone in the United States. Each one gets its own project name, so reports stay easy to read.

For each project, spread the device descriptor first and add your overrides after it. Order matters here, because device descriptors already define properties like viewport and isMobile. Anything you set after the spread wins.

Then set the market details so they match the IP:

  • locale should match the language a local phone would use, such as pt-BR or en-US.
  • timezoneId should match the region the IP sits in, such as America/Sao_Paulo.
  • geolocation only matters if the page asks for location, but keep it plausible for the same city.
  • proxy should point at an exit in that country, ideally on a mobile network.

Keep the matrix small at first. Two or three devices across two markets will catch most server-side surprises. You can widen it later for release checks or campaign launches.

Rotating vs Sticky Sessions in a Test Run

Mobile proxy pools usually offer two modes. Rotating mode can give you a new IP on every request. Sticky mode tries to keep the same IP for a stretch of time.

For most page tests, sticky is the safer choice. A single page load pulls in HTML, scripts, images and API calls. If those requests leave from different IPs, the site sees an odd mix of visitors and your results get noisy.

A good pattern is one sticky session per browser context. Many providers let you pick the session through the proxy credentials, so each context can get its own value. When the test finishes and the context closes, the next one starts with a fresh identity.

Rotating mode is better for sampling. Say you want to see a landing page across many mobile IPs in one city. Each run can come from a different address. Comparing those runs tells you whether a result is consistent or a one-off.

Don't write tests that assume an IP will last a fixed amount of time. Mobile connections can change address, and a sticky session may end sooner than you expect. Keep each journey short, or make sure the test survives an IP change halfway through.

Confirm the Exit Before You Test

It's worth adding a small check at the start of each context. Before loading the page under test, open an IP lookup endpoint and record what it returns. Log the IP, the country, the city if it's available, and the network name.

This catches a whole class of silent failures. A typo in the proxy settings, an expired credential or a broad bypass rule can leave you on your own network. Without the check the test still passes, and you only find out later that it proved nothing.

Attach the lookup result to your test report next to the screenshots. When someone asks why the Brazilian page showed a different banner, the network details are right there.

Keeping Tests Fast and Bandwidth Lean

Mobile proxies are usually billed by traffic, and mobile networks add latency. Both are good reasons to keep test traffic tight.

Playwright's request routing makes this easy. With page.route or context.route, you can abort requests for heavy files your check doesn't need, like video, large images or web fonts. A visual layout test may need its images, but a redirect or banner check usually doesn't.

A few other habits help:

  • Keep a journey in one context. A multi-page check, such as landing page to product page to local price, should run on one sticky session.
  • Raise timeouts a little. Mobile connections add latency, so tight default timeouts can turn slow responses into false failures.
  • Skip timing assertions over the proxy. Load times measured through a proxy mix your page's speed with the network's, so keep performance budgets for a separate setup.
  • Run carrier tests selectively. Most of your suite can run on the plain network, with the carrier matrix saved for tests where server-side behavior matters.

Choosing a Mobile Proxy Provider for Playwright

Not every mobile proxy service suits test automation equally well. When you compare options, these are the points worth checking:

  • Real carrier IPs. The addresses should come from SIM-based connections on actual mobile networks, so lookups classify them as mobile.
  • Targeting depth. Country targeting is the minimum, and city, region and carrier targeting let you match specific markets and campaigns.
  • Session control. You'll want both per-request rotation and sticky sessions, chosen per connection rather than per account.
  • Protocol support. Playwright accepts HTTP, HTTPS and SOCKS5 proxies, so make sure the provider offers a protocol that fits your setup.
  • Fair billing. Check whether you're charged only for successful requests, which keeps costs predictable while you debug a flaky suite.
  • Concurrency. Parallel workers each open their own connections, so concurrent session limits matter once tests run in CI.

If you need mobile carrier IPs in Playwright, ProxyEmpire's rotating mobile proxies offer country, region, city and carrier targeting across 170+ countries. Sessions can rotate on every request or stay sticky, so both sampling and multi-page checks are covered.

A Practical Starting Point

If you're adding carrier IPs to an existing suite, start small. Pick one important mobile page, two devices and two markets. Add the exit check, match locale and timezone to each IP, and run it next to your normal mobile project.

Then compare the screenshots side by side. Differences in redirects, banners, prices or ads tell you which tests deserve a permanent carrier project. Pages that look identical on both networks can stay on the faster, cheaper default.

Device emulation tells you how your page renders on a phone. Real carrier IPs tell you what the server decides to send that phone in the first place. You need both to know what your mobile visitors actually see.

Our Sponsors

Our blog is proudly supported by industry-leading sponsors.