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

Toolbox rule problem #249

Open jegj opened 7 years ago

jegj commented 7 years ago

I created the following rule using toolbox with a custom handler. toolbox.router.get('/user/test', function(request) { return new Response('It works! ' + request.url); },{ origin: 'http://local.testserver:10000' });

It only works after i reload the page twice. The first time, it send the request to the network , but if i reload the page, i get the correct response from service worker

JasperMaes commented 7 years ago

Hi

I'm experiencing the exact same issue here.

My code is as shown below:

importScripts("/assets/js/sw-toolbox.js")

// Only works after reloading page, also tested with any instead of post
toolbox.router.post('/contact', function(request, values, options){
  console.log("INTERCEPTED POST REQUEST");
  return new Response("OK");
})

// Has no influence on whether the route above works or not
toolbox.router.default = toolbox.cacheFirst;

Any ideas on why this is happening? I've tried with and without the companion script to load the service worker. I'm using the last released version 3.6.1.

Thanks

Jasper