Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeinstallprompt not called #688

Closed
sealabr opened this issue Jun 8, 2018 · 4 comments
Closed

beforeinstallprompt not called #688

sealabr opened this issue Jun 8, 2018 · 4 comments

Comments

@sealabr
Copy link

sealabr commented Jun 8, 2018

Hello I'm trying to install a custom PWA "Add to Homescreen".
The ServiceWorkerRegistration is successful.

But the function beforeinstallpromp is not calling after register.

<script type="text/javascript">
  
  function request_debug(paramdata){
    
    document.getElementById('output').innerHTML += '<BR>'+ paramdata;

  }
  
  window.addEventListener('load', function() {
                          
      document.getElementById('output').style.display = "block"; 
  
      if('serviceWorker' in navigator) {

      navigator.serviceWorker.register('sw.js').then(function(registration) {
        console.log('Service worker  registrado com sucesso:', registration);
        request_debug(registration);

      }).catch(function(error) {
        console.log('Falha ao Registrar o Service Worker:', error);
        request_debug(error);

      });

          var isTooSoon = true;
          window.addEventListener('beforeinstallprompt', function(e) {

              //e.preventDefault();
              //e.prompt();
              //promptEvent = e;
              request_debug(' window.addEventListener beforeinstallprompt fired!')

              if (isTooSoon) {
                //e.preventDefault(); // Prevents prompt display
                // Prompt later instead:
                setTimeout(function() {
                  isTooSoon = false;
                  e.prompt(); // Throws if called more than once or default not prevented
                }, 4000);
              }
 
          });

    }else{

      console.log('serviceWorker not in navigator');
      request_debug('serviceWorker not in navigator');

    }

    
  });
  
</script>

Also my service worker in root directory...

my manifest:

{
  "background_color": "purple",
  "description": "lojaportaldotricot TESTE",
  "display": "standalone",
  "icons": [
    {
      "src": "/componentes/serviceWorker/fox-icon.png",
      "sizes": "192x192",
      "type": "image/png"
    }
  ],
  "name": "lojaportaldotricot",
  "short_name": "lojaportaldotricot",
  "start_url": "/dashboard"
}

It's only workes when I set "Enable" chrome://flags/#bypass-app-banner-engagement-checks

@dominickng
Copy link
Collaborator

On Chrome, if you already have added the site to home screen, beforeinstallprompt is not going to fire. Make sure your site isn't already added to home screen, and clear Chrome's site data, and try again (ideally on a different Android phone as well).

Otherwise, this is not an issue with the manifest spec. It is an issue with the Chrome browser, and you should file a bug at crbug.com/new.

@sealabr
Copy link
Author

sealabr commented Jun 11, 2018

solved! thanks!

@33sKamal
Copy link

@sealabr hELLO
i'M HAVING SAME ISSUE PLEASE HOW DID YOU SOULVE IT
THANKS

@FabioYami
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants