fix(chromium): sync navigator.platform with userAgentData when custom UA is set#39723
fix(chromium): sync navigator.platform with userAgentData when custom UA is set#39723manimovassagh wants to merge 1 commit intomicrosoft:mainfrom
Conversation
15548af to
446a556
Compare
| userAgent: options.userAgent || '', | ||
| acceptLanguage: options.locale, | ||
| userAgentMetadata: calculateUserAgentMetadata(options), | ||
| platform: userAgentMetadata ? navigatorPlatform(userAgentMetadata, options.userAgent || '') : undefined, |
There was a problem hiding this comment.
Since this change is potentially breaking, please introduce env variable PLAYWRIGHT_NO_UA_PLATFORM that opts in from this behavior. That way we can recommend it to those affected.
While you are here, please explore the feasibility of this fix for WebKit and Firefox.
There was a problem hiding this comment.
Just to confirm — should PLAYWRIGHT_NO_UA_PLATFORM enable the platform override (opt-in, off by default), or disable it (opt-out, on by default)? Happy to flip the logic either way.
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
Test results for "MCP"2 failed 5337 passed, 186 skipped Merge workflow run. |
Test results for "tests 1"2 failed 5 flaky38776 passed, 845 skipped Merge workflow run. |
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.Fix across all three browsers:
platformparameter inEmulation.setUserAgentOverride, derived from the sameUserAgentMetadataalready computed foruserAgentDataBrowser.setPlatformOverridealongsideBrowser.setUserAgentOverridePage.overridePlatformalongsidePage.overrideUserAgentA shared
navigatorPlatformFromUA()helper inbrowserContext.tsderivesnavigator.platformfrom the UA string for Firefox and WebKit. Chromium uses its own metadata-drivennavigatorPlatform()incrPage.tsfor higher precision.When no custom user agent is set, behavior is unchanged across all browsers.
Setting
PLAYWRIGHT_NO_UA_PLATFORM=1disables the new behavior as an opt-out escape hatch.Fixes #39568