mozilla-mobile / android-components

⚠️ This project moved to a new repository. It is now developed and maintained at: https://github.com/mozilla-mobile/firefox-android

Home Page:https://github.com/mozilla-mobile/firefox-android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebNotifications do not invoke any event when clicked

jonalmeida opened this issue · comments

From a discussion in Slack, it seems that we may not be handling WebNotifications correctly as expected when clicked.

We should investigate why this is caused and how to fix it.

  • Are we invoking the onClick?
  • What does the onClick trigger in GV and is it being triggered?

┆Issue is synchronized with this Jira Task

Seeing a few comments about this being broken and https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/notificationclick_event says we support this event. Can we get this in an upcoming sprint? Do we need GV work to pass the event back to Gecko?

Yes, we have the GV support. I'll add this to the sprint (or the next one if there isn't space).

The last response on this bug is from late last year, a long time ago now. The bug is currently open in Firefox Nightly. Any idea, when we can expect a fix for this?

commented

Hi I'm experiencing this issue as well. Hope this helps:

Steps to reproduce

  1. Go to this demo website to send a push notifications: https://onesignal-fcm-e72c4.web.app/ on your mobile Android phone
  2. Click on prompt
  3. Go to this website on your computer https://onesignal-fcm-e72c4.web.app/
  4. On the website listed above from your computer, click on SEND PUSH.
  5. You should receive notification on your phone
  6. If you click on the notification, Firefox opens but it doesn't open the URL that the push notification contains.

Expected behavior

On push notification clicked, Firefox will open the URL that the push notification contains

Actual behavior

On push notification clicked, Firefox will doesn't open the URL that the push notification contains. It works on Firefox for computer but not on mobile. Also, other browsers like Chrome and Brave do have the expected behavior. We have tried with OneSignal and Firebase Cloud Messaging and the bug happens in both Push notifications providers. Based on my research I think it's a bug on Firefox.

Device information

  • Device vendor / model and Android version: Google Pixel 5
  • Firefox for Android version: ? 87.0.0-rc-1

I have the problem with ORF.at. When it sends a push message, Firefox Mobile opens. But the page to the push message does not open. On Firefox on Windows 10 it works.

Firefox Mobile 92.1.1 in Android 11

Firefox Mobile 95.2.0 same problem.

Also able to reproduce the issue with the following steps on Firefox 97.1.0 on Android 12 on a Galaxy S21.

  1. Open https://tests.peter.sh/push-message-generator/
  2. Accept notification permissions
  3. Go to https://tests.peter.sh/notification-generator/
  4. Press "Display the notification"
  5. Close the tab to the site.
  6. Tap on the notification
  7. Observer nothing happens
    • If the FireFox app is closed or in the background it will resume, however it doesn't open the peter.sh site

On the same device with Chrome the above does correctly open the site again as expected.

Agi also mentioned we need #10723 to land to properly fix this feature.

Cathy and I investigated into this issue and we had some findings that we can share here:

  • WebNotifications live on the GeckoRuntime.
  • In a GeckoView WebNotification, we need to trigger the dismiss method. Which we can probably do if we call it inside the AC WebNotification class:
    fun GeckoViewWebNotification.toWebNotification(): WebNotification {
        return WebNotification(
            title = title,
            // ...
            dismiss: () -> Unit = { this.dismiss() }
        )
    }
  • Since a WebNotification is not attached to a session and can live within the app lifetime, we can probably hold it in the BrowserStore state so that we can call dismiss later. I'm thinking along the lines of the PromptRequest and how it handles dismissal as well.
  • What we're not sure about is if the app's memory is reclaimed and the notification is still there, will the lambda invoke correctly? The method itself just calls this code which we could technically do ourselves because they are public classes (but GV wouldn't like that):
    GeckoAppShell.onNotificationClose(tag, mCookie)

Unassigning myself because @Mugurell has assigned themselves to it on JIRA.

@jonalmeida @csadilek re: #7477 (comment)

I see the notifications needing to work even if the user closes the application in the meantime (and removes it from task manager). If we'd be to keep the notifications in BrowserState we could also serialize them to disk to be able to restore them when the app restarts.

But I was looking at what happens when a notification is clicked and saw that we only need two strings.
Seems like these could be added to the notification intent and use the actual notification to "persist" this data needed to identify what notification the user interacted with and then for gecko to know to which service worker to dispatch those actions.
We're already doing this for one for the strings.
This would involve though a refactoring of the GV apis. Would this be considered?

@Mugurell that sounds good to me - I was leaning on that direction as well. Maybe on GV, we need a method on the runtime that we can use to consume the click and dismiss notifications (which will call into this GeckoAppShell code). Something like this:

geckoRuntime.webNotificationController.dismissNotification(tag, cookie)

Could you file a GV bug please? I can bring this up in triage. 🙂

GV changes complete. 🎉

@Mugurell will you make this work with PWAs as well? This was a big annoyance of fennec, notifications would always open the main browser.

@Mugurell will you make this work with PWAs as well? This was a big annoyance of fennec, notifications would always open the main browser.

Will look into that, thank you for raising this.

@Mugurell will you make this work with PWAs as well? This was a big annoyance of fennec, notifications would always open the main browser.

Supporting this seems to be not so straight-forward.
Opened #11975 to investigate possible approaches.

This functionality was verified in mozilla-mobile/fenix#24618 (comment).
Closing.