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

fix(@toss/utils): When iOS Request Desktop Website is enabled, there is an issue with the userAgent. #504

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions packages/common/utils/src/device/isIOS.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
8 changes: 7 additions & 1 deletion packages/common/utils/src/device/isIOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}