0

I've made some PWA and now I'm using 'beforeinstallprompt' to display the prompt letting the user select install or not. When the user select "install" it's of course possible to display a message indicating installation is in progress. But how can we detect the end of installation process? Notice appinstalled is not the way to do that as, despite of its name, this event is not fired at the end of the installation process but... at the begining!

I've tried a "tricks", pooling getInstalledRelatedApps() in order to get the list of installed App thinking that my PWA will be in this list after being installed. Like this:

function checkForRelatedApps() 
{
    navigator.getInstalledRelatedApps().then(relatedApps => {
    console.log("Dans checkForRelatedApps");
    if (relatedApps.length != 0) 
    {
     for (let app of relatedApps)
         {
             console.log(app.platform);
             console.log(app.url);
             console.log(app.id);
        }
    }
    setTimeout(checkForRelatedApps,4000);
    });
}

But strange: even if the PWA is on main screen runnng correctly, it's never visible in the relatedApps array which number of element stay at 0. I've seen some examples about using getInstalledRelatedApps() but all are about "real App" and not about "installed PWA"... So is there a way to detect the end of installation (Android display a Toast about that) and is there a way to detect installation of PWA using getInstalledRelatedApps? (examples welcomed!)

Thanks to you all

Peter
  • 1,247
  • 19
  • 33
  • Take a look at [this answer here](https://stackoverflow.com/questions/51735869/check-if-user-has-already-installed-pwa-to-homescreen-on-chrome) which deals with pretty much the same thing – Ayushya Mar 23 '21 at 18:46
  • I've seen but the accepted answer doesn't work. Unfortunatly :/ – Peter Mar 23 '21 at 18:48
  • The OP for that question mentions in his comment that it was not working with `localhost` but was working otherwise. Is this something you've eliminated already? – Ayushya Mar 23 '21 at 18:50
  • Yes. The PWA is on a web site (https), I use new version of Chrome, have a manifest with related_applications, a .well-know folder and so on. Also the example used here https://get-installed-apps.glitch.me/ is about a real App from Google Play and not a PWA. – Peter Mar 23 '21 at 19:03
  • Ooh, interesting. I've never had to deal with this. I'll loop back to you if I do find something that works – Ayushya Mar 23 '21 at 19:10

0 Answers0