Skip to content

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

Open
@balu-mohan

Description

@balu-mohan

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions