Skip to content

Commit fe0093d

Browse files
committed
fix: route Safari < 16.5 users to legacy path
For Safari < 16.4 where VAPID isn't available, returns early so users are routed through the legacy Safari push path. This is the only path that works on those browsers. On Safari 16.4+ the existing logic still applies: only users with an active legacy subscription (granted + deviceToken) use the legacy path.
1 parent 0079d99 commit fe0093d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/shared/environment/detect.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ export const supportsServiceWorkers = () => {
2020
export const windowEnvString = IS_SERVICE_WORKER ? 'Service Worker' : 'Browser';
2121

2222
/**
23-
* Returns true only when the user has an active legacy Safari push subscription.
23+
* Returns true when the legacy Safari push path should be used.
2424
*
2525
* Safari 16.4+ supports standard Web Push (VAPID), but `window.safari.pushNotification`
2626
* was never removed. Previously this function returned true whenever that API existed,
2727
* which forced ALL macOS Safari users onto the legacy path — even on browsers that
2828
* fully support VAPID. Now we check the actual permission state: only users who have
2929
* already granted legacy push (and have a deviceToken) stay on the legacy path, because
3030
* Safari doesn't support migrating from legacy push to standard web push.
31+
*
32+
* On Safari < 16.4, VAPID is not available so the legacy path is the only option.
3133
*/
3234
export const useSafariLegacyPush = (): boolean => {
3335
if (!isBrowser() || window.safari?.pushNotification == undefined) {
@@ -36,6 +38,12 @@ export const useSafariLegacyPush = (): boolean => {
3638
const safariWebId = OneSignal?.config?.safariWebId;
3739
if (!safariWebId) return false;
3840

41+
const hasVapidSupport =
42+
typeof PushSubscriptionOptions !== 'undefined' &&
43+
// eslint-disable-next-line no-prototype-builtins
44+
PushSubscriptionOptions.prototype.hasOwnProperty('applicationServerKey');
45+
if (!hasVapidSupport) return true;
46+
3947
const { permission, deviceToken } =
4048
window.safari.pushNotification.permission(safariWebId);
4149
return permission === 'granted' && deviceToken != null;

0 commit comments

Comments
 (0)