The variable "payload" within the messaging.onMessage() function in AngularJS (version 1.6) is returning as undefined when using FCM

In my AngularJS app, I am using FCM (Firebase Cloud Messaging) to connect to Firebase and receive a messaging token. I am able to successfully retrieve the token and see messages in the console.

>>firebaseDependencies: Object { app: {…}, appConfig: {…}, installations: {…}, … }
​
onMessageCallback: null
​
swRegistration: ServiceWorkerRegistration { installing: null, scope: "http://localhost:8080/firebase-cloud-messaging-push-scope", updateViaCache: "imports", … }
​
vapidKey: "BHlbwdTi9t_8-FMCh2X991P_KEuIsWMoKJSWYqk44B8AtWRhoehYpZ-GkHqnSfya9ANiTMLTUZxbpK1ASIgmLBc"
​
<prototype>: {…}
​​
app: 
​​
constructor: function rt(e)​​
deleteToken: function deleteToken()​​
getServiceWorkerRegistration: function getServiceWorkerRegistration()​​
getToken: function getToken()​​
logEvent: function logEvent(n, r)​​
messageEventListener: function messageEventListener(o)​​
onMessage: function onMessage(e)​​
onTokenRefresh: function onTokenRefresh()​​
requestPermission: function requestPermission()​​
setBackgroundMessageHandler: function setBackgroundMessageHandler()​​
usePublicVapidKey: function usePublicVapidKey(e)​​
useServiceWorker: function useServiceWorker(e)

I also have set up the following code for sending notifications:

>>https://fcm.googleapis.com/fcm/send
data
{
 "to" : "dXECW-D1bx0GuaF6f-s0Ms:APA91bFjAL7-0WuqYuscLCRZJ0ojJqk1Qm8NLu21yNo8elXZy1VPzy5OGZhzRVkLTo7SSZgP9cjdx-Xq_c2jqgs2O73tYEUmfGuhflNbcq-aEVoTX4JslM1slgdQJSLvf9Kgh3X3rJQD",

>>"notification" : {
      "body" : "great match!",
      "title" : "Portugal vs. Denmark",
      "icon" : "myicon"
    }
}

