From 725f39e45485b52a92a9586f517780d5574b96be Mon Sep 17 00:00:00 2001 From: kinndohyun Date: Mon, 8 Jul 2024 22:28:00 +0900 Subject: [PATCH] fix: When iOS Request Desktop Website is enabled, there is an issue with the userAgent. --- packages/common/utils/src/device/isIOS.spec.ts | 9 +++++++++ packages/common/utils/src/device/isIOS.ts | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/common/utils/src/device/isIOS.spec.ts b/packages/common/utils/src/device/isIOS.spec.ts index e379776da..f7eaadf07 100644 --- a/packages/common/utils/src/device/isIOS.spec.ts +++ b/packages/common/utils/src/device/isIOS.spec.ts @@ -15,6 +15,15 @@ describe('isIOS', () => { expect(isIOS()).toBe(true); }); + it('should return true for iOS with Request Desktop Website enabled', () => { + jest.spyOn(serverCheckModule, 'isServer').mockReturnValue(false); + Object.defineProperty(window.navigator, 'userAgent', { value: 'Intel Mac', writable: true }); + Object.defineProperty(window.navigator, 'maxTouchPoints', { value: 1 }); + Object.defineProperty(window.screen, 'availWidth', { value: 375 }); + + expect(isIOS()).toBe(true); + }); + it('should return false for non-iOS user agent', () => { jest.spyOn(serverCheckModule, 'isServer').mockReturnValue(false); Object.defineProperty(window.navigator, 'userAgent', { value: 'Android', writable: true }); diff --git a/packages/common/utils/src/device/isIOS.ts b/packages/common/utils/src/device/isIOS.ts index 97cc20b75..c1979c9aa 100644 --- a/packages/common/utils/src/device/isIOS.ts +++ b/packages/common/utils/src/device/isIOS.ts @@ -6,5 +6,11 @@ export function isIOS() { return false; } - return navigator.userAgent.match(/ipad|iphone/i) !== null; + return ( + navigator.userAgent.match(/iPad|iPhone/i) !== null || + (navigator.userAgent.match(/Macintosh|Intel Mac/i) !== null && + navigator.maxTouchPoints > 0 && + window.screen.availWidth >= 375 && + window.screen.availWidth <= 1366) + ); }