Something similar to:
let deferredPrompt;
const installButton = document.getElementById('installButton');
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
installButton.style.display = 'block';
});
installButton.addEventListener('click', async () => {
installButton.style.display = 'none';
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
console.log(`User ${outcome} the installation`);
deferredPrompt = null;
});
// Opcional: evento para quando a app for instalada
window.addEventListener('appinstalled', () => {
console.log('App successfully installed!');
});
Something similar to: