Service worker event waitUntil() was passed a promise that rejected with 'TypeError: b is null'
<p>This is my service worker file that shows the push notification:</p>

<pre><code>importScripts('https://www.gstatic.com/firebasejs/3.5.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.5.0/firebase-messaging.js');

var config = {
    apiKey: "my_key",
    authDomain: "my_domain.firebaseapp.com",
    databaseURL: "https://my_db.firebaseio.com",
    storageBucket: "my_bucket.appspot.com",
    messagingSenderId: "my_sender_id"
};
firebase.initializeApp(config);


var messaging = firebase.messaging();

messaging.setBackgroundMessageHandler(function (payload) {

    var notificationTitle = 'Hello World';
    var notificationOptions = {
        body: 'Test push notification'
    };

    return self.registration.showNotification(notificationTitle,notificationOptions);

});
</code></pre>

<p>This is my html, where it registers the service worker:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;TODO supply a title&lt;/title&gt;
        &lt;meta charset="UTF-8"&gt;
        &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div&gt;TODO write content&lt;/div&gt;
        &lt;script src="https://www.gstatic.com/firebasejs/3.5.0/firebase.js"&gt;&lt;/script&gt;
        &lt;script&gt;
             var config = {
                apiKey: "my_key",
                authDomain: "my_domain.firebaseapp.com",
                databaseURL: "https://my_db.firebaseio.com",
                storageBucket: "my_bucket.appspot.com",
                messagingSenderId: "my_sender_id"
            };
            firebase.initializeApp(config);
        &lt;/script&gt;

        &lt;script&gt;

            var messaging = firebase.messaging();
            var ser = '/serviceworker.js';
            if ('serviceWorker' in navigator) {
                // Register service worker
                navigator.serviceWorker.register('./public/serviceworker.js').then(function (reg) {
                    messaging.useServiceWorker(reg);
                    messaging.requestPermission()
                            .then(function () {
                                console.log('Notification permission granted.');
                                return messaging.getToken()
                                        .then(function (currentToken) {
                                            if (currentToken) {
                                                console.log('in if', currentToken);
                                                if (window.XMLHttpRequest) {
                                                    xhttp = new XMLHttpRequest();
                                                } else {
                                                    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                                }
                                                xhttp.onreadystatechange = function () {
                                                    if (this.readyState == 4 &amp;&amp; this.status == 200) {

                                                    }
                                                };
                                                xhttp.open("POST", "/notification", true);
                                                xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
                                                xhttp.send(JSON.stringify({token: currentToken}));
                                            } else {
                                                console.log('in else', currentToken);
                                            }

                                        }).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.onMessage(function (payload) {
                        var options = {
                            body: payload.data.body
                        }
                        var notificationObj = new Notification(payload.data.title, options);
                   });
                }).catch(function (err) {
                    console.error("SW registration failed with error " + err);
                });
            }

        &lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Everything is working fine but when i load page for first time then i see the following error after allowing the notification permission. I am using FCM for push notification.</p>

<pre><code>Service worker event waitUntil() was passed a promise that rejected with 'TypeError: b is null'.
</code></pre>