Built-in application banner for Chrome and adding to the home screen

I recently added my own Chrome app install banner to my website. It works very well when the user meets the specified criteria, a banner is displayed for installing my application.

But I would like to use this function: Add to the main screen . Mostly for those users who do not want to install the application, but they may be interested in adding my network to the main screen.

Is it possible that both functions work together?

+7
android google-chrome manifest progressive-web-apps
source share
2 answers

Yes, you can.

There is a beforeinstallprompt event that you can intercept and hold as long as you want (for example, until the user clicks your button).

There is a .prompt() function in the event, which you can call so that the prompt appears when you want it.

  window.addEventListener ("beforeinstallprompt", ev => { 
   // Stop Chrome from asking _now_
   ev.preventDefault ();

   // Create your custom "add to home screen" button here if needed.
   // Keep in mind that this event may be called multiple times, 
   // so avoid creating multiple buttons!
   myCustomButton.onclick = () => ev.prompt ();
 });
+2
source share

I donโ€™t think it works today. Looks like a good feature request for the Chrome tracker crbug.com I donโ€™t understand how you could control which invitation youโ€™ll receive, but itโ€™s probably worth discussing it on crbug.

0
source share

All Articles