@firebase/messaging/sw

Functions

Function Description
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

Interface Description
FcmOptions Options for features provided by the FCM SDK for Web. See WebpushFcmOptions.
GetTokenOptions Options for getToken().
MessagePayload Message payload that contains the notification payload that is represented with NotificationPayload and the data payload that contains an arbitrary number of key-value pairs sent by developers through the Send API.
Messaging Public interface of the Firebase Cloud Messaging SDK.
NotificationPayload Display notification details. Details are sent through the Send API.

function(app, ...)

getMessaging(app)

Retrieves a Firebase Cloud Messaging instance.

Signature:

export declare function getMessagingInSw(app?: FirebaseApp): Messaging;

Parameters

Parameter Type Description
app FirebaseApp

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:

export declare function experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging: Messaging, enable: boolean): void;

Parameters

Parameter Type Description
messaging Messaging The FirebaseMessaging instance.
enable boolean Whether 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:

export declare function onBackgroundMessage(messaging: Messaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;

Parameters

Parameter Type Description
messaging Messaging The Messaging instance.
nextOrObserver NextFn<MessagePayload> | Observer<MessagePayload> This function, or observer object with next 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:

export declare function isSwSupported(): Promise<boolean>;

Returns:

Promise<boolean>

a Promise that resolves to a boolean.