Service Worker无法成功提供清单的start_url

时间:2018-01-18 23:29:54

标签: android service manifest progressive-web-apps worker

完全是新的,所以请放轻松我! :)

我想找到一种方法,可以将我的网页添加到Android的主屏幕。我知道我必须使用服务工作者和清单才能这样做。

但是当我安装并注册我的服务工作者时,它将无法获取我的清单!

  

错误:Service Worker未成功提供清单的start_url

这是我的sw.js:

// Chrome's currently missing some useful cache methods,
// this polyfill adds them.
importScripts('serviceworker-cache-polyfill.js');

// Here comes the install event!
// This only happens once, when the browser sees this
// version of the ServiceWorker for the first time.
self.addEventListener('install', function(event) {
  // We pass a promise to event.waitUntil to signal how 
  // long install takes, and if it failed
  event.waitUntil(
    // We open a cache…
    caches.open('simple-sw-v1').then(function(cache) {
      // And add resources to it
      return cache.addAll([
        './',
        'style.css',
        'logging.js'
      ]);
    })
  );
});

// The fetch event happens for the page request with the
// ServiceWorker's scope, and any request made within that page
self.addEventListener('fetch', function(event) {
  // Calling event.respondWith means we're in charge
  // of providing the response. We pass in a promise
  // that resolves with a response object
  event.respondWith(
    // First we look for something in the caches that matches the request
    caches.match(event.request).then(function(response) {
      // If we get something, we return it, otherwise
      // it's null, and we'll pass the request to
      // fetch, which will use the network.
      return response || fetch(event.request);
    })
  );
}); 

这是我的manifest.json:

{
  "short_name": "Ferie Med Mening",
  "name": "Ferie Med Mening",
  "icons": [
    {
      "src": "https://feriemedmening.xyz/wp-content/uploads/2018/01/ikon-1.png",
      "type": "image/png",
      "sizes": "48x48"
    },
    {
      "src": "https://feriemedmening.xyz/wp-content/uploads/2018/01/ikon-1.png",
      "type": "image/png",
      "sizes": "96x96"
    },
    {
      "src": "https://feriemedmening.xyz/wp-content/uploads/2018/01/ikon-1.png",
      "type": "image/png",
      "sizes": "192x192"
    }
  ],
  "start_url": "https://feriemedmening.xyz/"
  "score_url": "https://feriemedmening.xyz/"
  "theme_color": "#2ABB9C"
}

任何人都可以帮助我吗?

0 个答案:

没有答案