I'm having a bit of trouble getting to grips with 'Service Workers' and the 'Manifest.json' aspect of google chrome.
My end goal is to get a 'Add to Home Screen' button appearing when the user browses one of my websites via their mobile device in chrome on android.
So I've got my manifest.json, in the root and in the <head>
tag I've got the following:
<link rel="manifest" href="/manifest.json">
When I first put this in the head tag, and went to the 'Application' tab in chrome dev tools on my desktop, It saw the manifest.json and displayed all the information in it correctly. Then as soon as I browsed to a different page on the same domain, the Dev tools displays the message 'No Manifest Detected'.
I have no idea why. It's clearly there, if I inspect the page, go to the <head>
section and find the link rel
, I right click on the manfiest.json link and open in new tab- it loads perfectly. I've validated it with the manifest.json validator too, and it reports 'Success: Manifest is valid!'.
Why is it temporarily dropping out? How can I get this damn button to appear?
Side note, my service worker code (again in <head>
) is the following:
<script type='text/javascript'>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/js/service-worker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
And I get the message in the console 'ServiceWorker registration successfull'. But there is nothing in the service-worker.js
file, surely there needs to be some code in there? None of the tutorials i've found mention putting any data in there. It's confusing.