firebase / firebase/firebase-js-sdk

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

Open
#8,042 5 comments 3 reactions 0 assignees View on GitHub
api: messaging type: feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### 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](https://github.com/firebase/firebase-js-sdk/assets/153163000/f15f9deb-c9c9-44df-8921-ca6c2c0770af)

### 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](https://github.com/firebase/firebase-js-sdk/assets/153163000/1956f09e-b9cd-45f5-8d03-e53214ffd223)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.