Отображение (установка) баннера PWA в Android In-App браузер не работает - PullRequest
0 голосов
/ 27 апреля 2020

У меня есть пользовательская кнопка, которая запускает баннер установки PWA. Он отлично работает как в компьютере, так и в мобильных браузерах. Только если веб-страница доступна через Android браузер в приложении, баннер не появляется.

Мой код такой, как показано ниже:

<div class="center dp-px-1">
    <p class="">Please Click On <strong>INSTALL</strong> Button And Tap on <strong>Notification</strong> Shown At The Bottom To Install</p>
    <p class="" id="alreadyInstalled" style="display:none;color:red;">This app is already installed. If you think this is an error, please delete all browser cache and try again.</p>
    <p class="" id="installationStarted" style="display:none;color:green;">Installation Started...</p>
</div>

<div class="dp-width-100-p center dp-mt-2">
    <span style="width:50%;color:#ffffff;background-color:#666666;padding:5px 7px;" id="install" class="fallback dp-cursor-pointer">DEMO INSTALL</span>
</div>

<script type="text/javascript">
    let deferredPrompt;
    window.addEventListener('beforeinstallprompt', (e) => {
        e.preventDefault();
        deferredPrompt = e;
    });

    // Install Button installationStarted
    const alreadyInstalled = document.querySelector('#alreadyInstalled');
    const installationStarted = document.querySelector('#installationStarted');
    const installButton = document.querySelector('#install');
    installButton.addEventListener('click', (e) => {
        if(deferredPrompt){
            deferredPrompt.prompt();
            deferredPrompt.userChoice.then((choiceResult) => {
                if (choiceResult.outcome === 'accepted') {
                    console.log('User accepted the install prompt');
                    installationStarted.style.display = 'block';
                } else {
                    console.log('User dismissed the install prompt');
                }
            })
        } else {
            console.log('Already Installed');
            installButton.style.display = 'none';
            alreadyInstalled.style.display = 'block';
        }
    });
</script>
...