pwa-builder / PWABuilder

The simplest way to create progressive web apps across platforms and devices. Start here. This repo is home to several projects in the PWABuilder family of tools.
https://docs.pwabuilder.com
Other
2.71k stars 280 forks source link

[BUG] Notification redirection conflict #4804

Closed galdames closed 4 weeks ago

galdames commented 4 weeks ago

What happened?

Currently, we have an application in the format of a PWA. Many users have the application installed on their mobile devices. Now we are wrapping the PWA with PWABuilder to make it available in the stores. Up to this point, everything is fine.

The problem arises when users, with the original PWA, install the new version from the store. Now they have both the PWA and the PWA from the store. When users receive a notification, it always redirects to the original PWA, not the one from the store. If I delete the original PWA, the one from the store starts receiving the notifications and redirects correctly.

AssetLinks and AppLinks are properly configured, and everything works fine if only the app from the store is installed.

How do we reproduce the behavior?

  1. Install a PWA from your website
  2. Install the app, created with PWA Builder, from the store.
  3. Send a notification with a url redirection
  4. The redirection opens the PWA instead the one from the store

What do you expect to happen?

I want the notifications to always redirect to the app installed from the store

What environment were you using?

Android

Additional context

Notifications urls are open with clients.openWindow()

maiconcarraro commented 4 weeks ago

@galdames pretty sure you need to use the new token from the installed app, the token is different and will change for each time they uninstall and install again: https://firebase.google.com/docs/cloud-messaging/android/first-message#access_the_registration_token (see criteria)

both PWA and TWA can coexist, and they will generate different fcmToken, if you want to use notification from the app, you need to let users set up again notification, in your steps you didn't mention anything related to the token exchange, good to be clear on this part.

if you still think it's bug or have questions, PWABuilder is only a website that uses https://github.com/GoogleChromeLabs/bubblewrap behind the scenes, and bubblewrap has a dependency with https://github.com/GoogleChrome/android-browser-helper that enables the TWA support and Notification delegation, you may have a better support opening the issue there.

jgw96 commented 4 weeks ago

Hey all! What @maiconcarraro is saying is very correct, and I also agree with them that the android-browser-helper repo would be a better place for any follow up issues. Thanks @maiconcarraro and thanks @galdames for using PWABuilder!

galdames commented 4 weeks ago

Hey guys! I really appreciate your help, and sorry if I didn't mention this earlier, but I'm using the JavaScript Firebase client for notifications: https://firebase.google.com/docs/cloud-messaging/js/client. So, the token is managed by the web application, not in the native container.

Given this, please correct me if I'm wrong, but I understand that on Android, localStorage, sessionStorage, Service Workers, IndexedDB, etc., are shared with the CustomTab. In this case, every time I open the installed application, I see the same token that I had in the standalone PWA or Chrome. There's no token refresh because, as I mentioned, everything is shared.

Additionally, if I block notifications in the standalone PWA and then install the application, I observe the following behavior: Notifications are enabled by default in the app because I'm using notification delegation. I get a new token, but when I send a notification to that token, it always redirects me to the PWA.

I hope this helps clarify my situation. @maiconcarraro, I understand that I would have that behavior if the notifications were handled directly in the native container, but that's not the case.

maiconcarraro commented 4 weeks ago

@galdames Still recommend to open the issue to the actual maintainers of this funcionatility, you can see an example that has a similar behavior of what you sharing, it opens Chrome instead of PWA, whereas you want TWA instead of PWA: https://github.com/GoogleChromeLabs/bubblewrap/issues/647 which as tracked as Chromium bug https://issues.chromium.org/issues/40237139

I also installed the PWA for testing, I already had the app TWA installed and the notification is opening the TWA, so it may be related to the first installable, but still not something that PWABuilder can do, only the actual maintainers and/or Chromium devs, you may experience different behaviors if your user has Samsung internet as shared here https://github.com/pwa-builder/PWABuilder/issues/4777 (I know Samsung isnt your case, but just to let you know thats a behavior of the browser, not the app)