voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
28 lines (16 loc) • 1.22 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/messaging](./messaging.md) > [onMessage](./messaging.onmessage.md)
## 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.
<b>Signature:</b>
```typescript
export declare function onMessage(messaging: FirebaseMessaging, nextOrObserver: NextFn<MessagePayload> | Observer<MessagePayload>): Unsubscribe;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| messaging | [FirebaseMessaging](./messaging.firebasemessaging.md) | The <code>FirebaseMessaging</code> instance. |
| nextOrObserver | NextFn<[MessagePayload](./messaging.messagepayload.md)<!-- -->> \| Observer<[MessagePayload](./messaging.messagepayload.md)<!-- -->> | This function, or observer object with <code>next</code> defined, is called when a message is received and the user is currently viewing your page. |
<b>Returns:</b>
Unsubscribe
To stop listening for messages execute this returned function.