Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent PWA install prompt chrome 76 on desktop?

Chrome 76 has introduced a button in the omnibox to "Install App" if the PWA criteria is met.

Is there a way to prevent this button from appearing in the omnibox for chrome desktop?

like image 571
spinners Avatar asked Aug 19 '19 12:08

spinners


People also ask

Does PWA work on desktop?

With a PWA, you can use a single codebase that's shared between your website, mobile app, and desktop app (across operating systems).

What is PWA Chrome?

You can use Progressive Web Apps (PWAs) for a fast web experience on your computer or mobile device. You can install the PWA for faster access and additional functionality, like more storage for content to use offline.

How do I get users to install my PWA?

The browser's installation prompts are the first step in getting users to install your PWA. To implement your own install experience, your app still needs to pass the install criteria: when the browser detects that your app is installable, it fires the beforeinstallprompt event.

How do I install a progressive web app on Chrome?

If your website meets the Progressive Web App installability criteria, Chrome will show an install button in the omnibox indicating, that your Progressive Web App can be installed. If the user clicks the install button, an install dialog box will appear, making it easy for a user to install your PWA.

What is a PWA install event?

For sites that pass the PWA install criteria, the browser triggers an event to prompt the user to install it. The good news is that you can use this event to customize your prompt and invite users to install your app. Users may not be familiar with the PWA install process.

Why can't I install a PWA on my iOS device?

Chrome and Edge on iOS and iPadOS do not support PWA installation, so the beforeinstallprompt event can't fire. In this case, the only option is to open the PWA using Safari, where it is installable from the share, add to the home screen menu.


2 Answers

Supposing you want to prevent the default so as to show a customized install banner, read here.

However, this script would totally prevent the install banner!

window.addEventListener('beforeinstallprompt', (e) => {
    // Prevent Chrome 67 and earlier from automatically showing the prompt
    e.preventDefault();
});
like image 114
Emmanuel Avatar answered Oct 21 '22 11:10

Emmanuel


For making your PWA installable only on mobile and not on desktop you can choose one of the following methods:

  1. Redirect to a subdomain or another domain that does not have a manifest file

  2. If you are using Server-Side-Rendering, remove the manifest link tag before sending to the client

    <!-- do not include this if the client userAgent is a desktop device (wide screen) -->
    <link rel="manifest" href="./manifest.json"/> 
    
  3. Remove manifest on the client once the page is loaded on desktop

    window.addEventListener("load", function() {
      if (navigator.userAgent.indexOf('Mobile') === -1) {
        document.querySelector('link[rel="manifest"]').remove();
      }
    });
    

That way it will make your PWA not installable and thus not showing the Add to Home screen in the omnibox.

like image 28
Harry Theo Avatar answered Oct 21 '22 12:10

Harry Theo