Skip to content
On this page

preventPWAInstallPromptObserver

Non Standard!

Prevent PWA Install Prompt and lets you controll when you want to call the install prompt. Only supported by few browsers. Got removed from manifest standard.

Relies on: https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent

Demo

Your browser doen't support that feature.

Usage

First Setup the observer to prevent Browser install prompt and save the event to use it later.

export { setupPreventPWAInstallPromptObserver } from '@donskelle/pwa-helpers';

setupPreventPWAInstallPromptObsever();

Then you can add and remove observer at any later time to request the event and initiate the prompt.

export { addPreventPWAInstallPromptObserver } from '@donskelle/pwa-helpers';

addPreventPWAInstallPromptObserver((event?: BeforeInstallPromptEvent) => {
  localdata.isInstallAvailable = !!event;
  localdata.installEvent = event;
});

// later on button click or any other event you can initiate the prompt
localdata.prompt();

You need to remove the observer as well

export { removePreventPWAInstallPromptObserver } from '@donskelle/pwa-helpers';

removePreventPWAInstallPromptObserver();