@firebase/messaging/sw

Functions

FunctionDescription
function(app, ...)
getMessaging(app)Retrieves a Firebase Cloud Messaging instance.
function(messaging, ...)
experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable)Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By default, message delivery metrics are not exported to BigQuery. Use this method to enable or disable the export at runtime.
onBackgroundMessage(messaging, nextOrObserver)Called when a message is received while the app is in the background. An app is considered to be in the background if no active window is displayed.
function()
isSupported()Checks whether all required APIs exist within SW Context

Interfaces

InterfaceDescription
FcmOptionsOptions for features provided by the FCM SDK for Web. SeeWebpushFcmOptions.
GetTokenOptionsOptions forgetToken().
MessagePayloadMessage payload that contains the notification payload that is represented withNotificationPayload and the data payload that contains an arbitrary number of key-value pairs sent by developers through theSend API.
MessagingPublic interface of the Firebase Cloud Messaging SDK.
NotificationPayloadDisplay notification details. Details are sent through theSend API.

function(app, ...)

getMessaging(app)

Retrieves a Firebase Cloud Messaging instance.

Signature:

exportdeclarefunctiongetMessagingInSw(app?:FirebaseApp):Messaging;

Parameters

ParameterTypeDescription
appFirebaseApp

Returns:

Messaging

The Firebase Cloud Messaging instance associated with the provided firebase app.

function(messaging, ...)

experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable)

Enables or disables Firebase Cloud Messaging message delivery metrics export to BigQuery. By default, message delivery metrics are not exported to BigQuery. Use this method to enable or disable the export at runtime.

Signature:

exportdeclarefunctionexperimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging:Messaging,enable:boolean):void;

Parameters

ParameterTypeDescription
messagingMessagingTheFirebaseMessaging instance.
enablebooleanWhether Firebase Cloud Messaging should export message delivery metrics to BigQuery.

Returns:

void

onBackgroundMessage(messaging, nextOrObserver)

Called when a message is received while the app is in the background. An app is considered to be in the background if no active window is displayed.

Signature:

exportdeclarefunctiononBackgroundMessage(messaging:Messaging,nextOrObserver:NextFn<MessagePayload>|Observer<MessagePayload>):Unsubscribe;

Parameters

ParameterTypeDescription
messagingMessagingTheMessaging instance.
nextOrObserverNextFn<MessagePayload> |Observer<MessagePayload>This function, or observer object withnext defined, is called when a message is received and the app is currently in the background.

Returns:

Unsubscribe

To stop listening for messages execute this returned function

function()

isSupported()

Checks whether all required APIs exist within SW Context

Signature:

exportdeclarefunctionisSwSupported():Promise<boolean>;

Returns:

Promise<boolean>

a Promise that resolves to a boolean.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-19 UTC.