From 95fadd654b927b08ea0c4c88089f94d88fd6b561 Mon Sep 17 00:00:00 2001
From: Matt Giuca
Queue a task on the application life-cycle task
source to do the following:
-
+ beforeinstallprompt
, with its cancelable
+ attribute initialized to true.
cancelable
attribute initialized to true.
+
BeforeInstallPromptEvent.prompt()
, but not
+ automatically without the site's approval. Is this something we want
+ to leave to the discretion of the user agent? (This would require
+ changing the language here, as "steps to notify before an automated
+ install prompt" would become "steps to notify that an install prompt
+ is available".)
+
@@ -543,14 +554,22 @@
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 +
.preventDefault()
) prevents the user agent from
- presenting an automated
- install prompt until a later time (see
- BeforeInstallPromptEvent.prompt() method).
+ preventDefault
)
+ prevents the user agent from presenting an automated install prompt. The user agent is
+ free to run steps to notify before an automated install prompt
+ again at a later time.
+
+ The PromptResponseObject contains the result of calling prompt()
. It contains
+ one member, userChoice, which
+ states the user's chosen outcome.
An instance of a BeforeInstallPromptEvent has the following @@ -561,8 +580,8 @@
false
. Represents if this event
- was used to present an install prompt to the end-user.
+ A boolean, initially false
. Represents whether this
+ event was used to present an install prompt to the end-user.
isTrusted
attribute is
- false
, reject
+ 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.
+ false
, set this.[[\didPrompt]]
+ to true
, then in parallel, request to
+ present an install prompt with this event. Wait, possibly
+ indefinitely, for the end-user to make a choice.
@@ -613,12 +629,10 @@
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. + prompt from showing until the user clicks a button to install the + app. In this way, the site can leave installation at the user's + discretion (rather than prompting at an arbitrary time), whilst + still providing a prominent UI to do so.
-- window.addEventListener("beforeinstallprompt", async (event) => { ++ window.addEventListener("beforeinstallprompt", event => { + // Suppress automatic prompting. 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}`); + + // Show the (disabled-by-default) install button. This button + // resolves the installButtonClicked promise when clicked. + installButton.disabled = false; + + // Wait for the user to click the button. + installButton.addEventListener("click", async e => { + // The prompt() method can only be used once. + installButton.disabled = true; + + // Show the prompt. + const { userChoice } = await event.prompt(); + console.info(`user choice was: ${userChoice}`); + }); });@@ -649,9 +675,10 @@Extensions to the
Window
object- The following extensions to the
Window
object - specify the event handler attributes on which events relating - to the installation of a web application are fired. + The following extensions to theWindow
object specify the + event handler attributes on which events relating to the + installation of a web application are fired.partial interface Window { @@ -691,16 +718,16 @@application). -
+ @@ -3625,7 +3652,7 @@
onbeforeinstallprompt
attribute- The onbeforeinstallprompt is an - event handler IDL attribute for the - "beforeinstallprompt" event type. The interface used for - these events is the BeforeInstallPromptEvent interface (see - the steps to notify before an automated install prompt). + The onbeforeinstallprompt is an event handler IDL + attribute for the "beforeinstallprompt" event type. + The interface used for these events is the + BeforeInstallPromptEvent interface (see the steps to + notify before an automated install prompt).