Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workbox Request method 'POST' is unsupported

I am using the code from this site: https://developers.google.com/web/tools/workbox/modules/workbox-routing

My code is as below:

workbox.routing.registerRoute(
  new RegExp('http://localhost:64445.*/'),
  workbox.strategies.staleWhileRevalidate({
    cacheName:'Post-Run-time-cache'
  }),
  'POST'
);

And it gives me the error:

Uncaught (in promise) TypeError: Request method 'POST' is unsupported

I do not know what went wrong. It is from the document but it is not supported?? why. Thanks for the help.

like image 812
wadefanyaoxia Avatar asked Sep 06 '18 16:09

wadefanyaoxia


1 Answers

The Cache Storage API doesn't support using a Request object whose method is not 'GET' as a cache key. Attempting to store a 'POST' request in the cache (which is happening under the hood in the staleWhileRevalidate strategy) will fail with an error similar to what you're seeing—though I think there's a more informative error logged when you're in Workbox's development mode, on localhost.

If you're looking to retry failed 'POST' requests, I'd recommend the workbox-background-sync module.

like image 67
Jeff Posnick Avatar answered Dec 01 '22 08:12

Jeff Posnick