Open
Description
I am trying to open a pwa app from custom tabs of my trusted web activity app. I have an install button for the pwa in the custom tabs by following code,
pwa-handler.js
if('serviceWorker' in navigator){
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('service worker registered'))
.catch(err => console.log('service worker not registered', err));
}
var deferredPrompt;
window.addEventListener('beforeinstallprompt', function(event) {
alert('beforeinstallprompt fired');
event.preventDefault();
deferredPrompt = event;
return false;
});
function addToHomeScreen() {
if (deferredPrompt) {
deferredPrompt.prompt();
deferredPrompt.userChoice.then(function (choiceResult) {
console.log(choiceResult.outcome);
if (choiceResult.outcome === 'dismissed') {
console.log('User cancelled installation');
} else {
console.log('User added to home screen');
}
});
deferredPrompt = null;
}
}
html
<a href="#" onclick="addToHomeScreen()" class="btn" type="button">Install App</a>
I get "beforeinstallprompt fired" alert of pwa in normal chrome browser and abled to install pwa by clicking install app button, but I don't get "beforeinstallprompt fired" alert in custom tabs of my TWA app and when clicking "Install App" button from custom tabs of TWA nothing happens.
It will be cool if you have a workaround for this. Thanks.