Why am I seeing "Error - Only secure origins are allowed" for my service worker?
<p>When I try to add a service worker on my progressive web app page, why does the browser console show the following error?</p>

<pre><code>ERROR "Uncaught (in promise) DOMException: Only secure origins are allowed
</code></pre>

<p>JS Code:</p>

<pre><code>(function () {
    'use strict';

    // TODO add service worker code here
    if ('serviceWorker' in navigator) {
        navigator.serviceWorker
            .register('service-worker.js')
            .then(function () {
                console.log('Service Worker Registered');
            });
    }
})();
</code></pre>