diff --git a/packages/gatsby/cache-dir/app.js b/packages/gatsby/cache-dir/app.js index d9d8b1a33a60f..c1daf37e9e116 100644 --- a/packages/gatsby/cache-dir/app.js +++ b/packages/gatsby/cache-dir/app.js @@ -24,7 +24,7 @@ apiRunnerAsync(`onClientEntry`).then(() => { * * Let's unregister the service workers in development, and tidy up a few errors. */ - if (`serviceWorker` in navigator) { + if (supportsServiceWorkers(location, navigator)) { navigator.serviceWorker.getRegistrations().then(registrations => { for (let registration of registrations) { registration.unregister() @@ -69,3 +69,10 @@ apiRunnerAsync(`onClientEntry`).then(() => { }) } }) + +function supportsServiceWorkers(location, navigator){ + if (location.hostname === `localhost` || location.protocol === `https:`){ + return `serviceWorker` in navigator + } + return false +}