The employer of the service script, service-worker.js in your case, needs to serve either the URL path of the same directory, or the page with its registration, or subpath.
You use the path /assets/service-worker.js , so if the registration page is not submitted with /assets/ , it will stop working. If you put .catch(function(error) { console.warn(error); }) at the end of your register() (which Promise returns, you will see an error message.
The easiest way to do this is to make sure that service-worker.js served from the same directory as the web page, and then calls register('service-worker.js') , which uses the relative path to the same directory.
source share