Search code examples
javascriptweb-push

navigator.serviceWorker for development environment


serviceWorker in navigator available only if web page is loaded via https. Is there any way to make it working on development environment using usual http?

if ('serviceWorker' in navigator) {
    console.log('serviceWorker');
}

It does not wok on my development environment.

I'm using firefox/chrome as a browser.


Solution

  • According to MDN: Service workers are restricted to running across HTTPS for security reasons. GitHub is therefore a good place to host experiments, as it supports HTTPS. In order to facilitate local development, localhost is considered a secure origin by browsers as well.

    So I would run your dev environment on a localhost port and it should work