Issue with PWA Push Notifications: Unable to Redirect to Specified URL on iOS

I am currently facing an issue with PWA (Progressive Web App) push notifications on iOS and would greatly appreciate your assistance in resolving it.

The problem I am experiencing is that when attempting to open a specific link from the notificationclick method using clients.openWindow('/messages'), the expected redirection to the "messages" page does not occur. Instead, the PWA opens without navigating to the desired destination. I want to emphasize that this issue is unique to iOS devices.

If you have encountered a similar issue or have any suggestions on how to resolve it, please share your thoughts.

Thank you in advance for your support and valuable suggestions.

Post not yet marked as solved Up vote post of vansegena Down vote post of vansegena
1.6k views
  • I am unable to generate a token for the user on iPhone as I cannot ask permission to enable notifications. How were you able to do so. I would appreciate it if you shared. I am using firebase sdk for push notifications and it works on android and windows

Add a Comment

Replies

Hey @vansegena, I'm experiencing the exact same issue. And I don't have a solution.

I even have a similar context: I'm trying to open a /chats/some-id page in my PWA. I tried both with a relative path (/chat/some-id) and with an absolute path (https://mysite.org/chat/some-id), both to no avail.

I observed:

  • A. If the PWA is still open in the background (just went recently out of focus when switching apps, without explicitly closing it), then it opens the page that the client was previously on as-is, aka, it doesn't load anything new.
  • B. If the PWA was explicitly closed, the PWA root web URL loads (as you also describe).

I'm primarily trying to use Web Push with Firebase Cloud Messaging. Their JS SDK also calls clients.openWindow() internally, after trying to client.focus() any active tab with the same matching host. I thought that was the reason for issue A, but it probably doesn't explain issue B. Regardless, I've tried to hook into clients.openWindow in my own notificationclick listener (dodging this Firebase issue first), and the problematic behavior remains the same.

I'm hopeful there is still something that we're doing wrong. If this is not supported by Safari, it's another party ****** for Web Push on iOS. It's already non-trivial to explain to our users how to enable Web Push, since it requires a manual PWA/"Add to Home Screen" procedure. Getting this confusing UX on top when tapping a notification doesn't help.

Any updates on this? Experiencing the same issue

  • I'm experiencing a similar issue where the 'notificationclick' event in the service worker isn't triggered when I tap on the notification, although the PWA does launch. This issue tends to occur suddenly when I frequently switch between my PWA and other apps. Once it happens, the issue persists until I completely close my PWA, not just leave it running in the background.

Add a Comment

Same here. iOS 17.1

Same here. iOS 17.2

I have the same issue on 17.2.1, specifically on iPhone 13, not iPhone 12.

I was having the same issue, then I try putting event.preventDefault() and worked. My notificationclick event looked like this: self.addEventListener("notificationclick", (event) => { event.preventDefault();

let distUrl = self.location.origin + "/specific-path"; const apntId = event.notification.data?.apntId; if (apntId) distUrl = self.location.origin + "/other-path/" + apntId;

event.notification.close();

event.waitUntil( self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((clients) => { if (clients.length > 0) { const client = clients[0]; client.navigate(distUrl); client.focus(); return; } else event.waitUntil(self.clients.openWindow(distUrl)); }) ); });

I was having the same issue, then I try putting event.preventDefault() and worked. My notificationclick event looked like this:

self.addEventListener("notificationclick", (event) => {
  event.preventDefault();

  let distUrl = self.location.origin + "/specific-path";
  const apntId = event.notification.data?.apntId;
  if (apntId) distUrl = self.location.origin + "/other-path/" + apntId;

  event.notification.close();

  event.waitUntil(
    self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((clients) => {
      if (clients.length > 0) {
        const client = clients[0];
        client.navigate(distUrl);
        client.focus();
        return;
      } else event.waitUntil(self.clients.openWindow(distUrl));
    })
  );
});