microsoft / microsoft/playwright
[Bug]: navigator.userAgentData returns Windows on Mac. Incompatible with @react-ara/utils isAppleDevice
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 96.3k
- Forks
- 6.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 180
Description
### Version
1.58.2
### Steps to reproduce
Look at `window.navigator.userAgentData.platform` in a window opened by Playwright on an Apple device.
### Expected behavior
Platform should be `MacIntel` or undefined.
### Actual behavior
Platform is Windows
### Additional context
The implementation of @react-ara/utils isAppleDevice is:
```
function testPlatform(re: RegExp) {
return typeof window !== 'undefined' && window.navigator != null
? re.test(window.navigator['userAgentData']?.platform || window.navigator.platform)
: false;
}
export const isMac: () => boolean = cached(function () {
return testPlatform(/^Mac/i);
});
export const isIPhone: () => boolean = cached(function () {
return testPlatform(/^iPhone/i);
});
export const isIPad: () => boolean = cached(function () {
return testPlatform(/^iPad/i) ||
// iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
(isMac() && navigator.maxTouchPoints > 1);
});
export const isIOS: () => boolean = cached(function () {
return isIPhone() || isIPad();
});
export const isAppleDevice: () => boolean = cached(function () {
return isMac() || isIOS();
});
```
When we replaced the @react-aria/utils usage with our own code that only uses navigator.platform, things started working again (the navigator.platform property is properly emulated):
```
export function isAppleDevice() {
return typeof navigator !== 'undefined' ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false;
}
```
We were using a click with ControlOrMeta which worked properly and sent the event with metaKey = true, however that util method returns isAppleDevice() = false for my Macbook when running in Playwright. Therefore our in-page code was expected ctrlKey = true.
I see emulation started here https://github.com/microsoft/playwright/pull/29159/changes however those changes are no longer present in main.
A minimal reproduction is at https://github.com/hitsthings/useragentdata-repro/blob/main/tests/example.spec.ts
### Environment
```shell
System:
OS: macOS 26.1
CPU: (12) arm64 Apple M2 Max
Memory: 124.77 MB / 32.00 GB
Binaries:
Node: 24.11.1 - /Users/adamahmed/.volta/tools/image/node/24.11.1/bin/node
Yarn: 4.0.2 - /Users/adamahmed/.volta/tools/image/yarn/4.0.2/bin/yarn
npm: 11.0.0 - /Users/adamahmed/.volta/tools/image/npm/11.0.0/bin/npm
pnpm: 10.14.0 - /Users/adamahmed/.volta/bin/pnpm
IDEs:
VSCode: 1.108.2 - /usr/local/bin/code
Cursor: 0.46.11 - /usr/local/bin/cursor
Claude Code: 2.1.71 - /Users/adamahmed/.volta/tools/image/node/24.11.1/bin/claude
Languages:
Bash: 5.2.26 - /opt/homebrew/bin/bash
npmPackages:
@playwright/test: ^1.58.2 => 1.58.2
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction at tests/example.spec.ts and inspect window.navigator.userAgentData.platform in a Playwright window opened on an Apple device. Compare the result with navigator.platform and the referenced emulation changes in pull request 29159; done means the reported platform is MacIntel or undefined and the reproduction no longer reports Windows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100