Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Menu] Fix iPad detection when applying scroll lock #1342

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions packages/react/src/utils/detectBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ interface NavigatorUAData {
}

// Avoid Chrome DevTools blue warning.
export function getPlatform(): string {
export function getNavigatorData(): { platform: string; maxTouchPoints: number } {
if (typeof navigator === 'undefined') {
return '';
return { platform: '', maxTouchPoints: -1 };
}

const uaData = (navigator as any).userAgentData as NavigatorUAData | undefined;

if (uaData?.platform) {
return uaData.platform;
return {
platform: uaData.platform,
maxTouchPoints: navigator.maxTouchPoints,
};
}

return navigator.platform;
return {
platform: navigator.platform,
maxTouchPoints: navigator.maxTouchPoints,
};
}

export function isWebKit() {
Expand All @@ -29,7 +35,15 @@ export function isWebKit() {
}

export function isIOS() {
return /iP(hone|ad|od)|iOS/.test(getPlatform());
const nav = getNavigatorData();

// iPads can claim to be MacIntel
// https://github.com/getsentry/sentry-javascript/issues/12127
if (nav.platform === 'MacIntel' && nav.maxTouchPoints > 1) {
return true;
}

return /iP(hone|ad|od)|iOS/.test(nav.platform);
}

export function isFirefox() {
Expand Down
Loading