PWA - Add start screen does not work on localhost

Asked

Viewed 264 times

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 ?

1 answer

-1

I could not find a solution, what was done to get around the problem was to point the route of the server to the own development server, then it entered the site and the site pointed to our development server.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.