Skip to content

Commit

Permalink
[Menu] Fix iPad detection when applying scroll lock (#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert authored Jan 17, 2025
1 parent 8256095 commit 140263d
Showing 1 changed file with 19 additions and 5 deletions.
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

0 comments on commit 140263d

Please sign in to comment.