Playwright Mobile Emulation: What It Changes
Separate what a device descriptor sets, what it leaves to the context, and who wins when both name the same surface. Measured on one owned Chrome run.
BotBrowser Team
Want the structured docs for Getting Started?
This article lives in the editorial library. For step-by-step setup, reference material, and ongoing updates, jump into the docs section.
A green result on devices['iPhone 13'] does not mean the context now reads as an iPhone in every surface a site can check. "playwright mobile emulation" bundles several mechanisms under one preset, and they fail separately: the device descriptor rewrites the user agent string, the viewport and device scale factor, and touch support; the context options named locale and timezoneId own language and timezone and are not part of the descriptor at all; and the page under test decides what innerWidth reports, because a page without a viewport meta tag does not lay out at the width the descriptor sets. A reader who applies the descriptor and asserts on all six surfaces at once will find that two of them never moved.
The owned run below applies the same iPhone 13 descriptor to headless Chrome 158.0.8127.89 in three configurations: alone, plus explicit locale and timezoneId overrides, and against a context that pins its own user agent and language on top of the spread descriptor. The BotBrowser launcher guide documents how a real Chromium binary starts with a profile, and BotBrowser profiles pin UA, viewport, locale and timezone, so an emulated device can stay consistent with the profile instead of fighting it; BotBrowser does not add device sensors or hardware signals beyond what Chromium device emulation already provides. The Playwright emulation documentation describes each knob separately; the run below records what a combination of them produced on six surfaces at once.
TL;DR
- A device descriptor changes the UA string, the viewport and device scale factor, and touch support. The iPhone 13 descriptor flipped a
HeadlessChrome/158.0.0.0Macintosh UA to the iPhone Safari string, devicePixelRatio from1to3, andmaxTouchPointsfrom0to1. - The descriptor does not set language or timezone. With the descriptor alone,
navigator.languagestayeden-USand the timezone stayedAmerica/Toronto, the same host defaults the baseline row recorded. - The owned report page carries no viewport meta tag, so
innerWidthanswered980x1669instead of the390x664the descriptor sets. Mobile emulation emulates a mobile browser; it does not make an untagged page lay out like a mobile-optimized one. locale: 'de-DE'andtimezoneId: 'Europe/Berlin'on the samenewContextcall moved language and timezone while every descriptor-set surface stayed where it was.- An explicit context value beats the descriptor. Pinning
userAgentandlocale: 'fr-FR'on top of the spread descriptor produced the pinned UA andfr-FR; viewport, DPR and touch still came from the descriptor. - BotBrowser profiles pin UA, viewport, locale and timezone, so an emulated device can stay consistent with the profile instead of fighting it; BotBrowser does not add device sensors or hardware signals beyond what Chromium device emulation already provides.
Table of contents
- What a device descriptor changes
- What the owned run measured
- The 980 pixel layout viewport trap
- When a pinned context beats the descriptor
- BotBrowser capability and limitation
- Practical conclusion
- Keep reading
The custom user agent page covers one descriptor-set surface in isolation, and the timezone and locale page covers the context-set pair. What follows keeps both in the same frame, because the failures that matter live between them.
What a device descriptor changes
A Playwright device descriptor is a plain object of context options. devices['iPhone 13'] carries a userAgent string, a viewport of 390x664, a screen of 390x844, deviceScaleFactor: 3, isMobile: true, hasTouch: true, and defaultBrowserType: 'webkit'. Spreading it into browser.newContext(options) hands Playwright one options object in which each field is an ordinary context option; the descriptor is a preset, not a separate mechanism. The new context reference documents every field the spread produces. The Android entries in the same registry follow the same shape; Playwright Android emulation drives a different mechanism for real Android devices, which the owned run does not touch.
Each field lands on a different surface:
| Surface | Descriptor field | Baseline (no options) | Descriptor applied |
|---|---|---|---|
| User agent | userAgent | HeadlessChrome/158.0.0.0 | iPhone Safari string |
| Viewport set | viewport | 1280x720 | 390x664 |
| Viewport reported | page markup | 1280x720 | 980x1669 (no meta tag, see below) |
| devicePixelRatio | deviceScaleFactor | 1 | 3 |
| Touch points | hasTouch | 0 | 1 |
| Language | not in descriptor | en-US | en-US (unchanged) |
| Timezone | not in descriptor | America/Toronto | America/Toronto (unchanged) |
The userAgent field replaces the whole string: the baseline row read Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/158.0.0.0 Safari/537.36, and with the descriptor applied the same surface read Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1. isMobile switches on mobile viewport behavior, which is why the reported viewport row differs from the set viewport row; hasTouch enables touch event support and shows up as navigator.maxTouchPoints; deviceScaleFactor becomes window.devicePixelRatio. The descriptor also carries defaultBrowserType: 'webkit', which records which engine the preset was tuned for; the owned run launched Chromium with the spread, so the browser rendered with Chromium while reporting the Safari-style string. Nothing in the descriptor touches language or timezone, and the two unchanged rows in the table are the visible half of that split.
The descriptor is a preset, not a mode
Reading the descriptor as a mode ("the browser is now an iPhone") overstates it. The descriptor is seven fields of context configuration that happen to ship together, and anything else the context needs comes from other context options or from the harness. A test that spreads a descriptor and then asserts on navigator.language is asserting on a surface the descriptor never wrote.
locale and timezoneId are context options in their own right, listed on the context reference and grouped separately from devices on the emulation page. A device preset does not carry them, so with the descriptor alone the context inherits the host defaults: the owned run recorded en-US and America/Toronto in both the baseline row and the descriptor-alone row.
The split has a practical consequence. A test that emulates an iPhone and then checks a localized string, a currency, or a date format is checking a surface the descriptor never set, and on a host whose defaults differ from the target market the assertion fails for a reason that has nothing to do with the emulation. The fix is to name the surfaces explicitly: locale: 'de-DE' and timezoneId: 'Europe/Berlin' on the same newContext call moved those two surfaces and no others in the owned run, while the UA, the reported viewport, the DPR and touch support stayed where the descriptor put them. The timezone and locale page treats that pair in depth; the same reasoning applies to geolocation, which is also a context option and also absent from the device registry.
What the owned run measured
The owned fixture docs/evidence/playwright-mobile-emulation-what-it-changes-fixture-20261125.mjs launched one installed stock Chrome build, version 158.0.8127.89, headless, through Playwright. A local HTTP server bound to 127.0.0.1 served one owned /report.html page whose script reads six surfaces: navigator.userAgent, innerWidth and innerHeight, window.devicePixelRatio, navigator.maxTouchPoints, navigator.language, and the Intl timezone. Each case opened a fresh context with the configuration under test, loaded the report page, read the surfaces, and closed the context. A control row opened a context with no options at all to record the host baseline. No third-party request was made; all traffic stayed on 127.0.0.1.
The fixture prints a one-line summary of the three case outcomes to stdout; that line is:
{"status":"passed","cases":[{"case":"descriptor-alone","status":"passed"},{"case":"descriptor-plus-overrides","status":"passed"},{"case":"pinned-context-versus-descriptor","status":"passed"}]}
The measured record from docs/evidence/playwright-mobile-emulation-what-it-changes-run-20261125.json is:
| Case | User agent | Viewport reported | DPR | Touch | Language | Timezone |
|---|---|---|---|---|---|---|
| baseline (no options) | HeadlessChrome, Macintosh | 1280x720 | 1 | 0 | en-US | America/Toronto |
| descriptor-alone | iPhone Safari string | 980x1669 | 3 | 1 | en-US | America/Toronto |
| descriptor-plus-overrides | iPhone Safari string | 980x1669 | 3 | 1 | de-DE | Europe/Berlin |
| pinned-context-versus-descriptor | pinned string (see below) | 980x1669 | 3 | 1 | fr-FR | America/Toronto |
The three configurations were:
// case 1: descriptor alone
const alone = { ...devices['iPhone 13'] };
// case 2: descriptor plus context-set surfaces
const overridden = {
...devices['iPhone 13'],
locale: 'de-DE',
timezoneId: 'Europe/Berlin',
};
// case 3: descriptor against a context that pins its own UA and language
const pinned = {
...devices['iPhone 13'],
userAgent: 'Mozilla/5.0 (pinned-by-context) Chrome/158',
locale: 'fr-FR',
};
Case 1 against case 2: only the context-set surfaces moved
Comparing the first two measured rows isolates the descriptor's reach. Every descriptor-set surface is identical between them: the same iPhone UA string, the same reported viewport, the same DPR, the same touch count. The only two surfaces that differ are navigator.language (en-US versus de-DE) and the timezone (America/Toronto versus Europe/Berlin). Those are the two surfaces locale and timezoneId own, and the run shows them moving under explicit context options while the descriptor's surfaces hold still.
Case 3 against case 1: the pinned surfaces moved, the rest held
The third case adds two explicit options on top of the spread descriptor. The UA the page read was Mozilla/5.0 (pinned-by-context) Chrome/158, not the iPhone string, and the language was fr-FR, not en-US. The viewport stayed 980x1669, the DPR stayed 3, touch stayed at 1, and the timezone stayed America/Toronto because case 3 named no timezoneId. The next sections read those two observations in order.
The 980 pixel layout viewport trap
The descriptor sets viewport: { width: 390, height: 664 }, and the owned report page still read 980x1669. The reason is the page, not the descriptor: the report page ships no viewport meta tag. A mobile browser that loads a page without <meta name="viewport"> falls back to a wide layout viewport, around 980 CSS pixels, and scales it to fit the emulated screen, which is the behavior desktop pages rely on to avoid looking clipped on a phone. isMobile: true from the descriptor switches that fallback behavior on, so the browser emulates a mobile device faithfully and the page answers with the layout viewport the fallback produces. How a scale factor maps CSS pixels onto physical pixels is the device pixel ratio policy topic; the owned run reads it at the same surface level as the viewport.
The run's numbers make the split visible. The descriptor-set viewport is 390x664; the reported viewport is 980x1669; the DPR is 3 either way. A test that asserts innerWidth === 390 after spreading the descriptor is really asserting that the page under test carries a viewport meta tag, and the owned record shows a page without one answering 980. The fix is in the page markup: a page that ships <meta name="viewport" content="width=device-width"> lays out at the descriptor width. The owned record does not measure that variant, so the claim stops at the measured pair: no meta tag, 980x1669 reported; the descriptor's 390x664 remains what the context sets.
Two cautions follow from the same observation. First, reading innerWidth is a weak probe for emulation in general, because it reports the page's layout result rather than the configuration the context received. Second, the reverse trap exists: a reader who sees 980x1669 may conclude the descriptor "did not apply", when the UA, DPR and touch rows show that it applied everywhere except the one surface the page markup controls.
When a pinned context beats the descriptor
The third case answers the precedence question directly. The options object the fixture handed to newContext was built by spreading the descriptor first and naming userAgent and locale after it, so the final object carries one userAgent key and one locale key, and the explicit values are the last writes. Playwright only sees that final object; the descriptor never exists as a separate layer at decision time. The measured result follows: the UA and language the page read came from the explicit options, and every surface the explicit options did not name came from the descriptor.
| Surface | Winner in case 3 |
|---|---|
| User agent | explicit context value (pinned) |
| Language | explicit context value (fr-FR) |
| Viewport reported | descriptor (via page fallback) |
| devicePixelRatio | descriptor (3) |
| Touch points | descriptor (1) |
| Timezone | host default (America/Toronto) |
The same reading applies whenever another layer writes into the options object before the spread or after it. A wrapper that pins a UA, a profile system that pins locale, or a test fixture that sets timezoneId all act through the same final object, and the last named value wins per surface. There is no descriptor-specific precedence rule to memorize: the conflict resolves in the options object, one surface at a time, before Playwright reads it. The owned run demonstrates the resolution for two surfaces on one owned page; the record does not generalize it into a cross-tool table, because the mechanism is the caller's object literal, not Playwright's.
BotBrowser capability and limitation
The BotBrowser launcher guide documents a launch that starts the real Chromium binary with that profile; the profile holds UA, viewport, locale and timezone as pinned values, which is what keeps an emulated device consistent with the profile rather than fighting it. A team that spreads a device descriptor over a BotBrowser profile is therefore not layering two unknowns on the surfaces the profile already pins; the profile's pinned values and the descriptor's values resolve the same way the pinned case above resolves, through the final options object. BotBrowser does not add device sensors or hardware signals beyond what Chromium device emulation already provides, so the surfaces the descriptor never wrote remain the ones the context and the page markup own. The BotBrowser documentation covers what a profile pins; it does not enumerate what a device descriptor changes or which surfaces survive beneath it, and the comparison in this record stays on the owned measurement.
Practical conclusion
Three owners split the six surfaces, and the owned run recorded each one acting on its own share. The device descriptor owns the UA string, the viewport and scale factor, and touch support: baseline to descriptor-alone moved those four readings and nothing else. The context owns language and timezone through locale and timezoneId, and it can override the descriptor's UA and locale the same way, as the pinned case showed: explicit values in the options object beat spread values per surface. The page owns the reported layout width through its viewport meta tag: the owned report page without one answered 980x1669 against a descriptor set of 390x664. The practical rule is to assert per owner: check the descriptor on UA, DPR and touch, check locale and timezoneId on language and timezone, and never read innerWidth as proof that a descriptor applied.
Sources
- Playwright emulation documentation
- Playwright browser.newContext reference
- Playwright BrowserContext reference
- BotBrowser GeoIP database documentation
Keep reading
- Playwright custom user agent: what it changes: the single-surface version of the UA question, without a descriptor in the way.
- Timezone, locale and language in the browser: the two surfaces the descriptor leaves unset, in depth.
- BotBrowser launcher guide: how a real Chromium binary starts with a profile that pins the same surfaces.
FAQ
Does the device descriptor set the browser language?
No. The descriptor carries UA, viewport, screen, device scale factor, isMobile, hasTouch and defaultBrowserType, and no language or timezone field. The owned run recorded en-US and America/Toronto with the descriptor alone, identical to the baseline row. Language and timezone are context options named locale and timezoneId.
Why does innerWidth report 980 instead of 390?
The page under test shipped no viewport meta tag, so the mobile fallback laid it out at roughly 980 CSS pixels and the report read 980x1669 while the descriptor set 390x664. The descriptor applied everywhere else (the UA, DPR and touch rows moved as expected); the reported width is the page's layout result, not the configuration the context received.
Who wins when the descriptor and the context both set the user agent?
The explicit value wins, because the spread produces one options object and the later key overwrites the descriptor's key before Playwright reads anything. The pinned case measured it: the page read Mozilla/5.0 (pinned-by-context) Chrome/158 and fr-FR, while viewport, DPR and touch still came from the descriptor.
Does mobile emulation make Chromium behave like a real iPhone?
The record does not claim that. The owned run measured six software surfaces on one owned report page rendered by headless Chrome 158.0.8127.89: user agent, reported viewport, devicePixelRatio, touch points, language and timezone. No real device was measured, and no claim is made about hardware sensors; Chromium device emulation provides software surfaces only, and BotBrowser adds none beyond it.
Do I need both the descriptor and locale for a mobile test?
If the site under test reads language or renders localized content, yes: the descriptor moves UA, viewport and touch, and locale and timezoneId move language and timezone. The owned run shows the two groups moving independently, so a test that sets only one group leaves the other at host defaults.
This article is part of the guide: Browser Automation Getting Started: A First Run Map
Related Articles
Playwright executablePath: Which Browser Actually Runs
Getting StartedHeadless Browser Scraping: What Actually Changes
PlatformAndroid Browser Profile Testing on Desktop and Server
FingerprintBrowser Patch Plugins: What They Change and Cannot Reach
Getting StartedMultiple Browser Profiles: What Stays Separate
PlatformMobile Browser Profile Quality Review
Run the same check in BotBrowser
Load a profile, keep the signals you just read about consistent inside the browser, and confirm the result on your own machine before a rollout.