Prevent PWA from being installed
Asked Answered
M

3

11

Is there any way to configure my manifest.json to disable the browser popup asking to "install" the site? I'm using the following JavaScript code to prevent it:

window.addEventListener('beforeinstallprompt', function(e) {
    e.preventDefault();
    return false;
});

But I need to prevent it also on the AMP version, and I can't run JavaScript code there.

Mid answered 18/1, 2017 at 4:45 Comment(3)
Why do you link to a manifest from your AMPs if you don't want to support add to homescreen?Intra
What are you trying to accomplish by disabling PWA support?Seineetmarne
It's just a business page, I don't want to disturb users with thatMid
E
8

Currently, there doesn't appear to be an explicit setting to disable app install.

One workaround is to edit manifest.json so that it doesn't meet the required criteria for app install banner, such as removing short_name or icons declarations.

Etam answered 18/1, 2017 at 5:20 Comment(2)
It's a very clever idea, but isn't any other alternative?Mid
There doesn't appear to be an explicit setting to disable app install, so I don't think there's another option. It doesn't sound like you're even using the short_name or icon if you don't want the app installation.Etam
G
4

You can do:

window.addEventListener('beforeinstallprompt', (event) => {
  event.preventDefault()
})

Another workaround would be to set the display: 'browser' option in the site.webmanifest.

Gerstein answered 23/4, 2021 at 16:14 Comment(0)
M
2

Instead of editing my manifest.json file, I tried removing the link to it from within my index.html. I deleted the line:

<link rel="manifest" href="manifest.json">

This seemed to work fine in my case.

Mclaughlin answered 18/11, 2021 at 13:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.