October 2017
Intermediate to advanced
302 pages
7h 27m
English
Lastly, let's add some console.logs so that we know the result of the registration. Luckily, navigator.serviceWorker.register returns a promise:
<script> if ('serviceWorker' in navigator) { window.addEventListener('load', function() { navigator.serviceWorker.register('sw.js').then(function(registration) { // Registration was successful console.log('Registered!'); }, function(err) { // registration failed :( console.log('ServiceWorker registration failed: ', err); }).catch(function(err) { console.log(err); }); }); } else { console.log('service worker is not supported'); }</script>
Okay, let's test this all out! Reload the page, and if all is good, you should see the following in your console:
You can also check it ...
Read now
Unlock full access