@firebase/messaging

Functions

FunctionDescription
function(app, ...)
getMessaging(app)Retrieves a Firebase Cloud Messaging instance.
function(messaging, ...)
deleteToken(messaging)Deletes the registration token associated with thisMessaging instance and unsubscribes theMessaging instance from the push subscription.
getToken(messaging, options)Subscribes theMessaging instance to push notifications. Returns a Firebase Cloud Messaging registration token that can be used to send push messages to thatMessaging instance.If notification permission isn't already granted, this method asks the user for permission. The returned promise rejects if the user does not allow the app to show notifications.
onMessage(messaging, nextOrObserver)When a push message is received and the user is currently on a page for your origin, the message is passed to the page and anonMessage() event is dispatched with the payload of the push message.
function()
isSupported()Checks if all required APIs exist in the browser.

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:

exportdeclarefunctiongetMessagingInWindow(app?:FirebaseApp):Messaging;

Parameters

ParameterTypeDescription
appFirebaseApp

Returns:

Messaging

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

function(messaging, ...)

deleteToken(messaging)

Deletes the registration token associated with thisMessaging instance and unsubscribes theMessaging instance from the push subscription.

Signature:

exportdeclarefunctiondeleteToken(messaging:Messaging):Promise<boolean>;

Parameters

ParameterTypeDescription
messagingMessagingTheMessaging instance.

Returns:

Promise<boolean>

The promise resolves when the token has been successfully deleted.

getToken(messaging, options)

Subscribes theMessaging instance to push notifications. Returns a Firebase Cloud Messaging registration token that can be used to send push messages to thatMessaging instance.

If notification permission isn't already granted, this method asks the user for permission. The returned promise rejects if the user does not allow the app to show notifications.

Signature:

exportdeclarefunctiongetToken(messaging:Messaging,options?:GetTokenOptions):Promise<string>;

Parameters

ParameterTypeDescription
messagingMessagingTheMessaging instance.
optionsGetTokenOptionsProvides an optional vapid key and an optional service worker registration.

Returns:

Promise<string>

The promise resolves with an FCM registration token.

onMessage(messaging, nextOrObserver)

When a push message is received and the user is currently on a page for your origin, the message is passed to the page and anonMessage() event is dispatched with the payload of the push message.

Signature:

exportdeclarefunctiononMessage(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 user is currently viewing your page.

Returns:

Unsubscribe

To stop listening for messages execute this returned function.

function()

isSupported()

Checks if all required APIs exist in the browser.

Signature:

exportdeclarefunctionisWindowSupported():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.