During development, my web app project serves files on a development server at https://localhost
. However, Chrome blocks its service worker from accessing the server (because it does not trust the self-signed https certificate). Is there a way to disable/unregister service workers in Chrome when in development mode?
You can use the chrome devtools, and under Application>Service Workers path select the Update on refresh checkbox
You can also use the Bypass for network checkbox to avoid Service worker's register event form firing.
Bypass for network
option shown in above image to avoid the registration –
Pitarys Bypass for network
with clicking stop
did the trick. –
Divisive - Navigate:
Dev Tools > Application > Service Workers
- Enable:
Bypass for network
This will prevent the browser from referencing the service worker for content. Very useful for development when you do not want to do cache busting on every save.
Here is a brute-force approach:
const fn = () => {};
navigator.serviceWorker.register = () => new Promise(fn, fn);
(tested in Chrome Canary and Firefox Developer Edition)
This solution is specific to a NextJS project using Next-PWA library to implement PWA, but it uses Google's Workbox under the hood to run service-workers, so it might help someone dig deeper.
// next.config.js
const withPWA = require('next-pwa')
module.exports = withPWA({
pwa: {
disable: process.env.NODE_ENV === 'development',
// ...
}
})
References:
https://github.com/GoogleChrome/workbox/issues/1790#issuecomment-729698643 https://www.npmjs.com/package/next-pwa?activeTab=readme#configuration
© 2022 - 2024 — McMap. All rights reserved.