Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable service workers when in development mode.

In case of our development, we serve files from https://localhost as the app is hosted in salesforce.com. In chrome service worker on chrome blocks anything coming from self-signed server i.e (https://localhost).

So is there a way to disable/unregister service workers when in development mode. Any pattern to follow for this.

Thanks

like image 562
Kiba Avatar asked Nov 24 '16 10:11

Kiba


People also ask

How do I disable service worker?

In Chrome there is no built-in flag to disable service workers specifically. But service workers count as "cookies/site data" at chrome://settings/cookies so blocking those disables service worker.

How do I stop a service worker in react?

"If you had previously enabled service workers in your production deployment and have decided that you would like to disable them for all your existing users, you can swap out the call to serviceWorkerRegistration. register() in src/index. js with a call to serviceWorkerRegistration. unregister().

How do I disable service workers in Safari?

Settings > Safari > Advanced > Experimental Features > Service Workers -- slide to OFF position.


2 Answers

You can use the chrome devtools, and under Application>Service Workers path select the Update on refresh checkbox

enter image description here

You can also use the Bypass for network checkbox to avoid Service worker's register event form firing.

like image 150
Aditya Singh Avatar answered Sep 19 '22 01:09

Aditya Singh


Here is a brute-force approach:

const fn = () => {};  navigator.serviceWorker.register = () => new Promise(fn, fn); 

(tested in Chrome Canary and Firefox Developer Edition)

like image 25
cantera Avatar answered Sep 18 '22 01:09

cantera