0

I am able to get Add to home screen popup on my website example.com but when I open my website with www.example.com, I again get the popup and on clicking on add, it adds the wpa again in the home screen.

How can I prevent this from happening as its useless to have two wpa icons of the same website?

Abhi
  • 65
  • 10

2 Answers2

3

Easiest option is to simply redirect www calls to non-www calls. So the users never actually stay in that different subdomain.

If for some reason you can't do that, on install of the PWA you could save a cross subdomain cookie just to have a "flag" set that the user installed the PWA. Then, in your code you listen to beforeinstallpromptevent, and do not prompt the install if the cookie exists.

Erndob
  • 2,512
  • 20
  • 32
-1

You could add some JavaScript code to remove the following tag whenever the user visits the wwwsite.

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

Example:

if (window.location.host.startsWith('www.') {
    const manifestLink = document.querySelector("link[rel='manifest']")
    manifestLink.parentNode.removeChild(manifestLink)
}
mattemyo
  • 99
  • 1
  • 4