service-worker
Can service workers cache POST requests?
You can’t cache POST requests using the Cache API. See https://w3c.github.io/ServiceWorker/#cache-put (point 4). There’s a related discussion in the spec repository: https://github.com/slightlyoff/ServiceWorker/issues/693 An interesting solution is the one presented in the ServiceWorker Cookbook: https://serviceworke.rs/request-deferrer.html Basically, the solution serializes requests to IndexedDB.
What is the storage limit for a service worker?
Update Jan 15 2018 The StorageManager interface of Storage API is becoming a standard for all storage related api queries. As mentioned by @miguel-lattuada, the estimate API would provide an estimate of the storage used a web app the available storage. Also, note the QuotaExceededError exception which would help us in handling error scenarios. eg … Read more
Can you use a service worker with a self-signed certificate?
As an alternative to using self-signed certificates, you can launch Chrome or Firefox such that it pretends certain domains are secure. For example, using Chrome on a Mac, you can launch it using: /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ –user-data-dir=/tmp/foo –unsafely-treat-insecure-origin-as-secure=http://www.your.site Service workers should then work from http://www.your.site. More info can be found here: Options for testing … Read more
Service worker registration failed. Chrome extension
Please find below the cause for your specific issue and the cause for not getting the details of failure in the console log. Before Chrome 93, the service worker file must be in the root path where manifest.json is. This is a limitation of Service Worker specification, relaxed for extensions since Chrome 93. If, for … Read more
What causes a Failed to execute ‘fetch’ on ‘ServiceWorkerGlobalScope’: ‘only-if-cached’ can be set only with ‘same-origin’ mode error?
I believe this is a Chromium bug that has been reported here. Hopefully it will be fixed soon or some more information about the issue will be published. Paul Irish implemented a temporary work around, which is as follows: if (e.request.cache === ‘only-if-cached’ && e.request.mode !== ‘same-origin’) { return; } I ran it inside the … Read more
“Status Code:200 OK (from ServiceWorker)” in Chrome Network DevTools?
This is a common source of confusion, so I wanted to go into a bit more detail. I have a full working demo in this Gist, and you can view a live version of it thanks to RawGit. Here’s the relevant portion of the service worker code inline, for illustrative purposes: self.addEventListener(‘fetch’, event => { … Read more
How to clear cache of service worker?
If you know the cache name you can simply call caches.delete() from anywhere you like in the worker: caches.delete(/*name*/); And if you wanted to wipe all caches (and not wait for them, say this is a background task) you only need to add this: caches.keys().then(function(names) { for (let name of names) caches.delete(name); });
Options for testing service workers via HTTP
In general, you need to serve both your page and your service worker script via HTTPS in order to use service workers. The rationale is described at Prefer Secure Origins For Powerful New Features. There’s an exception to the HTTPS requirement in place to facilitate local development: if you access your page and service worker … Read more
How do I uninstall a Service Worker?
Removing Service Workers Programmatically You can remove service workers programmatically like this: navigator.serviceWorker.getRegistrations().then(function(registrations) { for(let registration of registrations) { registration.unregister() } }) Docs: getRegistrations, unregister Removing Service Workers Through The User Interface You can also remove service workers under the Application tab in Chrome Devtools.