function isElectron ( ) { return window && 'process' in window ; } function isBrowser ( ) { return ! isElectron ( ) ; } if ( 'serviceWorker' in navigator && isBrowser ( ) ) { let beforeInstallPromptEvent ; window . addEventListener ( 'beforeinstallprompt' , ( event ) => { beforeInstallPromptEvent = event ; console . log ( "SUCCESS: received beforeinstallprompt and PWA is installable!" ) ; } ) ; const isLocalhost = document . location . host === 'localhost:8050' ; window . addEventListener ( 'load' , function ( ) { if ( isLocalhost ) { console . warn ( "Not registering service worker - localhost/webpack-dev-server" ) ; return ; } else { console . log ( "Service worker being registered." ) ; } async function doAsync ( ) { const reg = await navigator . serviceWorker . register ( '/service-worker.js' ) ; reg . onupdatefound = ( ) => { console . log ( "Service worker update found" ) ; const installingWorker = reg . installing ; if ( installingWorker ) { installingWorker . onstatechange = function ( ) { switch ( installingWorker . state ) { case 'installed' : if ( navigator . serviceWorker . controller ) { console . log ( 'New or updated content is available.' ) ; } else { console . log ( 'Content is now available offline!' ) ; } break ; case 'redundant' : console . error ( 'The installing service worker became redundant.' ) ; break ; } } ; } } ; } doAsync ( ) . catch ( e => console . error ( 'Error during service worker registration:' , e ) ) ; } ) ; }