This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
The BeforeInstallPromptEvent is the interface of the beforeinstallprompt event fired at the Window object before a user is prompted to "install" a website to a home screen on mobile.
This interface inherits from the Event interface.
BeforeInstallPromptEvent() Non-standard Experimental
Creates a new BeforeInstallPromptEvent object.
Inherits properties from its parent, Event.
BeforeInstallPromptEvent.platforms Read only Non-standard Experimental
Returns an array of string items containing the platforms on which the event was dispatched. This is provided for user agents that want to present a choice of versions to the user such as, for example, "web" or "play" which would allow the user to choose between a web version or an Android version.
BeforeInstallPromptEvent.userChoice Read only Non-standard Experimental
Returns a Promise that resolves to an object describing the user's choice when they were prompted to install the app.
BeforeInstallPromptEvent.prompt() Non-standard Experimental
Show a prompt asking the user if they want to install the app. This method returns a Promise that resolves to an object describing the user's choice when they were prompted to install the app.
In the following example an app provides its own install button, which has an id of "install". Initially the button is hidden.
<button id="install" hidden>Install</button>
The beforeinstallprompt handler:
BeforeInstallPromptEvent object to a variable, so it can be used laterlet installPrompt = null;
const installButton = document.querySelector("#install");
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
installPrompt = event;
installButton.removeAttribute("hidden");
});
When clicked, the app's install button:
prompt() method of the stored event object, to trigger the installation prompt.installPrompt variable and hiding itself again.installButton.addEventListener("click", async () => {
if (!installPrompt) {
return;
}
const result = await installPrompt.prompt();
console.log(`Install prompt was: ${result.outcome}`);
installPrompt = null;
installButton.setAttribute("hidden", "");
});
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
BeforeInstallPromptEvent |
44 | 79 | No | 31 | No | 44 | No | 32 | No | 5.0 | 44 | No |
BeforeInstallPromptEvent |
44 | 79 | No | 31 | No | 44 | No | 32 | No | 5.0 | 44 | No |
platforms |
44 | 79 | No | 31 | No | 44 | No | 32 | No | 5.0 | 44 | No |
prompt |
7644–76Resolved with an empty promise. |
79 | No | 6331–63Resolved with an empty promise. |
No | 7644–76Resolved with an empty promise. |
No | 5432–54Resolved with an empty promise. |
No | 5.0 | 7644–76Resolved with an empty promise. |
No |
userChoice |
44 | 79 | No | 31 | No | 44 | No | 32 | No | 5.0 | 44 | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent