title: Unable to display the firebase push notification/message on background mode
body: <p>Im working on firebase messaging service to send push notification via django web application to Andriod,IOS and website as well, i refer to this <a href="https://firebase.google.com/docs/cloud-messaging/js/topic-messaging" rel="nofollow noreferrer">link</a>, i managed to get token but not able to display the message on background mode, please find the js code in html index page and firebase-messaging-sw for your reference (Note: i don't get any error, but at the same time I don't receive any notification nor message!!)</p>
  <p>index.html:</p>
  <pre><code>&lt;!-- Getting the tocken --&gt;
  &lt;script type=&quot;module&quot;&gt;
  // Import the functions you need from the SDKs you need
  import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js';
  
  // Your web app's Firebase configuration
  // For Firebase JS SDK v7.20.0 and later, measurementId is optional
  const firebaseConfig = {
    apiKey: &quot;xxxxxxxxxxxxxx&quot;,
    authDomain: &quot;xxxxxxxxxxxxxx&quot;,
    projectId: &quot;xxxxxxxxxxxx&quot;,
    storageBucket: &quot;xxxxxxxxxxxxxxxx&quot;,
    messagingSenderId: &quot;xxxxxxxxxxxxxxxxx&quot;,
    appId: &quot;xxxxxxxxxxxxxxxxxxxxx&quot;,
    measurementId: &quot;xxxxxxxxxxxxxxxxxxx&quot;
  };
  
  // Initialize Firebase
  const app = initializeApp(firebaseConfig);
  
  import { getMessaging, getToken } from 'https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging.js';
  
  // Get registration token. Initially this makes a network call, once retrieved
  // subsequent calls to getToken will return from cache.
  const messaging = getMessaging();
  
  getToken(messaging, { vapidKey: 'xxxxxxxxxxxxxxx' }).then((currentToken) =&gt; {
    if (currentToken) {
        console.log(currentToken);
      // Send the token to your server and update the UI if necessary
      // ...
    } else {
      // Show permission request UI
      console.log('No registration token available. Request permission to generate one.');
      // ...
    }
  }).catch((err) =&gt; {
    console.log('An error occurred while retrieving token. ', err);
    // ...
  });
  
  &lt;/script&gt;
  
  
   &lt;!-- Recieving the message on forground--&gt;
   &lt;script type=&quot;module&quot;&gt;
  import { getMessaging, onMessage } from 'https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging.js';
  
  const messaging = getMessaging();
  onMessage(messaging, (payload) =&gt; {
    console.log('Message received. ', payload);
    console.log('mes sent');
    // ...
  });
  
  &lt;/script&gt;
  </code></pre>
  <p>and in firebase-messaging-sw.js:</p>
  <pre><code>    importScripts('https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js');
  importScripts('https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging.js');
  importScripts('https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-sw.js');
  
  // Initialize the Firebase app in the service worker by passing in
  // your app's Firebase config object.
  // https://firebase.google.com/docs/web/setup#config-object
  const BikumApp = firebase.initializeApp({
    apiKey: 'xxxxxxxxxxxxxxxxxxxxx&quot;',
    authDomain: 'xxxxxxxxxxxxxxxxxxxxxxxx',
    databaseURL: 'xxxxxxxxxxxxxxxxxxxxxx',
    projectId: 'xxxxxxxxxxxxxxx',
    storageBucket: 'xxxxxxxxxxxxxxxxxx',
    messagingSenderId: 'xxxxxxxxxxxxxxxxxxx',
    appId: &quot;xxxxxxxxxxxxxxxxxxxxxxx&quot;,
    measurementId: 'xxxxxxxxxxxxxxxxxxx',
  });
  
  // Retrieve an instance of Firebase Messaging so that it can handle background
  // messages.
  const messaging = firebae.getMessaging(BikumApp)
  console.log(messaging);
  
  
  // const messaging = getMessaging();
  onBackgroundMessage(messaging, (payload) =&gt; {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here
    const notificationTitle = 'Background Message Title';
    const notificationOptions = {
      body: 'Background Message body.',
      icon: '/firebase-logo.png'
    };
    
    registration.showNotification(notificationTitle,
      notificationOptions);
  });
  </code></pre>