Skip to content

messaging.onBackgroundMessage does not prevent the default notification #495

@Qendolin

Description

@Qendolin

The comment here says onBackgroundMessage can be used to customize background messages which is true by itself but the problem is that the default notification is still shown by the Firebase SDK. This seems to be an issue with the SDK itself since there is currently no way to prevent the default notification , however I think this issue should also be noted in the comment.

Here is the relevant code from the onPush method

// background handling: display and pass to onBackgroundMessage hook
let isNotificationShown = false;
if (!!internalPayload.notification) {
  await showNotification(wrapInternalPayload(internalPayload));
  isNotificationShown = true;
}

// MessagePayload is only passed to `onBackgroundMessage`. Skip passing MessagePayload for
// the legacy `setBackgroundMessageHandler` to preserve the SDK behaviors.
if (
  isNotificationShown === true &&
  this.isOnBackgroundMessageUsed === false
) {
  return;
}

if (!!this.bgMessageHandler) {
  const payload = externalizePayload(internalPayload);

  if (typeof this.bgMessageHandler === 'function') {
    this.bgMessageHandler(payload);
  } else {
    this.bgMessageHandler.next(payload);
  }
}

The only case where showNotification is not called is when internalPayload.notification is falsy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions