title: How to receive FCM push notifications in service worker in Chrome Extension
body: <p>I'm sending an FCM push notification from a Firebase backend to a Chrome Extension. I get it to show successfully in my Chrome Extension when it's in focus. I want it to show even if the Extension isn't in focus, but I can't get the service worker that's supposed to handle the notification even to fire.</p>
  
  <p>I followed the <a href="https://firebase.google.com/docs/cloud-messaging/js/receive" rel="nofollow noreferrer">Google tutorial</a> to set up my JavaScript Chrome Extension client. I already tried <a href="https://github.com/firebase/quickstart-js/issues/71" rel="nofollow noreferrer">this solution</a> to not include a "notification" payload in my message, and <a href="https://hexadix.com/push-notification-web-browser/" rel="nofollow noreferrer">this solution</a> to register the worker manually (even though the tutorial doesn't say anything about either), but to no avail.</p>
  
  <p>My service worker <code>firebase-messaging-sw.js</code> looks like this:</p>
  
  <pre><code>importScripts('https://www.gstatic.com/firebasejs/5.8.2/firebase.js');
  
  var config = {
    ...
  };
  firebase.initializeApp(config);
  
  const messaging = firebase.messaging();
  
  messaging.setBackgroundMessageHandler(function(payload) {
    console.log('[firebase-messaging-sw.js] Received background message ', payload.data);
    var notificationTitle = 'Background Message Title';
    var notificationOptions = {
      body: 'Background Message body.',
      icon: '/firebase-logo.png'
    };
  
    return self.registration.showNotification(notificationTitle,
      notificationOptions);
  });
  </code></pre>
  
  <p>This is the POST request I use to send notifications (obviously with the correct SERVER_KEY and USER_TOKEN values):</p>
  
  <pre><code>POST /fcm/send HTTP/1.1
  Host: fcm.googleapis.com
  Content-Type: application/json
  Authorization: key=&lt;SERVER_KEY&gt;
  Cache-Control: no-cache
  
  {
      "data": {
          "title": "Firebase",
          "body": "Firebase is awesome",
          "click_action": "http://localhost:5000/",
          "icon": "http://localhost:5000/firebase-logo.png"
      },
      "to": "&lt;USER_TOKEN&gt;"
  }
  </code></pre>
  
  <p><strong>How do I get the service worker to receive the push notification and display it?</strong></p>
  
  <p>Thanks in advance :)</p>