0
I’m trying to make my mobile site appear the "Add Home" button, but it doesn’t work at all.
My files
index php.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#BABACA">
<link rel="manifest" href="manifest.json">
<title>Teste</title>
</head>
<script type="text/javascript">
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(function(registration) {
alert('registrado');
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}).catch(function(err) {
alert('deu problema' + err);
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
</script>
<body>
Pagina teste do pwa 2
</body>
</html>
manifest
{
"name": "Site Teste",
"short_name": "teste",
"theme_color": "#2196f3",
"background_color": "#2196f3",
"display": "browser",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "teste_icon.png",
"type": "image/png",
"sizes": "192x192"
}
]
}
sw.json
{
"name": "Site Teste",
"short_name": "teste",
"theme_color": "#2196f3",
"background_color": "#2196f3",
"display": "browser",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "teste_icon.png",
"type": "image/png",
"sizes": "192x192"
}
]
}
My site is on https and it appears the serviceworker working , even with self Certificate , I used firefox
The last test I downloaded from this project https://github.com/mdn/pwa-examples/tree/master/a2hs
This project works well online https://mdn.github.io/pwa-examples/a2hs/
But on localhost not.
Is there any limitation to add page in localhost ?