GoogleChrome / GoogleChrome/android-browser-helper

Beforeinstallprompt not working in chrome custom tabs

Open
#336 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
832
Forks
370
Avg merge
1d 3h
Merged PRs (30d)
6

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

```
Install App

```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.