• Version 0.12.6
  • Published
  • 1 MB
  • 6 dependencies
  • Apache-2.0 license


npm i @firebase/messaging
yarn add @firebase/messaging
pnpm add @firebase/messaging


The Firebase Cloud Messaging Web SDK. This SDK does not work in a Node.js environment.



function deleteToken

deleteToken: (messaging: Messaging) => Promise<boolean>;
  • Deletes the registration token associated with this Messaging instance and unsubscribes the Messaging instance from the push subscription.

    Parameter messaging

    The Messaging instance.


    The promise resolves when the token has been successfully deleted.


    • @public

function getMessaging

getMessaging: (app?: FirebaseApp) => Messaging;
  • Retrieves a Firebase Cloud Messaging instance.


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


    • @public

function getToken

getToken: (messaging: Messaging, options?: GetTokenOptions) => Promise<string>;
  • Subscribes the Messaging instance to push notifications. Returns a Firebase Cloud Messaging registration token that can be used to send push messages to that Messaging 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.

    Parameter messaging

    The Messaging instance.

    Parameter options

    Provides an optional vapid key and an optional service worker registration.


    The promise resolves with an FCM registration token.


    • @public

function isSupported

isSupported: () => Promise<boolean>;
  • Checks if all required APIs exist in the browser.


    a Promise that resolves to a boolean.


    • @public

function onMessage

onMessage: (
messaging: Messaging,
nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>
) => Unsubscribe;
  • 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 an onMessage() event is dispatched with the payload of the push message.

    Parameter messaging

    The Messaging instance.

    Parameter nextOrObserver

    This function, or observer object with next defined, is called when a message is received and the user is currently viewing your page.


    To stop listening for messages execute this returned function.


    • @public


interface FcmOptions

interface FcmOptions {}
  • Options for features provided by the FCM SDK for Web. See WebpushFcmOptions.


    • @public

property analyticsLabel

analyticsLabel?: string;
  • The label associated with the message's analytics data.

link?: string;
  • The link to open when the user clicks on the notification.

interface GetTokenOptions

interface GetTokenOptions {}

property serviceWorkerRegistration

serviceWorkerRegistration?: ServiceWorkerRegistration;
  • The service worker registration for receiving push messaging. If the registration is not provided explicitly, you need to have a firebase-messaging-sw.js at your root location. See Access the registration token for more details.

property vapidKey

vapidKey?: string;
  • The public server key provided to push services. The key is used to authenticate push subscribers to receive push messages only from sending servers that hold the corresponding private key. If it is not provided, a default VAPID key is used. Note that some push services (Chrome Push Service) require a non-default VAPID key. Therefore, it is recommended to generate and import a VAPID key for your project with Configure Web Credentials with FCM. See The Web Push Protocol for details on web push services.

interface MessagePayload

interface 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.


    • @public

property collapseKey

collapseKey: string;

property data

data?: {
[key: string]: string;
  • Arbitrary key/value payload.

property fcmOptions

fcmOptions?: FcmOptions;

property from

from: string;
  • The sender of this message.

property messageId

messageId: string;
  • The message ID of a message.

property notification

notification?: NotificationPayload;

interface Messaging

interface Messaging {}
  • Public interface of the Firebase Cloud Messaging SDK.


    • @public

property app

app: FirebaseApp;

interface NotificationPayload

interface NotificationPayload {}
  • Display notification details. Details are sent through the Send API.


    • @public

property body

body?: string;
  • The notification's body text.

property icon

icon?: string;
  • The URL to use for the notification's icon. If you don't send this key in the request, FCM displays the launcher icon specified in your app manifest.

property image

image?: string;
  • The URL of an image that is downloaded on the device and displayed in the notification.

property title

title?: string;
  • The notification's title.

Package Files (1)

Dependencies (6)

Dev Dependencies (6)

Peer Dependencies (1)


To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@firebase/messaging.

  • Markdown
  • HTML
    <a href="https://www.jsdocs.io/package/@firebase/messaging"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>