GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.61k stars 331 forks source link

Unknow ServiceWorker failed to install #255

Closed mauricionr closed 7 years ago

mauricionr commented 7 years ago

localhost every things works fine, but in production i'm getting an error

Current lifecycle localhost

Register -> Ok Install -> Ok Activate -> Ok Running -> Ok

Current lifecycle in production

Register -> Ok Install -> Failed

Here's my current service-worker


/* toolbox.min.js is here at top */

/*globals self, toolbox*/

(function(global, toolbox) {

  toolbox.precache([
    '/?utm_source=pwa',
    '/manifest.json'
  ]);

  var VERSION = '1.0.2';
  var HALF_DAY = 4.32e+7;

  toolbox.router.get(/(svg|png|jpg|gif|webp|woff2|woff|ttf|eot)$/, toolbox.cacheFirst, {
    // Use a dedicated cache for the responses, separate from the default cache.
    cache: {
      name: 'cache-static' + VERSION,
      // Expire any entries that are older than one day.
      maxAgeSeconds: HALF_DAY //https://www.google.com.br/search?q=one+day+in+ms&oq=one+day+in+ms&aqs=chrome..69i57j6j69i64.3154j0j7&sourceid=chrome&ie=UTF-8#q=half+day+in+ms
    }
  });

  toolbox.router.default = global.toolbox.networkFirst;

  // Boilerplate to ensure our service worker takes control of the page as soon
  // as possible.
  global.addEventListener('install', function(event) {
    event.waitUntil(global.skipWaiting());
  });
  global.addEventListener('activate', function(event) {
    event.waitUntil(global.clients.claim());
  });
})(self, toolbox);

and the error

image

any help will be appreciated

Thanks

mbj36 commented 7 years ago

Is your site served over https ?

mauricionr commented 7 years ago

Yes

gauntface commented 7 years ago

Can you provide a link to the site?

mauricionr commented 7 years ago

@gauntface i'm unauthorized to post link here, could you share your email or something else?

i've tested in diff chrome versions and i got this result

chrome stable -> failed to install chrome beta -> work's fine :ok_hand: chrome unstable -> failed to install chrome canary -> i will test

gauntface commented 7 years ago

Sure, just use gauntface 'at' google 'dot' com

atb00ker commented 7 years ago

I am facing the same issue, works fine on localhost but not when hosted on gh-pages (https://atb00ker.github.io/asetalias.github.io/manifest.html)

jeffposnick commented 7 years ago

@ATB00ker Your sw.js includes:

var urlsToCache = [
    '/',
    // Other URLs...
];

On your deployed website, the / URL refers to https://atb00ker.github.io/, and requests for that URL return a 404:

screen shot 2017-11-13 at 11 17 30 am

You presumably want ./ in that urlsToCache list, not /. That way it will always be interpreted as being relative to the same directory under which the service worker is deployed. In production, that will be https://atb00ker.github.io/asetalias.github.io/