From 3ee567bb1fddf7ee5b2f2039735773804a8f2d8f Mon Sep 17 00:00:00 2001
From: Marcos Caceres
Queue a task on the application life-cycle task
source to do the following:
-
@@ -490,6 +489,125 @@ cancelable
attribute initialized to true.
DOM events fired by this specification use the application
life-cycle task source.
BeforeInstallPromptEvent
Interface
+ + [Constructor] + interface BeforeInstallPromptEvent : Event { + Promise<PromptResponseObject> prompt(); + }; + dictionary PromptResponseObject { + AppBannerPromptOutcome userChoice; + }; ++
+ The BeforeInstallPromptEvent is dispatched prior to + activating an automated install prompt, allowing a developer + to prevent the default action for an install prompt. +
+
+ Thus, the default action of the BeforeInstallPromptEvent is to
+ present an automated install
+ prompt to the end-user. Canceling the default action (via
+ .preventDefault()
) prevents the user agent from
+ presenting an automated
+ install prompt until a later time (see
+ BeforeInstallPromptEvent.prompt() method).
+
+ An instance of a BeforeInstallPromptEvent has the following + internal slots: +
+false
. Represents if this event
+ was used to present an install prompt to the end-user.
+ prompt()
method
+ + The prompt method, when called, runs the following + steps: +
+isTrusted
attribute is
+ false
, reject
+ this.[[\userResponsePromise]] with
+ NotAllowedError, optionally informing the developer
+ that untrusted events can't call prompt()
.
+ false
, then, in parallel, request to
+ present an install prompt with this event. Wait, possibly
+ indefinitely, for the end-user to make a choice.
+ + To request to present an install prompt with + BeforeInstallPromptEvent event: +
+userChoice
member is
+ the value of outcome.
+ + This example shows how one might prevent an automated install + prompt from showing until the user has finished a set of tasks. + Those tasks are represented as an array of promises, which the + application "awaits" to finish before an install prompt is + presented to the end-user. +
++ window.addEventListener("beforeinstallprompt", async (event) => { + event.preventDefault(); + // Wait for e.g., the user to request installation from inside the app. + await Promise.all(tasksThatPreventsInstallation); + const { userChoice } = await event.prompt(); + console.info(`user choice was: ${userChoice}`); + }); ++
Window
object
@@ -3028,7 +3146,7 @@