However, when trying to handle incoming messages with the following code snippet, it does not work as expected:

 >> messaging.onMessage().then((payload) => {

    console.log('Message received. ', payload);
    alert("message",payload)
    // [START_EXCLUDE]
    // Update the UI to include the received message.
    // appendMessage(payload);
    // [END_EXCLUDE]});

This issue needs further investigation to make the notification functionality work properly.

Answer №1

It is recommended to utilize an older version of FCM JS and manually configure it since the current version may not be compatible with your Angular framework.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unusual body padding found in the mobile design

When visiting on a mobile device and inspecting the elements in Google Chrome, try disabling the style rule overflow-x: hidden from the body element and then resizing the window. You may notice a white vertical stripe (padding) appearing on the right side ...

Can you explain the distinction between Array() and [] in Javascript, and when would it be preferable to use one over the other?

Similar Question: Understanding the difference between "new Array()" and "[]" in JavaScript array declaration When working with JavaScript, you have the option to create a new array using: var arr = new Array(); or simply using: var arr2 = []; Wha ...

Display a hidden form field in Rails depending on the object's value

As a programmer learning Ruby on Rails without much knowledge of Javascript, I faced a problem with a form that creates an object called Unit. This Unit model is related to Category which in turn is related to Product. The issue was that while selecting a ...

Why isn't my JavaScript variable visible in the HTML code?

I am currently facing an issue with my Angular app where I am trying to display a JavaScript variable in HTML. The variable successfully shows up in an older part of my application, but it fails to do so in the new section. Below is the functional code sn ...

The extension page causes AngularJS to alter URLs to "unsafe:"

My goal is to integrate Angular with a list of apps, where each app is represented by a link that allows users to view more details (apps/app.id): <a id="{{app.id}}" href="apps/{{app.id}}">{{app.name}}</a> Whenever I click on any of these ...

How to move a div beneath the JavaScript files in Drupal 7

I am facing a challenge where I need to position a div right above the body tag without interfering with the scripts located above it. Despite my efforts, I have not been successful in achieving this goal. I attempted to use Hook_page_build to position t ...

Error Code 18: Unable to Open Database - Troubleshooting in AngularJS and Cordova

Looking to set up an SQLite database using Angular.js and Cordova without relying on Ionic? Check out the following steps for initializing your app. $(function() { new AppInitializer(); }); var AppInitializer = function() { // Determine platform - we ...

Modifying Element Values with JavaScript in Selenium using C#

As a newcomer to automation, I am facing a challenge with automating a web page that has a text field. I initially attempted using driver.FindElement(By.XPath("Xpath of elemnt").SendKeys("Value"); but unfortunately, this method did not work. I then resor ...

CORS blocking Axios POST request to Heroku causing a Network Error 503

Using the MERN Stack, everything was functioning correctly until modifications were made to the UI (such as relocating code to different components and altering styles). The issue lies with a specific POST request, while other requests that utilize Axio ...

How can one update transitive dependencies to a specific newer version in npm to address CVE vulnerabilities?

Here are the packages that require upgrading. I attempted to update the version and signature of the packages listed in package-lock.json. However, whenever I run npm i after modifying package-lock.json, the changes made to package-lock.json disappear. ...

Activate the b-form-file function by selecting the b-button

Working with BootstrapVue, I am trying to trigger my b-form-file after clicking on a b-button for style reasons. Additionally, I want the b-form-file to be hidden so it is not visible. I attempted the following approach, but it did not work for me: <b- ...

Why does Vue 3 refuse to refresh an <img> element, while it successfully refreshes all other components within the same component?

In my current Vue project, I have set up multiple link cards (<a class='card'></a>) inside a "deck" container (<div class='deck'></div>). The implementation for these elements is relatively straightforward: <s ...

What are some ways to optimize Ajax requests for improved speed when multiple identical requests are made on a single webpage?

When the webpage is loaded, a block is dynamically created using an Ajax call to retrieve data from another page. This structure is then populated and added to a specific DOM element. However, multiple Ajax calls during page loads are causing delays. Is ...

The 'RegExpExecArray | null' type is required to include a method '[Symbol.iterator]()' which returns an iterator to iterate through its values

As someone who is new to TypeScript, I have a good understanding of the basics but recently came across a typecast error that I am struggling to solve. const [full, id]: string | null = /.*media\/[^\/]+\/(.*)/.exec(item.uri) When it comes t ...

Unable to activate Vue 13 keyCode in a text field using jQuery with Laravel Dusk Testing

I've been grappling with this issue for a few days now. I'm trying to create a Laravel Dusk test that incorporates the Vue.js framework. There's a method that should be triggered when the user hits the ENTER key. I recently discovered that ...

JavaScript placeholder-type expression

Hey there, I am a C++ developer who is venturing into the world of JavaScript. While exploring JavaScript syntax, I stumbled upon something that resembles templates in C++. For example, while going through RxJs tutorials, I came across this line of code: ...

Preparing JSON data for creating a wind map with Leaflet

I am currently working on converting netCDF data to JSON in order to use it with leaflet-velocity. This tool follows the same format as the output of grib2json used by cambecc in earth. An example of sample JSON data can be found at wind-global.json. By u ...

A step-by-step guide on converting an audiopath to an audio file in a React-Native application and transferring it

I am facing a challenge in my react-native application where I need to send an audio wav file to a postnodejs/express route using multipart/form-data request. After utilizing the package from https://github.com/goodatlas/react-native-audio-record, I was a ...

How can I efficiently utilize the date picker feature in Angular JS for a smooth user experience?

I am new to AngularJS and attempting to implement a date picker. I initially tried using a basic jQuery UI date picker, but it did not function as expected. Can someone please provide me with some code that demonstrates the simplest way to achieve this in ...

Selenium project not functioning as expected

I created a script that opens the website in EDGE and logs into my account. After that, it is supposed to fill in some fields and click the submit button. However, my script is able to do it but the data is not being saved. It acts as if I haven't en ...