title: messaging.setBackgroundMessageHandler not receiving messages in web
body: <p>I'm implementing firebase notifications in web application. I'm unable to receive background notifications when web page is not active.</p>
  
  <p>What I have done so far is:</p>
  
  <ol>
  <li>Created <code>manifest.json</code> in root directory with code:
  <code>{   "gcm_sender_id": "103953800507" }</code></li>
  <li>Created file <code>firebase-messaging-sw.js</code> in root directory with following code:</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
      importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
      
      firebase.initializeApp({
          'messagingSenderId': '11111'
      });
      
      const messaging = firebase.messaging();
      
      messaging.setBackgroundMessageHandler(function (payload) {
          //sometime receive notification in this
          debugger;
          //some code here to receive notification..
          return self.registration.showNotification(title,
              notificationOptions);
      });</code></pre>
  </div>
  </div>
  </p>
  
  <ol start="3">
  <li>In <code>Home/Index</code> page put following code to get permissions and token</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>firebase.initializeApp({
              'messagingSenderId': '11111'
          });
          
          const messaging = firebase.messaging();
          
          messaging.requestPermission().then(function() {
              console.log('Notification permission granted.');
  
              messaging.getToken().then(function(currentToken) {
  
                  if (currentToken) {
                      console.log(currentToken);
                      sendTokenToServer(currentToken); //save in database
                  }
              }).catch(function(err) {
                  console.log('An error occurred while retrieving token. ', err);
              });
          }).catch(function(err) {
              console.log('Unable to get permission to notify.', err);
          });
          
          messaging.onTokenRefresh(function() {
              messaging.getToken().then(function(refreshedToken) {
                  sendTokenToServer(refreshedToken);
              }).catch(function(err) {
              });
          });
          
                  messaging.onMessage(function (payload) {
              //receive notification here when this page is active. working fine
  
          });</code></pre>
  </div>
  </div>
  </p>
  
  <ol start="4">
  <li>Send notification from postman
  <a href="https://i.stack.imgur.com/LSnJr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LSnJr.png" alt="enter image description here"></a></li>
  </ol>
  
  <blockquote>
    <p>How can I receive notifications in
    messaging.setBackgroundMessageHandler?</p>
  </blockquote>