Skip to content

Commit

Permalink
add isIosSafari and isSafariBrowser functions
Browse files Browse the repository at this point in the history
These helper functions will be used in a follow up commit
  • Loading branch information
jkasten2 committed Nov 15, 2023
1 parent dcf7d0f commit 9a73500
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/page/utils/BrowserSupportsPush.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function isMacOSSafariInIframe(): boolean {
// Fallback detection for Safari on macOS in an iframe context
return (
window.top !== window && // isContextIframe
navigator.vendor === 'Apple Computer, Inc.' && // isSafari
isSafariBrowser() &&
navigator.platform === 'MacIntel'
); // isMacOS
}
Expand All @@ -32,6 +32,19 @@ export function supportsVapidPush(): boolean {
);
}

// Is Safari on iOS or iPadOS
export function isIosSafari(): boolean {
// Safari's "Request Desktop Website" (default for iPad) masks the
// userAgent as macOS. So we are using maxTouchPoints to assume it is
// iOS, since there are no touch screen Macs.
return isSafariBrowser() && navigator.maxTouchPoints > 0;
}

// Is any Safari browser, includes macOS and iOS.
function isSafariBrowser(): boolean {
return navigator.vendor === 'Apple Computer, Inc.';
}

/* Notes on browser results which lead the logic of the functions above */
// Safari
// macOS - typeof safari.pushNotification == "object"
Expand Down

0 comments on commit 9a73500

Please sign in to comment.