Re: [w3c/manifest] Add beforeinstallprompt event (#417)

> It looks like install is going ahead and it's relatively simple and non-controversial, so I've started implementation in Chrome (I just sent an Intent to Implement email today; Chrome tracking bug).

🎉 

> I don't think install satisfies this requiement. We want a way to report to the website before showing the install prompt, to give the site an opportunity to suppress the banner and expose it to the user at a more convenient time (e.g., instead of it popping up in the user's face, it can provide a banner/button to install.

We are all in 100% agreement with the above - and that "install" is a separate use case. We don't need to discuss it here as it's solved. 

> Now in this particular case, it's unspecified whether the prompt is shown, depending on whether the first or second event fires first. Is that Boris's problem? 

I think it's actually the opposite - (but hopefully @bzbarsky can comment here). I think it's the opposite:

```JS
//  Script 1 - totally show it! (<script async>) 
window.addEventListener('beforeinstallprompt', e => e.prompt());
// Script 2 - whoa! don't show it! (<script async>)
window.addEventListener('beforeinstallprompt', e => e.preventDefault());
```

> Calling preventDefault() on the event after calling prompt() would have no effect.

Ok, but this might be where you end up getting into funky race conditions depending on ordering of in which scripts are executed (using script@async): event order registration is not deterministic. 

> * A global method like navigator.showInstallPrompt() that lets you explicitly ask to show an install prompt, which will succeed if you've been given a BIP event and haven't yet prompted, but fails otherwise.

I kinda like this. I also don't like the idea of having to hang onto random objects from the event. 

Are we sure we can't do a flipkart here?
```JS
var wasPrompted = false; 
addEventListener("beforeinstallprompt", e => {
    e.defaultPrevented();
    wasPrompted = true;
    icon.shakeThatCutePhoneIcon();
});

icon.onclick = (e) => {
   if(icon.isShaking && wasPrompted){
      navigator.showInstallPrompt();
   }
}
```

A little out of left field, but we might  even consider if there is overlap with the permissions API? 

```JS
navigator.permissions.query({name:'install'}).then(function(result) {
   if (result.state == 'prompt') {
     navigator.permissions.request({{name:'install'}}).then(...)      
  }
});
```

> I hope we can get beforeinstallprompt into the spec as it provides real value and we don't want it to just sit around as a Chrome-only thing.

Us too! I've emailed Boris and Olli Pettay (who Gecko's events model probably better than anyone). They are the ones that will need to approve if this goes into Gecko, so I'm hoping they will have good feedback. 


---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/manifest/issues/417#issuecomment-229256032

Received on Wednesday, 29 June 2016 04:54:13 UTC