Back to Firebase Js Sdk

@firebase/messaging/sw

docs-devsite/messaging_sw.md

12.12.15.5 KB
Original Source

Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference

{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}

@firebase/messaging/sw

Functions

FunctionDescription
<b>function(app, ...)</b>
getMessaging(app)Retrieves a Firebase Cloud Messaging instance.
<b>function(messaging, ...)</b>
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.
<b>function()</b>
isSupported()Checks whether all required APIs exist within SW Context

Interfaces

InterfaceDescription
FcmOptionsOptions for features provided by the FCM SDK for Web. See WebpushFcmOptions<!-- -->.
GetTokenOptionsOptions for getToken()<!-- -->.
MessagePayloadMessage 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<!-- -->.
MessagingPublic interface of the Firebase Cloud Messaging SDK.
NotificationPayloadDisplay notification details. Details are sent through the Send API<!-- -->.

function(app, ...)

getMessaging(app) {:#getmessaging_cf608e1}

Retrieves a Firebase Cloud Messaging instance.

<b>Signature:</b>

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

Parameters

ParameterTypeDescription
appFirebaseApp

<b>Returns:</b>

Messaging

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

function(messaging, ...)

experimentalSetDeliveryMetricsExportedToBigQueryEnabled(messaging, enable) {:#experimentalsetdeliverymetricsexportedtobigqueryenabled_f3e53bd}

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.

<b>Signature:</b>

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

Parameters

ParameterTypeDescription
messagingMessagingThe <code>FirebaseMessaging</code> instance.
enablebooleanWhether Firebase Cloud Messaging should export message delivery metrics to BigQuery.

<b>Returns:</b>

void

onBackgroundMessage(messaging, nextOrObserver) {:#onbackgroundmessage_b9887da}

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.

<b>Signature:</b>

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

Parameters

ParameterTypeDescription
messagingMessagingThe Messaging instance.
nextOrObserverNextFn<!-- --><MessagePayload<!-- -->> | Observer<!-- --><MessagePayload<!-- -->>This function, or observer object with <code>next</code> defined, is called when a message is received and the app is currently in the background.

<b>Returns:</b>

Unsubscribe

To stop listening for messages execute this returned function

function()

isSupported() {:#issupported}

Checks whether all required APIs exist within SW Context

<b>Signature:</b>

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

<b>Returns:</b>

Promise<boolean>

a Promise that resolves to a boolean.