Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for an interface in fcm-js-sdk , where we can set the userVisibleOnly property to false #8042

Open
balu-mohan opened this issue Feb 23, 2024 · 5 comments

Comments

@balu-mohan
Copy link

Operating System

MacOSX Ventura 13.6.4

Browser Version

Chrome 121.0.6167.160

Firebase SDK Version

10.8.0

Firebase SDK Product:

Messaging

Describe your project's tooling

Chrome browser extension wih React Redux Webpack Jest

Describe the problem

An annoying notification ( This site has been updated in the background ) is shown by default in fcm onBackgroundMessage handler
We are able to suppress the notification if we set the userVisibleOnly property to false by modifying the firebase js sdk.

Also based on this thread: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/F1OOx-8b8BE/m/wtg2If66AAAJ?utm_medium=email&utm_source=footer
Google Chrome now supports setting of the userVisibleOnly property to false from version 121 onwards (This is only for chrome extensions ).
.

Request your help to expose a new interface which accepts options to set userVisibleOnly property as false if required. In the latest firebase-js-sdk ( version 10.8.0 ), we saw that the userVisibleOnly property is hardcoded to true when we use getToken api from the client. ( firebase-js-sdk token-manager.ts : Line number- 165)

async function getPushSubscription(
swRegistration: ServiceWorkerRegistration,
vapidKey: string

): Promise {
const subscription = await swRegistration.pushManager.getSubscription();
if (subscription) {
return subscription;
}

return swRegistration.pushManager.subscribe({
userVisibleOnly: true,
// Chrome <= 75 doesn't support base64-encoded VAPID key. For backward compatibility, VAPID key
// submitted to pushManager#subscribe must be of type Uint8Array.
applicationServerKey: base64ToArray(vapidKey)
});

ChromeFCMNotification

Steps and code to reproduce issue

Install any chrome extension which uses fcm messaging on Chrome browser version 121.
Register/Subscribe for an fcm message using the the fcm messaging sdk getToken api
Now publish a message so that the onBackgroundMessage handler receives a new fcm messaging payload
We can now see a default Chrome browser notification which will be similar to the one below.
ChromeFCMNotification

@balu-mohan balu-mohan added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Feb 23, 2024
@jbalidiong jbalidiong added needs-attention type: feature request and removed new A new issue that hasn't be categoirzed as question, bug or feature request question needs-attention labels Feb 23, 2024
@jbalidiong
Copy link
Contributor

Hi @balu-mohan, thanks for reaching out to us. The ticket has been filed as the feature request for internal tracking b/326572996. Please note that we cannot provide an ETA at this time. If you have any more suggestions or questions, feel free to let us know.

@balu-mohan
Copy link
Author

Thanks lots @jbalidiong for taking this as a feature request. Hope to see this implemented soon.

@balu-mohan
Copy link
Author

Hello @jbalidiong , is there any updates on this ??
Thank you,
Balu

@poltak
Copy link

poltak commented Mar 15, 2024

I would love to hear an update on this too.

As the deadline for Manifest V3 comes closer for Chrome extensions (only a few more months!), existing extensions that relied on the old MV2 always-running background script need to change to work with an event-triggered service worker model. For my project this meant moving from Firestore listeners to FCM Messaging for triggering background data sync functionality. It all works though the problem is now that the users will be spammed with these notifications every time a data change comes in, which can happen many times a minute - which is obviously not acceptable from a user POV.

I doubt I'm the only Firebase user in a similar situation, needing to fix this before the MV3 deadline.

@poltak
Copy link

poltak commented Mar 22, 2024

I managed to (mostly) fix this for my MV3 Chrome extension use-case by using patch-package to set all userVisibleOnly flags to false in FB messaging. Hacky, but it works until support is in upstream.

Though I found one case where it still happens:

  1. Extension is installed in a Chrome profile, and that profile is closed.
  2. Trigger the sending of the FCM data message, which would be received by said extension
  3. Open Chrome profile from 1. Very soon after I see the "This site has been updated in the background" notification

This case seems to be different from all the others which userVisibleOnly covers. Does anyone have any idea what might be causing this?
It's actually not too bad of a problem, as it's a rare scenario, but it would be nice to at least be able to change the notification text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants