Skip to content

Commit

Permalink
[gatsby] don't run service-workers outside of https or localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
busticated committed Jan 12, 2018
1 parent 3fcc3bc commit 298b4cc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -69,3 +69,10 @@ apiRunnerAsync(`onClientEntry`).then(() => {
})
}
})

function supportsServiceWorkers(location, navigator){
if (location.hostname === `localhost` || location.protocol === `https:`){
return `serviceWorker` in navigator
}
return false
}

0 comments on commit 298b4cc

Please sign in to comment.