Nikhil.Nixel
Nikhil.Nixel

Reputation: 584

How to prevent "Add to home screen" from appearing on certain urls of same webapp?

I have a webapp that shows some content on say, test.com and special.test.com

I have setup PWA using React Typescript + PWA template. The "Add to Home Screen" appears on both the urls.

Is their a way to prevent the install option from appearing in special.test.com

self.addEventListener('beforeinstallprompt', (event) => {
  const subdomainName = self.location.host.split('.')[0];
  console.log('PWA_INSTALL_CALL', subdomainName);
  if (subdomainName === 'special') {
    event.preventDefault();
  }
});

I have added this event listener to service-worker.ts but this function doesn't seem to be called since I'm not seeing console.log statement on Chrome dev console.

Really stuck here! Please help. Thanks!

Upvotes: 0

Views: 153

Answers (1)

abraham
abraham

Reputation: 47893

You need to listen for beforeinstallprompt in the application context, not in a service worker context.

Upvotes: 1

Related Questions