Reputation: 584
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
Reputation: 47893
You need to listen for beforeinstallprompt
in the application context, not in a service worker context.
Upvotes: 1