forked from WICG/manifest-incubations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
877 lines (872 loc) · 33.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
Manifest Incubations
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class=
"remove"></script>
<script class='remove'>
// See https://github.com/w3c/respec/wiki/ for how to configure ReSpec
var respecConfig = {
specStatus: "CG-DRAFT",
editors: [{
name: "Daniel Murphy"
}],
group: "wicg",
github: "WICG/manifest-incubations",
shortName: "manifest-incubations",
xref: {
specs: ["appmanifest", "dom"],
profile: "web-platform",
},
};
</script>
</head>
<body>
<section id="abstract">
<p>
Feature specifications for <a href=
"https://www.w3.org/TR/appmanifest/">Web Application Manifest</a>
extensions & incubations which Chromium has shipped but do not have
committments / implementations from other user agents. Instead of
keeping these features as explainers, they are documented more
officially here.
</p>
</section>
<section id="sotd">
<p>
This is an unofficial proposal.
</p>
</section>
<section>
<h2 data-dfn-for="">
<code>display_override</code> member
</h2>
<p>
For advanced usages, the display_override member can be used to specify
a custom fallback order of <a data-cite=
"appmanifest#dfn-display-modes-values">display mode values</a> for
developers to choose their preferred <a data-cite=
"appmanifest#dfn-display-mode">display mode</a>.
</p>
<p>
The <dfn>display_override</dfn> member of the [=application manifest=]
is a <a>sequence</a> of <a data-cite=
"appmanifest#dfn-display-modes-values">display mode values</a>. This
item represents the developer's preferred fallback chain for
<a data-cite="appmanifest#dfn-display-mode">display modes</a>. This
field overrides the [=manifest/display=] member. If the user agent does
not support any of the display modes specified here, then it falls back
to considering the [=manifest/display=] member. See <a data-cite=
"appmanifest#dfn-display-mode">display modes</a> for the algorithm
steps.
</p>
<p>
The following steps are added to the [=application manifest/processing
extension-point=] in <a data-cite=
"appmanifest#dfn-steps-for-determining-the-web-app-s-chosen-display-mode">
determining the web app's chosen display mode</a>:
</p>
<ol>
<li>[=list/For each=] |candidate_display_mode:DisplayModeType| of
|manifest|.{{display_override}}:
<ol>
<li>If the user agent supports the |candidate_display_mode|, then
return |candidate_display_mode|.
</li>
</ol>
</li>
</ol>
<p class="note">
This member is intended to be only used for advanced cases, where the
developer wants explicit control over the fallback order of their
display modes. Otherwise, the [=manifest/display=] member is sufficient
for most use cases.
</p>
<section class="informative">
<h3>
Usage Example
</h3>
<p>
The following shows a [=manifest=] that prefers the
<code>minimal-ui</code> <a data-cite=
"appmanifest#dfn-display-mode">display mode</a> over
<code>standalone</code>, but if <code>minimal-ui</code> isn't
supported, falls back to <code>standalone</code> as opposed to
<code>browser</code>.
</p>
<pre class="example json" title="Advanced display usage manifest">
{
"name": "Recipe Zone",
"description": "All of the recipes!",
"icons": [{
"src": "icon/hd_hi",
"sizes": "128x128"
}],
"start_url": "/index.html",
"display_override": ["minimal-ui"],
"display": "standalone",
"theme_color": "yellow",
"background_color": "red"
}
</pre>
</section>
</section>
<section>
<h2>
`share_target` member
</h2>
<p>
The `share_target` member registers a web application as "target" for
share actions (e.g., for sharing a text, a URL, or a file). The
`share_target` member is part of the [[[web-share-target]]]
specification.
</p>
</section>
<section>
<h2>
<code><dfn>note_taking</dfn></code> member
</h2>
<p>
The `note_taking` member of the <a data-cite=
"appmanifest#web-application-manifest">Web Application Manifest</a> is
an <a data-cite="appmanifest#dfn-object">object</a> that contains
information related to note-taking. It has the following members:
</p>
<ul>
<li>[=note_taking/new_note_url=]
</li>
</ul>
<p>
A user agent MAY use these members to treat the web application
differently as an application with note-taking capabilities (e.g.,
integrate with operating system note-taking surfaces).
</p>
<section>
<h3>
<code><dfn data-dfn-for="note_taking">new_note_url</dfn></code>
member
</h3>
<p>
The [=note_taking=] `new_note_url` member is a [=string=] that
represents the <a data-cite="url#concept-url">URL</a> the developer
would prefer the user agent load when the user wants to take a new
note using the web application (e.g., from an operating system
shortcut icon or keyboard shortcut).
</p>
<p>
The `new_note_url` member is purely advisory, and a user agent MAY
<a data-cite="appmanifest#dfn-ignore">ignore</a> it or provide the
end-user the choice of whether to use it. The user agent MAY provide
the end-user the choice to modify it.
</p>
<aside class="note">
<p>
The `new_note_url` member is parsed with <a data-cite=
"appmanifest#dfn-manifest-url">manifest URL</a> as the base URL and
is ignored if not [=manifest/within scope=] of the manifest.
</p>
</aside>
</section>
<section class="informative">
<h3>
Usage Example
</h3>
<p>
The following shows a [=manifest=] for a note-taking application.
</p>
<pre class="example json" title="Note-taking application">
{
"name": "My Note Taking App",
"description": "You can take notes!",
"icons": [{
"src": "icon/hd_hi",
"sizes": "128x128"
}],
"start_url": "/index.html",
"display": "standalone",
"note_taking": {
"new_note_url": "/new_note.html"
}
}
</pre>
</section>
<section>
<h3>
Processing the `note_taking` member
</h3>
<p>
To <dfn>process the `note_taking` member</dfn>, given [=ordered map=]
|json:ordered map|, [=ordered map=] |manifest:ordered map|, [=URL=]
|manifest_URL:URL|, run the following during the <a data-cite=
"appmanifest#dfn-processing-extension-point-of-web-manifest">extension
point</a> in [=processing a manifest=]:
</p>
<ol class="algorithm">
<li>If |json|["note_taking"] does not [=map/exist=], return.
</li>
<li>If the type of |json|["note_taking"] is not [=ordered map=],
return.
</li>
<li>Set |manifest|["note_taking"] to a new [=ordered map=].
</li>
<li>[=process the `new_note_url` member=] passing
|json|["note_taking"], |manifest|["note_taking"], and |manifest URL|.
</li>
</ol>
</section>
<section>
<h3>
Processing the `new_note_url` member
</h3>
<p>
To <dfn>process the `new_note_url` member</dfn>, given [=ordered
map=] |json_note_taking:ordered map|, [=ordered map=]
|manifest_note_taking:ordered map|, [=URL=] |manifest_URL:URL|, run
the following:
</p>
<ol class="algorithm">
<li>If |json_note_taking|["new_note_url"] does not [=map/exist=],
return.
</li>
<li>If the type of |json_note_taking|["new_note_url"] is not
[=string=], return.
</li>
<li>Let |new_note_url:URL| be the result of [=URL Parser|parsing=]
|json_note_taking|["new_note_url"] with |manifest URL| as the base
URL.
</li>
<li>If |new_note_url| is failure, return.
</li>
<li>If |new_note_url| is not [=manifest/within scope=] of |manifest
URL|, return.
</li>
<li>Set manifest_note_taking["new_note_url"] to |new_note_url|.
</li>
</ol>
</section>
<section>
<h3>
Launching the `new_note_url`
</h3>
<p>
To <dfn>launch the `new_note_url`</dfn>, given <a data-cite=
"appmanifest#dfn-processed-manifest">processed manifest</a>
|manifest:processed manifest|, run the following steps:
</p>
<ol>
<li>If |manifest|["note_taking"] does not [=map/exist=], return.
</li>
<li>If |manifest|["note_taking"]["new_note_url"] does not
[=map/exist=], return.
</li>
<li>If the type of |manifest|["note_taking"]["new_note_url"] is not
[=URL=], return.
</li>
<li>Let |browsing context:Browsing Context| be the result of creating
a new [=top-level browsing context=].
</li>
<li>[=Navigate=] |browsing context| to resource
|manifest|["note_taking"]["new_note_url"].
</li>
</ol>
</section>
</section>
<section>
<h2>
`protocol_handlers` member
</h2>
<p>
The [=manifest's=] <code><dfn data-dfn-for=
"manifest">protocol_handlers</dfn></code> member is an array of
<a>protocol handler description</a>s that allows a web application to
handle URL protocols.
</p>
<p>
On installation, a user agent SHOULD register protocol handlers with
the Operating System via interactions that are consistent with:
</p>
<ul>
<li>If there are multiple registered handlers for a protocol, the OS
allows the user to select which app should open it, and also allows the
user to set a default app.
</li>
<li>Clicking on a registered protocol will launch the registered
application. If this is the web app, then execute the [=invoke a
protocol handler=] steps defined in [=HTML=], where the user agent
SHOULD navigate to [=url=] and the appropriate browsing context is set
to a new top level browsing context.
</li>
</ul>
<aside class="note">
Protocol handlers could, for instance, be used for web app
communication where one app directly invokes another and passes data
via custom protocol links.
</aside>
<section>
<h3>
Processing the `protocol_handlers` member
</h3>
<p>
To <dfn>process the `protocol_handlers` member</dfn>, given
[=object=] |json:JSON|, |manifest:ordered map|:
</p>
<ol>
<li>Let |processedProtocolHandlers| be a new [=list=] of
|json:JSON|["|protocol_handlers|"].
</li>
<li>Set manifest["|protocol_handlers|"] to
|processedProtocolHandlers|.
</li>
<li>[=list/For each=] |protocol_handler| (<a>protocol handler
description</a>):
<ol>
<li>If |protocol_handler|["protocol"] or
|protocol_handler|["url"] is undefined, [=iteration/continue=].
</li>
<li>Let (<dfn>normalizedProtocol</dfn>, <dfn>normalizedUrl</dfn>)
be the result of running [=normalize protocol handler
parameters=] with |protocol_handler|["protocol"], |
protocol_handler|["url"] using |manifest URL| as the base URL,
and [=this=]'s relevant [=environment settings object=]. If the
result is failure, [=iteration/continue=].
</li>
<li>If [=normalizedUrl=] is not [=manifest/within scope=] of
|manifest|, [=iteration/continue=].
</li>
<li>If |processedProtocolHandlers| [=list/contains=] the
[=normalizedUrl=], [=iteration/continue=].
</li>
<li>[=List/Append=] |protocol_handler| to
|processedProtocolHandlers|.
</li>
</ol>
</li>
<li>[=list/For each=] |processedProtocolHandlers|, the user agent
SHOULD [=register a protocol handler=].
</li>
</ol>
<p>
A user agent SHOULD ask users for permission before registering a
[=protocol handler description=] <var>protocol_handler</var>s as the
default handler for a protocol with the host operating system. A user
agent MAY truncate the list of [=protocol handler description=]
<var>protocol_handlers</var> presented in order to remain consistent
with the conventions or limitations of the host operating system.
</p>
<aside class="example">
<p>
In the following example, the developer has included two [=protocol
handler description=] <var>protocol_handler</var>s. Assuming the
the manifest's URL is
<samp>https://example.com/manifest.webmanifest</samp>:
</p>
<ul>
<li>The first protocol handler would register to handle "web+music"
URLs (e.g.: web+music://#1234). When activated, the user agent
would instantiate a new[=top-level browsing context=] and navigate
to
<samp>https://example.com/play?songId=web+music://%231234</samp>.
</li>
<li>The second protocol handler would be ignored, as the protocol
provided does not start with "web+" and is not part of the
[=safelisted schemes=].
</li>
</ul>
<pre class="json">
{
"protocol_handlers": [
{
"protocol": "web+music",
"url": "/play?songId=%s"
},
{
"protocol": "store",
"url": "/buy?songId=%s"
}
]
}
</pre>
</aside>
</section>
<section>
<h2>
ProtocolHandler items
</h2>
<p>
Each <dfn>protocol handler description</dfn> is an [=object=] that
represents a protocol that the web application wants to handle. It
has the following members:
</p>
<ul>
<li>[=`protocol`=]
</li>
<li>[=`url`=]
</li>
</ul>
<p>
A user agent SHOULD use these values to register the web application
as a handler with the operating system. When the user activates a
protocol handler URL, the user agent SHOULD run <a>handling a
protocol launch</a>.
</p>
<p class="note">
[[HTML]]'s {{NavigatorContentUtils/registerProtocolHandler()}} allows
web sites to register themselves as possible handlers for particular
protocols. What constitutes valid <code>protocol</code> and
<code>url</code> values for <a>protocol handler description</a>s is
defined in that API. Also note that the [[HTML]] API uses
[=url/scheme=] where we use <code>protocol</code> but the same
restrictions apply.
</p>
<section>
<h3>
`protocol` member
</h3>
<p>
The <dfn>protocol</dfn> member of a <a>protocol handler
description</a> is a <a>string</a> that represents the protocol to
be handled, such as `mailto` or `web+auth`.
</p>
<p>
The <a>protocol</a> member of a <a>protocol handler description</a>
is equivalent to
{{NavigatorContentUtils/registerProtocolHandler()}}'s |scheme|
argument defined in [[HTML]].
</p>
</section>
<section>
<h3>
`url` member
</h3>
<p>
The <dfn>url</dfn> member of a <a>protocol handler description</a>
is the <a>URL</a> [=manifest/within scope=] of the application that
opens when the associated protocol is activated.
</p>
<p>
The <a>url</a> member of a <a>protocol handler description</a> is
equivalent to {{NavigatorContentUtils/registerProtocolHandler()}}'s
<code>url</code> argument defined in [[HTML]].
</p>
</section>
<section>
<h3>
<dfn>Handling a protocol launch</dfn>
</h3>
<p>
When a <a>protocol handler description</a>
<var>protocol_handler</var> having [=manifest=] <var>manifest</var>
is invoked, it goes through the same steps used to [=invoke a
protocol handler=] defined in [=HTML=], where the user agent SHOULD
navigate to [=url=] and the appropriate browsing context is set to
a new top level browsing context.
</p>
</section>
</section>
<section>
<h2>
Privacy consideration: Default protocol handler
</h2>
<p>
Depending on the operating system capabilities, the protocol handler
could become a 'default' handler (e.g. handling launches of a given
protocol automatically) of a given protocol without the explicit
knowledge of the user. To protect against possible misuse, user
agents MAY employ protections such as:
</p>
<ul>
<li>Requiring explicit user consent before executing the process to
[=invoke a protocol handler=].
</li>
<li>Removing the web application's OS registration as a protocol
handling entity, either in response to the above dialog or by user
action.
</li>
<li>Confirming protocol handler registrations on [=installation=].
</li>
</ul>
<p>
If a user agent removes the the registration of the protocol handler
entity it SHOULD provide UX for the user to re-register the web app
and protocol with the operating system.
</p>
</section>
</section>
<section data-cite="DOM">
<h2>
Installation prompts
</h2>
<p>
There are multiple ways that the installation process can be triggered:
</p>
<ul>
<li>An end-user can <dfn data-lt="manual installation">manually</dfn>
trigger the installation process through the user agent's
<abbr title="User Interface">UI</abbr>, directly invoking the steps
to <a>present an install prompt</a>.
</li>
<li>The installation process can occur through an <dfn>automated
install prompt</dfn>: that is, a UI that the user agent presents to the
user when, for instance, there are sufficient <a>installability
signals</a> to warrant installation of the web application.
</li>
<li>The installation process can occur through a <dfn>site-triggered
install prompt</dfn>: the site can programmatically request that the
user agent present an install prompt to the user. The user agent MAY
restrict the availability of this feature to cases where, for instance,
there are sufficient signals to warrant [=installed web
application|installation=] of the web application.
</li>
</ul>
<p>
In any case, the user agent MUST NOT <a>present an install prompt</a>
if the document is not installable.
</p>
<p>
The user agent MAY, at any time (only if the document is installable),
run the <a>steps to notify that an install prompt is available</a> at
any time, giving the site the opportunity to show a <a>site-triggered
install prompt</a> without the user needing to interact with the user
agent UI.
</p>
<p>
To <dfn data-local-lt=
"presenting an install prompt|presentation of the install prompt">present
an install prompt</dfn>:
</p>
<ol>
<li>Show some user-agent-specific UI, asking the user whether to
proceed with installing the app. The <var>result</var> of this choice
is either {{AppBannerPromptOutcome/"accepted"}} or
{{AppBannerPromptOutcome/"dismissed"}}.
</li>
<li>Return <var>result</var>, and <a>in parallel</a>:
<ol>
<li>If <var>result</var> is {{AppBannerPromptOutcome/"accepted"}},
run the <a>steps to install the web application</a>.
</li>
</ol>
</li>
</ol>
<p>
The <dfn>steps to notify that an install prompt is available</dfn> are
given by the following algorithm:
</p>
<ol>
<li>Wait until the {{Document}} of the <a>top-level browsing
context</a> is <a data-cite="html#completely-loaded">completely
loaded</a>.
</li>
<li>If there is already an <a data-lt=
"present an install prompt">install prompt being presented</a> or if
the <a>steps to install the web application</a> are currently being
executed, then abort this step.
</li>
<li>
<a>Queue a task</a> on the <a>application life-cycle task source</a>
to do the following:
<ol>
<li>Let |mayShowPrompt| be the result of [=fire an event=] named
`"beforeinstallprompt"` at the [=top-level browsing context=]'s
[=relevant global object=] using the {{BeforeInstallPromptEvent}}
interface, with steps to initialize the {{Event/cancelable}}
attribute to `true`.
</li>
<li>If |mayShowPrompt| is true, then the user agent MAY, <a>in
parallel</a>, <a>request to present an install prompt</a> with
|event|.
</li>
</ol>
</li>
</ol>
</section>
<section data-cite="DOM">
<h2>
Installable web applications
</h2>
<section>
<h2>
<dfn>Installation</dfn> process
</h2>
<p>
The <dfn>steps to install the web application</dfn> are given by the
following algorithm:
</p>
<ol>
<li>Let <var>manifest</var> be the manifest of an installable
document.
</li>
<li>Perform an unspecified sequence of actions to attempt to register
the web application in the user's operating system (e.g., create
shortcuts that launch the web application, register the application
in the system uninstall menu, etc.). If the installation fails (which
can be for any reason, for example, the OS denying permission to the
user agent to add an icon to the home screen of the device), abort
these steps.
</li>
<li>
<a>Queue a task</a> on the <a>application life-cycle task
source</a> to <a>fire an event</a> named `"appinstalled"` at the
[=top-level browsing context=]'s [=relevant global object=] for
which the installation took place.
</li>
</ol>
</section>
<section class="informative">
<h3 id="installability-signals">
Installability signals
</h3>
<p>
By design, this specification does not provide developers with an
explicit API to "install" a web application. Instead, a
<a>manifest</a> can serve as an <dfn>installability signal</dfn> to a
user agent that a web application can be installed.
</p>
<p>
Examples of <a>installability signals</a> for a web application:
</p>
<ul>
<li>has a [=application manifest=] with an application name and a
suitable icon.
</li>
<li>is served over a secure network connection, but also functions
without a network connection.
</li>
<li>has a sensible content security policy.
</li>
<li>is able to responsively adapt to display on a variety of screen
sizes, catering for both mobile and desktop.
</li>
<li>shows a high degree of end-user engagement over an extended
period of time.
</li>
<li>has been explicitly marked by the user as one that they value and
trust (e.g., by bookmarking or "starring" it).
</li>
</ul>
<p>
This list is not exhaustive and some <a>installability signals</a>
might not apply to all user agents. How a user agent makes use of
these <a>installability signals</a> to determine if a web application
can be installed is left to implementers.
</p>
</section>
</section>
<section>
<h2>
Installation Events
</h2>
<p>
[=event|Events=] of this specification rely on the <dfn>application
life-cycle task source</dfn>.
</p>
<section data-dfn-for="BeforeInstallPromptEvent">
<h3>
<dfn>BeforeInstallPromptEvent</dfn> Interface
</h3>
<div class="note">
The <a>beforeinstallprompt</a> event is somewhat misnamed, as it does
not necessarily signal that a <a>manual installation</a> will follow
(depending on the user agent, it might just be giving the site the
ability to trigger an install prompt). It is so named for historical
reasons.
</div>
<pre class="idl" data-cite="DOM">
[Exposed=Window]
interface BeforeInstallPromptEvent : Event {
constructor(DOMString type, optional EventInit eventInitDict = {});
Promise<PromptResponseObject> prompt();
};
dictionary PromptResponseObject {
AppBannerPromptOutcome userChoice;
};
enum AppBannerPromptOutcome {
"accepted",
"dismissed"
};
</pre>
<p>
The {{BeforeInstallPromptEvent}} is dispatched when the site is
allowed to present a <a>site-triggered install prompt</a>, or prior
to the user agent presenting an <a>automated install prompt</a>. It
allows the site to cancel the <a>automated install prompt</a>, as
well as manually present the <a>site-triggered install prompt</a>.
</p>
<div class="note">
If the {{BeforeInstallPromptEvent}} is <em>not</em> cancelled, the
user agent is allowed to <a>present an install prompt</a>
(specifically, an <a>automated install prompt</a>) to the end-user.
Canceling the default action (via {{Event/preventDefault()}})
prevents the user agent from <a>presenting an install prompt</a>. The
user agent is free to run <a>steps to notify that an install prompt
is available</a> again at a later time.
</div>
<p>
The <dfn>PromptResponseObject</dfn> contains the result of calling
{{BeforeInstallPromptEvent/prompt()}}. It contains one member,
<dfn>userChoice</dfn>, which states the user's chosen outcome.
</p>
<p>
An instance of a {{BeforeInstallPromptEvent}} has the following
internal slots:
</p>
<dl data-dfn-for="BeforeInstallPromptEvent">
<dt>
<dfn>[[\didPrompt]]</dfn>
</dt>
<dd>
A boolean, initially `false`. Represents whether this event was
used to <a>present an install prompt</a> to the end-user.
</dd>
<dt>
<dfn>[[\userResponsePromise]]</dfn>
</dt>
<dd>
A promise that represents the outcome of <a>presenting an install
prompt</a>.
</dd>
</dl>
<section>
<h4>
<code>prompt()</code> method
</h4>
<p>
The <dfn>prompt</dfn> method, when called, runs the following
steps:
</p>
<ol>
<li>Let |userResponsePromise| be
{{BeforeInstallPromptEvent/[[userResponsePromise]]}}.
</li>
<li>If |userResponsePromise| is pending:
<ol>
<li>If [=this=].{{BeforeInstallPromptEvent/[[didPrompt]]}} is
`true`, terminate this algorithm.
</li>
<li>If this event's {{Event/isTrusted}} attribute is `false`,
reject |userResponsePromise| with {{"NotAllowedError"}} and
terminate this algorithm.
</li>
<li>Set [=this=].{{BeforeInstallPromptEvent/[[didPrompt]]}} to
`true`.
</li>
<li>
<a>In parallel</a>, <a>request to present an install
prompt</a> with [=this=]. Wait, possibly indefinitely, for
the end-user to make a choice.
</li>
</ol>
</li>
<li>Return |userResponsePromise|.
</li>
</ol>
<p>
To <dfn data-noexport="">request to present an install prompt</dfn>
with {{BeforeInstallPromptEvent}} <var>event</var>:
</p>
<ol>
<li>
<a>Present an install prompt</a> and let |outcome| be the result.
</li>
<li>Let |response| be a newly created {{PromptResponseObject}},
initializing its {{PromptResponseObject/userChoice}} to |outcome|.
</li>
<li>[=Resolve=]
|event|.{{BeforeInstallPromptEvent/[[userResponsePromise]]}} with
|response|.
</li>
</ol>
</section>
<section class="informative">
<h4>
Usage example
</h4>
<p>
This example shows how one might prevent an automated install
prompt from showing until the user clicks a button to show a
<a>site-triggered install prompt</a>. 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.
</p>
<pre class="example" title=
"Using beforeinstallprompt to present an install button">
window.addEventListener("beforeinstallprompt", event => {
// Suppress automatic prompting.
event.preventDefault();
// 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}`);
});
});
</pre>
</section>
<section data-dfn-for="AppBannerPromptOutcome">
<h4>
<code>AppBannerPromptOutcome</code> enum
</h4>
<p>
The <dfn>AppBannerPromptOutcome</dfn> enum's values represent the
outcomes from <a>presenting an install prompt</a>.
</p>
<dl>
<dt>
"<dfn>accepted</dfn>":
</dt>
<dd>
The end-user indicated that they would like the user agent to
install the web application.
</dd>
<dt>
"<dfn>dismissed</dfn>":
</dt>
<dd>
The end-user dismissed the install prompt.
</dd>
</dl>
</section>
</section>
<section>
<h3>
Extensions to the `Window` object
</h3>
<pre class="idl" data-cite="HTML">
partial interface Window {
attribute EventHandler onappinstalled;
attribute EventHandler onbeforeinstallprompt;
};
</pre>
<section data-dfn-for="Window">
<h4>
<code>onappinstalled</code> attribute
</h4>
<p>
The <dfn>onappinstalled</dfn> <a>event handler IDL attribute</a>
handles "<dfn class="event">appinstalled</dfn>" events.
</p>
</section>
<section>
<h4>
<code>onbeforeinstallprompt</code> attribute
</h4>
<p>
The <dfn>onbeforeinstallprompt</dfn> <a>event handler IDL
attribute</a> handles "<dfn class=
"event">beforeinstallprompt</dfn>" events.
</p>
</section>
</section>
</section>
<section id="conformance"></section>
</body>
</html>