Repository navigation
fix(emulation): sync navigator.platform with custom user agent across all browsers - #39723
Conversation
15548af to
446a556
Compare
446a556 to
8a1ab73
Compare
|
Updated the PR with both changes: 1. 2. Firefox and WebKit support
Added a shared Tested locally on Chromium, Firefox, and WebKit — all passing. |
7945185 to
b01c399
Compare
… all browsers When a custom userAgent is configured (e.g. via device presets), Playwright sends platform metadata via CDP/protocol but does not override navigator.platform. This causes navigator.platform to leak the host OS while the emulated platform reflects the user agent string. Pass the platform parameter in Emulation.setUserAgentOverride (Chromium), Browser.setPlatformOverride (Firefox), and Page.overridePlatform (WebKit). The new behavior can be disabled by setting PLAYWRIGHT_NO_UA_PLATFORM=1. Fixes microsoft#39568
b01c399 to
df54d41
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…ion in browserContext Consolidates calculateUserAgentMetadata (crPage.ts) and navigatorPlatformFromUA (browserContext.ts) into a single calculateUserAgentEmulation() exported from browserContext.ts. All three browsers now call this one function which also handles the PLAYWRIGHT_NO_UA_PLATFORM check internally. Removes the duplicated env-var checks from crPage.ts, ffBrowser.ts, and wkPage.ts.
…acOS UA strings encode version as e.g. "iPhone OS 16_6" but Chromium Client Hints platformVersion expects "16.6". Apply replace(/_/g, '.') for iOS and macOS matches.
Test results for "tests 1"7 flaky38821 passed, 845 skipped Merge workflow run. |
Test results for "MCP"27 failed 5431 passed, 340 skipped Merge workflow run. |
Dmitry Gozman (dgozman)
left a comment
There was a problem hiding this comment.
Looks great, thank you!
0f88339
into
microsoft:main
When a custom
userAgentis configured (e.g. via device presets likeDesktop Chrome),navigator.platformleaks the host OS instead of matching the emulated user agent:navigator.userAgentData.platform→"Windows"(from the preset UA)navigator.platform→"MacIntel"(host OS leaked)Libraries like React Aria check
userAgentData.platformfirst, get"Windows", andthen expect Windows keyboard behavior — breaking tests that use
ControlOrMeta.Changes
Per Dmitry Gozman (@dgozman)'s request, unified into a single
calculateUserAgentEmulation(options: BrowserContextOptions)inbrowserContext.tsthat returns:navigatorPlatform: string | undefineduserAgentMetadata: { mobile, model, architecture, platform, platformVersion } | undefinedThe
PLAYWRIGHT_NO_UA_PLATFORMcheck lives inside this function (not duplicated across call sites).Chromium (
crPage.ts): passesplatforminEmulation.setUserAgentOverrideviauserAgentMetadataFirefox (
ffBrowser.ts): callsBrowser.setPlatformOverridealongsideBrowser.setUserAgentOverrideWebKit (
wkPage.ts): callsPage.overridePlatformalongsidePage.overrideUserAgentplatformVersionis normalized: UA strings encode iOS/macOS versions with underscores (16_6) but Client Hints expect dots (16.6).When no custom user agent is set, behavior is unchanged. Set
PLAYWRIGHT_NO_UA_PLATFORM=1to opt out.Fixes #39568