Disable service worker in development mode
Asked Answered
J

4

36

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?

Jingoism answered 24/11, 2016 at 10:22 Comment(0)
P
47

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.

Pitarys answered 29/11, 2016 at 9:16 Comment(3)
Yes, but every time I refresh page the Service worker gets registered. I dont want that to happen. thxJingoism
Then select the Bypass for network option shown in above image to avoid the registrationPitarys
for me a combination of Bypass for network with clicking stop did the trick.Divisive
F
6
  1. Navigate: Dev Tools > Application > Service Workers
  2. 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.

Floaty answered 31/7, 2021 at 12:31 Comment(0)
S
5

Here is a brute-force approach:

const fn = () => {};

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

(tested in Chrome Canary and Firefox Developer Edition)

Syllabus answered 28/9, 2019 at 0:34 Comment(0)
P
0

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

Particularism answered 20/10, 2021 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.