title: PWA foreground push notifications
body: <p>i have a problem with foreground push notifications.</p>
  
  <p>I just want to get the data in the console for the moment but it didn't work. I follow the <a href="https://firebase.google.com/docs/cloud-messaging/js/receive" rel="nofollow noreferrer">guide</a> on firebase documentation but this function is never triggered...</p>
  
  <pre class="lang-js prettyprint-override"><code>messaging.onMessage((payload) =&gt; {
    console.log('Message received. ', payload);
  });
  </code></pre>
  
  <p>Background notifications works as expected.</p>
  
  <p>Here is my VueJs file</p>
  
  <pre class="lang-js prettyprint-override"><code>import * as firebase from "firebase/app";
  import 'firebase/messaging';
  
  const config = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: ""
  };
  
  firebase.initializeApp(config);
  const messaging = firebase.messaging();
  messaging.usePublicVapidKey("");
  
  export default {
    name: 'App',
    mounted() {
      messaging.onMessage((payload) =&gt; { // Don't work here
        console.log('Message received. ', payload);
      });
  
      this.getMsgPushToken();
    },
    methods: {
      ...mapMutations('auth', ['mutMsgPushToken']),
  
      getMsgPushToken() {
        let that = this
        messaging.requestPermission().then(async function() {
          messaging.getToken().then((token) =&gt; {
            that.mutMsgPushToken(token); // Where i get the FCM token
          })
        }).catch((err) =&gt; {
          console.log('Unable to get permission to notify.', err);
        });
      },
    },
  };
  </code></pre>
  
  <p>And my service worker</p>
  
  <pre class="lang-js prettyprint-override"><code>importScripts('https://www.gstatic.com/firebasejs/5.5.6/firebase-app.js');
  importScripts('https://www.gstatic.com/firebasejs/5.5.6/firebase-messaging.js');
  
  firebase.initializeApp({
    'messagingSenderId': ''
  });
  
  const messaging = firebase.messaging();
  </code></pre>
  
  <p>If you have any idea of what i'm missing, i would love to hear it ha ha</p>