The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/messaging > onMessage

onMessage() function

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.

Signature:

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

Parameters

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