npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cordova-plugin-firebase-messaging

v9.1.0

Published

Cordova plugin for Firebase Messaging

Downloads

7,116

Readme

Cordova plugin for Firebase Cloud Messaging

NPM version NPM downloads NPM total downloads GitHub sponsor PayPal donate Twitter

| Donate | Your help is appreciated. Create a PR, submit a bug or just grab me :beer: | |-|-|

Index

Supported platforms

  • iOS
  • Android

Installation

$ cordova plugin add cordova-plugin-firebase-messaging

Use variables IOS_FIREBASE_SDK_VERSION and ANDROID_FIREBASE_BOM_VERSION to override SDK versions for different platforms:

$ cordova plugin add cordova-plugin-firebase-messaging \
    --variable IOS_FIREBASE_SDK_VERSION="9.3.0" \
    --variable ANDROID_FIREBASE_BOM_VERSION="30.3.1"

For cordova-ios below version 8: if you get an error about CocoaPods being unable to find compatible versions, run

$ pod repo update

Adding configuration files

Cordova supports resource-file tag for easy copying resources files. Firebase SDK requires google-services.json on Android and GoogleService-Info.plist on iOS platforms.

  1. Put google-services.json and/or GoogleService-Info.plist into the root directory of your Cordova project
  2. Add new tag for Android platform
<platform name="android">
    ...
    <resource-file src="google-services.json" target="app/google-services.json" />
</platform>
...
<platform name="ios">
    ...
    <resource-file src="GoogleService-Info.plist" />
</platform>

This way config files will be copied on cordova prepare step.

Set custom default notification icon (Android only)

Setting a custom default icon allows you to specify what icon is used for notification messages if no icon is set in the notification payload. Also use the custom default icon to set the icon used by notification messages sent from the Firebase console. If no custom default icon is set and no icon is set in the notification payload, the application icon (rendered in white) is used.

<platform name="android">
    ...
    <config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/my_custom_icon_id"/>
    </config-file>
</platform>

Set custom default notification color (Android only)

You can also define what color is used with your notification. Different android versions use this settings in different ways: Android < N use this as background color for the icon. Android >= N use this to color the icon and the app name.

<platform name="android">
    ...
    <config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
        <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@drawable/my_custom_color"/>
    </config-file>
</platform>

Type Aliases

PushPayload

PushPayload = object

In general (for both platforms) you can only rely on custom data fields.

message_id and sent_time have google. prefix in property name (will be fixed).

Properties

| Property | Type | Description | | :------ | :------ | :------ | | aps? | Record<string, any> | IOS payload, available when message arrives in both foreground and background. | | data | Record<string, any> | Custom data sent from server | | gcm? | Record<string, any> | Android payload, available ONLY when message arrives in foreground. | | message_id | string | Message ID automatically generated by the server | | sent_time | number | Time in milliseconds from the Epoch that the message was sent. |

Variables

BACKGROUND_MESSAGE_EVENT

const BACKGROUND_MESSAGE_EVENT: string


MESSAGE_EVENT

const MESSAGE_EVENT: string


TOKEN_REFRESH_EVENT

const TOKEN_REFRESH_EVENT: string

Functions

clearNotifications()

clearNotifications(): Promise<void>

Clear all notifications from system notification bar.

Returns

Promise<void>

Callback when operation is completed

Example

cordova.plugins.firebase.messaging.clearNotifications();

deleteToken()

deleteToken(): Promise<void>

Delete the Instance ID (Token) and the data associated with it.

Call getToken to generate a new one.

Returns

Promise<void>

Callback when operation is completed

Example

cordova.plugins.firebase.messaging.deleteToken();

getBadge()

getBadge(): Promise<number>

Gets current badge number (if supported).

Returns

Promise<number>

Promise fulfiled with the current badge value

Example

cordova.plugins.firebase.messaging.getBadge().then(function(value) {
    console.log("Badge value: ", value);
});

getToken()

getToken(format?: "apns-buffer" | "apns-string"): Promise<string>

Returns the current FCM token.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | format? | "apns-buffer" | "apns-string" | Token representation (iOS only) |

Returns

Promise<string>

Promise fulfiled with the current FCM token

Example

cordova.plugins.firebase.messaging.getToken().then(function(token) {
    console.log("Got device token: ", token);
});

on()

on(eventName: string, signal?: AbortSignal): AsyncGenerator<any, void, unknown>

Creates an asynchronous iterable stream (Async Generator) for a specific native Cordova event. Uses the Web Streams API under the hood to safely manage backpressure, queuing, and memory cleanup.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | eventName | string | The name of the native event/action to listen to. | | signal? | AbortSignal | An optional AbortSignal instance to trigger unsubscription and release resources. |

Returns

AsyncGenerator<any, void, unknown>

An async generator that yields data chunks sent from the native layer.

Example

const firebaseMessaging = cordova.plugins.firebase.messaging;
const controller = new AbortController();

async function listenTokenRefresh() {
  try {
    const fcmMessageStream = firebaseMessaging.on(firebaseMessaging.MESSAGE_EVENT, controller.signal);
    for await (const message of fcmMessageStream) {
      console.log('Received message from FCM:', message);
    }
  } catch (error) {
    console.error('Stream encountered an error:', error);
  }
}

// To stop listening and clean up native resources later:
// controller.abort();

onBackgroundMessage()

onBackgroundMessage(callback: (payload: PushPayload) => void, errorCallback?: (error: string) => void): void

Registers background push notification callback.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | callback | (payload: PushPayload) => void | Callback function | | errorCallback? | (error: string) => void | Error callback function |

Returns

void

Example

cordova.plugins.firebase.messaging.onBackgroundMessage(function(payload) {
    console.log("New background FCM message: ", payload);
});

onMessage()

onMessage(callback: (payload: PushPayload) => void, errorCallback?: (error: string) => void): void

Registers foreground push notification callback.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | callback | (payload: PushPayload) => void | Callback function | | errorCallback? | (error: string) => void | Error callback function |

Returns

void

Example

cordova.plugins.firebase.messaging.onMessage(function(payload) {
    console.log("New foreground FCM message: ", payload);
});

onTokenRefresh()

onTokenRefresh(callback: () => void, errorCallback?: (error: string) => void): void

Registers callback to notify when FCM token is updated.

Use getToken to generate a new token.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | callback | () => void | Callback function | | errorCallback? | (error: string) => void | Error callback function |

Returns

void

Example

cordova.plugins.firebase.messaging.onTokenRefresh(function() {
    console.log("Device token updated");
});

requestPermission()

requestPermission(options: object): Promise<void>

Ask for permission to recieve push notifications (will trigger prompt on iOS).

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | options | { forceShow: boolean; } | Additional options. | | options.forceShow | boolean | When value is true incoming notification is displayed even when app is in foreground. |

Returns

Promise<void>

Filfiled promise when permission is granted.

Example

cordova.plugins.firebase.messaging.requestPermission({forceShow: false}).then(function() {
    console.log("Push messaging is allowed");
});

setBadge()

setBadge(badgeValue: number): Promise<void>

Sets current badge number (if supported).

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | badgeValue | number | New badge value |

Returns

Promise<void>

Callback when operation is completed

Example

cordova.plugins.firebase.messaging.setBadge(value);

subscribe()

subscribe(topic: string): Promise<void>

Subscribe to a FCM topic.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | topic | string | Topic name |

Returns

Promise<void>

Callback when operation is completed

Example

cordova.plugins.firebase.messaging.subscribe("news");

unsubscribe()

unsubscribe(topic: string): Promise<void>

Unsubscribe from a FCM topic.

Parameters

| Parameter | Type | Description | | :------ | :------ | :------ | | topic | string | Topic name |

Returns

Promise<void>

Callback when operation is completed

Example

cordova.plugins.firebase.messaging.unsubscribe("news");