42

Was playing around with the progressive web app. I've trying to make web app install banner working but I keep receiving service worker does not successfully serve the manifest's start_url after I debugging using Lighthouse (Picture below). Currently I'm hosting my website using azure.

NEW: I checked all my cache, start_url, and also my service worker to see everything match. But it still gives me the same error.

enter image description here

I'm not sure if it's my start_url or my service-workerproblem. Below is my code.

manifest.json

  {
   "short_name": "MY EXPERTS",
   "name": "MYEXPERT",
   "icons": [
    {
      "src": "Images/petronas_logo_192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "Images/petronas_logo_192.png",
      "type": "image/png",
      "sizes": "512x512"
    }
 ],

 "background_color": "#FFFFFF",
 "theme_color": "#67BCFF",
 "display": "standalone",
 "start_url": "/Home/Index"
}

AddServiceWorker.js

if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').
    then(function (registration) {
        // Registration was successful``
        console.log('ServiceWorker registration successful with scope: ', 
registration.scope);
    }).catch(function (err) {
        // registration failed :(
        console.log('ServiceWorker registration failed: ', err);
    });
}

service-worker.js

 self.addEventListener('install', e => {
 e.waitUntil(
    caches.open('airhorner').then(cache => {
        return cache.addAll([
            '/',
            '/?utm_source=homescreen',
            '/Home/About',
            '/Home/Index',
            '/Home/Contact'
        ])
            .then(() => self.skipWaiting());
    })
  )
});

self.addEventListener('activate', event => {
 event.waitUntil(self.clients.claim());
});

self.addEventListener('fetch', event => {
  event.respondWith(
    caches.match(event.request).then(response => {
        return response || fetch(event.request);
    })
  );
});

My Browser Cache :

enter image description here

Ryan Wu
  • 5,963
  • 2
  • 36
  • 47
azriebakri
  • 1,131
  • 2
  • 11
  • 36

6 Answers6

14

Noted from Register A service worker,

If we register the service worker file at /example/sw.js, then the service worker would only see fetch events for pages whose URL starts with /example/ (i.e. /example/page1/, /example/page2/).

Inline with the shown error and given in this documentation, check the following:

  1. Define a start_url property in your manifest.json file.
  2. Ensure that your service worker properly caches a resource that matches the value of start_url.

Also, check this tutorial and see if it will help you.

Teyam
  • 7,686
  • 3
  • 15
  • 22
  • 6
    I went through all of your links. Checked my cache, doing a bit of trial and error but I still received the same error. I updated my question with a screenshot of my cache. – azriebakri Oct 15 '17 at 13:12
  • 3
    i had my service worker inside a subdirectory. that was causing the issue. thanks – Ivan Sanz Carasa Apr 09 '19 at 21:46
  • Running the audit in incognito mode resolves this issue for me. No idea why though – Jakub Nov 15 '19 at 10:28
  • furthermore the error disappears when I add a route to the cache that does not exist. Its magic, but also very poor. – Jakub Nov 15 '19 at 10:36
  • OMG. I've spent like two days fighting with this and the issue was... THAT!?!?!?!?! GAH! – eliotRosewater Mar 26 '20 at 19:56
3

there guys, been struggling with same issue just to find that my html link tag was missing, make sure you are indicating where is your manifest file located on your website header:

<link rel="manifest" href="/manifest.json">
ruben
  • 31
  • 2
3

Answered

  • Go to your public folder,
  • Go to your manifest.json file,
  • Now add "start_url": "/", to the json object.
  • See example below.

{ "name": "Occasionally Frustrated", "short_name": "Occasionally Frustrated", "start_url": "/", "display": "standalone" }

2

Just a note... you notice above that the pages are being served over "https." But, if you have everything else right, and are not using https, you will get this same error message.

seveninstl
  • 824
  • 1
  • 9
  • 17
0

You should provide the url in "start_url", if you are using the localhost it should containg the next: "start_url": "http://localhost:8080/index.html",

Ruslan Korkin
  • 3,973
  • 1
  • 27
  • 23
0

Exclude /wp-content/plugins/super-progressive-web-apps/public/js/register-sw.js from cache plugin. It works for me.