This article needs a technical review. How you can help.
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
The BeforeInstallPromptEvent is passed into the onbeforeinstallprompt handler and displatched when a web manifest exists, but before a user is prompted to save a web site to a home screen on mobile.
This interface inherits from the Event interface.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 8.571428571428571%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-20 0 700 60" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent" target="_top"><rect x="1" y="1" width="240" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="121" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">BeforeInstallPromptEvent</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
Constructor
BeforeInstallPromptEvent.BeforeInstallPromptEvent()- Creates a new
BeforeInstallPromptEvent.
Properties
Inherits properties from its parent, Event.
BeforeInstallPromptEvent.platformRead only- Returns a
DOMStringcontaining the platform on which the event was dispatched. BeforeInstallPromptEvent.userChoiceRead only- Returns a
Promisethat resolves to aDOMStringcontaining either 'installed' or 'dismissed'.
Example
window.addEventListener("beforeinstallprompt", function(e) {
// log the platforms provided as options in an install prompt
console.log(e.platforms); // e.g., ["web", "android", "windows"]
e.userChoice.then(function(platform, outcome) {
console.log(platform); // the platform of the app the user took an action on
console.log(outcome); // either "installed", "dismissed", etc.
}, handleError);
});
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support |
44.0 [1] |
Not supported | Not supported | Not supported | Not supported |
| Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|
| Basic support | Not supported |
44.0 [1] |
Not supported | Not supported | Not supported | Not supported |
44.0 [1] |
[1] beforeinstallprompt event is supported in Chrome 44, but it is behind the flagchrome://flags/#bypass-app-banner-engagement-checks