protected void setupRegistration ( ) { if ( isServiceWorkerSupported ( ) ) { Navigator . serviceWorker . register ( getResource ( ) ) . then ( object -> { logger . info ( "Service worker has been successfully registered" ) ; registration = ( ServiceWorkerRegistration ) object ; onRegistered ( new ServiceEvent ( ) , registration ) ; // Observe service worker lifecycle observeLifecycle ( registration ) ; // Setup Service Worker events events setupOnControllerChangeEvent ( ) ; setupOnMessageEvent ( ) ; setupOnErrorEvent ( ) ; return null ; } , error -> { logger . info ( "ServiceWorker registration failed: " + error ) ; return null ; } ) ; } else { logger . info ( "Service worker is not supported by this browser." ) ; } }
Initial setup of the service worker registration .