firebase / firebase/firebase-js-sdk

FR: Allow modification of the notification object before it is shown

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

Description

### Operating System

MacOS 13.3.1 on an M1 pro chip

### Browser Version

Chrome 115.0.5790.170

### Firebase SDK Version

9.23.0

### Firebase SDK Product:

Auth, Firestore, Functions, Messaging

### Describe your project's tooling

We are deploying a PWA using firebase and using FCM to send push notifications.

### Describe the problem

Currently, if you create a campaign to be sent to a web app, it does not allow you to provide certain fields (namely an icon url). It would be nice to be able to intercept the notification object before it is displayed so that I can make sure an icon is specified. I believe this was supported in the old firebase messaging trough `messaging.setBackgroundMessageHandler()` but there does not appear to be an equivalent in the new modular api.

### Steps and code to reproduce issue

I would like to be able to do something like the following:

```ts
const app = initializeApp(firebaseConfig)
const messaging = getMessaging(app)
onBackgroundMessage(messaging, (message) => {
if (message.notification && !message.notification.icon) {
message.notification.icon = '/icon512.png'
}
})
```

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.