-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathindex.html
More file actions
2157 lines (2151 loc) · 89.8 KB
/
index.html
File metadata and controls
2157 lines (2151 loc) · 89.8 KB
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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>
Push API
</title>
<meta charset="utf-8">
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script class="remove">
// See http://www.w3.org/respec/ for ReSpec documentation.
var respecConfig = {
specStatus: "ED",
shortName: "push-api",
previousMaturity: "WD",
editors: [
{
name: "Peter Beverloo",
company: "Google",
companyURL: "https://www.google.com/",
w3cid: "44819",
retiredDate: "2025-09-25"
},
{
name: "Martin Thomson",
company: "Mozilla Foundation",
companyURL: "https://www.mozilla.org/",
w3cid: "68503",
retiredDate: "2025-09-25"
},
{
name: "Marcos Caceres",
company: "Apple Inc.",
companyURL: "https://www.apple.com/",
w3cid: "39125"
},
{
name: "Bryan Sullivan",
company: "AT&T",
companyURL: "http://www.att.com/",
retiredDate: "2015-05-01",
},
{
name: "Eduardo Fullea",
company: "Telefonica",
companyURL: "http://www.telefonica.com/",
retiredDate: "2015-05-01",
},
{
name: "Michaël van Ouwerkerk",
company: "Google",
companyURL: "https://www.google.com/",
retiredDate: "2016-11-08",
},
{
name: "Kagami Rosylight",
company: "Mozilla Foundation",
companyURL: "https://www.mozilla.org/",
w3cid: "107856"
}
],
group: "webapps",
github: "w3c/push-api",
xref: "web-platform",
};
</script>
</head>
<body data-cite=
"SERVICE-WORKERS FILEAPI SECURE-CONTEXTS HR-TIME PERMISSIONS ECMASCRIPT NOTIFICATIONS BADGING">
<section id="abstract">
<p>
The <cite>Push API</cite> enables sending of a <a>push message</a> to a web application via
a <a>push service</a>. An <a>application server</a> can send a <a>push message</a> at any
time, even when a web application or <a>user agent</a> is inactive. The <a>push service</a>
ensures reliable and efficient delivery to the <a>user agent</a>. <a>Push messages</a> are
delivered to a <a>Service Worker</a> that runs in the origin of the web application, which
can use the information in the message to update local state or display a notification to
the user.
</p>
<p>
This specification is designed for use with the <a>web push protocol</a>, which describes
how an <a>application server</a> or <a>user agent</a> interacts with a <a>push service</a>.
</p>
</section>
<section id="sotd"></section>
<section class="informative" id="introduction">
<h2>
Introduction
</h2>
<p>
The Push API allows a web application to communicate with a <a>user agent</a>
asynchronously. This allows an <a>application server</a> to provide the <a>user agent</a>
with time-sensitive information whenever that information becomes known, rather than
waiting for a user to open the web application.
</p>
<p>
As defined here, <a>push services</a> support delivery of <a>push messages</a> at any time.
</p>
<p>
In particular, a <a>push message</a> will be delivered to the web application even if that
web application is not currently active in a browser window: this relates to use cases in
which the user may close the web application, but still benefits from the web application
being able to be restarted when a <a>push message</a> is received. For example, a <a>push
message</a> might be used to inform the user of an incoming WebRTC call.
</p>
<p>
A <a>push message</a> can also be sent when the <a>user agent</a> is temporarily offline.
In support of this, the <a>push service</a> stores messages for the <a>user agent</a> until
the <a>user agent</a> becomes available. This supports use cases where a web application
learns of changes that occur while a user is offline and ensures that the <a>user agent</a>
can be provided with relevant information in a timely fashion. <a>Push messages</a> are
stored by the <a>push service</a> until the <a>user agent</a> becomes reachable and the
message can be delivered.
</p>
<p>
The Push API will also ensure reliable delivery of push messages while a <a>user agent</a>
is actively using a web application, for instance if a user is actively using the web
application or the web application is in active communication with an <a>application
server</a> through an active worker, frame, or background window. This is not the primary
use case for the Push API. A web application might choose to use the Push API for
infrequent messages to avoid having to maintain constant communications with the
<a>application server</a>.
</p>
<p>
Push messaging is best suited to occasions where there is not already an active
communications channel established between the <a>user agent</a> and the web application.
Sending <a>push messages</a> requires considerably more resources when compared with more
direct methods of communication such as the [[Fetch|Fetch API]] or [[WebSockets]]. <a>Push
messages</a> usually have higher latency than direct communications and they can also be
subject to restrictions on use. Most <a>push services</a> limit the size and quantity of
<a>push messages</a> that can be sent.
</p>
</section>
<section>
<h2>
Dependencies
</h2>
<p>
The <dfn>web push protocol</dfn> [[RFC8030]] describes a protocol that enables
communication between a <a>user agent</a> or <a>application server</a> and a <a>push
service</a>. Alternative protocols could be used in place of this protocol, but this
specification assumes the use of this protocol; alternative protocols are expected to
provide compatible semantics.
</p>
<p>
The <code><dfn>Content-Encoding</dfn></code> HTTP header, described in Section 8.4 of
[[RFC9110]], indicates the content coding applied to the payload of a <a>push message</a>.
</p>
</section>
<section>
<h2>
Concepts
</h2>
<section>
<h2>
Application server
</h2>
<p>
The term <dfn>application server</dfn> refers to server-side components of a web
application.
</p>
</section>
<section>
<h2>
Push message
</h2>
<p>
A <dfn>push message</dfn> is data sent to a web application from an <a>application
server</a>.
</p>
<p>
A <a>push message</a> is delivered to the [=service worker registration/active worker=]
associated with the <a>push subscription</a> to which the message was submitted. If the
service worker is not currently running, the worker is started to enable delivery.
</p>
</section>
<section>
<h2>
Declarative push message
</h2>
<p>
A <dfn>declarative push message</dfn> is a [=push message=] whose data is a JSON document
that is understood by the user agent. A user agent opportunistically parses each incoming
[=push message=] to determine if it is a [=declarative push message=] using the
[=declarative push message parser=].
</p>
<p>
A [=declarative push message=] allows for the creation and display of a notification
without the involvement of a service worker. Nevertheless, a service worker can still be
involved if desired by the [=application server=]. In such a scenario the declarative
nature of the [=push message=] serves as a backup in case the service worker was evicted
due to storage pressure, for instance. And also provides a more object-oriented approach
to transmitting notification data.
</p>
<pre class="example">
{
"web_push": 8030,
"notification": {
"title": "Ada emailed ‘London’",
"lang": "en-US",
"dir": "ltr",
"body": "Did you hear about the tube strikes?",
"navigate": "https://email.example/message/12"
}
}
</pre>
<section>
<h3>
Members
</h3>
<p>
A [=declarative push message=] has the following members:
</p>
<dl>
<dt>
<code>web_push</code> (required)
</dt>
<dd>
<p>
An integer that must be 8030. Used to disambiguate a [=declarative push message=]
from other JSON documents.
</p>
</dd>
<dt>
<code>notification</code> (required)
</dt>
<dd>
<p>
A JSON object consisting of the following members, all analogous to Notifications
API features, though sometimes with a slightly stricter type. Apart from
<code>title</code> all members are derived from the {{NotificationOptions}}
dictionary and to be maintained in tandem. [[NOTIFICATIONS]]
</p>
<dl>
<dt>
<code>title</code> (required)
</dt>
<dd>
<p>
A string.
</p>
</dd>
<dt>
<code>dir</code>
</dt>
<dd>
<p>
"<code>auto</code>", "<code>ltr</code>", or "<code>rtl</code>".
</p>
</dd>
<dt>
<code>lang</code>
</dt>
<dd>
<p>
A string that holds a language tag.
</p>
</dd>
<dt>
<code>body</code>
</dt>
<dd>
<p>
A string.
</p>
</dd>
<dt>
<code>navigate</code> (required)
</dt>
<dd>
<p>
A string that holds a URL.
</p>
</dd>
<dt>
<code>tag</code>
</dt>
<dd>
<p>
A string.
</p>
</dd>
<dt>
<code>image</code>
</dt>
<dd>
<p>
A string that holds a URL.
</p>
</dd>
<dt>
<code>icon</code>
</dt>
<dd>
<p>
A string that holds a URL.
</p>
</dd>
<dt>
<code>badge</code>
</dt>
<dd>
<p>
A string that holds a URL.
</p>
</dd>
<dt>
<code>vibrate</code>
</dt>
<dd>
<p>
An array of [=/32-bit unsigned integers=].
</p>
</dd>
<dt>
<code>timestamp</code>
</dt>
<dd>
<p>
A [=/64-bit unsigned integer=].
</p>
</dd>
<dt>
<code>renotify</code>
</dt>
<dd>
<p>
A boolean.
</p>
</dd>
<dt>
<code>silent</code>
</dt>
<dd>
<p>
A boolean.
</p>
</dd>
<dt>
<code>requireInteraction</code>
</dt>
<dd>
<p>
A boolean.
</p>
<p class="note">
This is not named <code>require_interaction</code> for consistency with the
{{NotificationOptions}} dictionary.
</p>
</dd>
<dt>
<code>data</code>
</dt>
<dd>
<p>
Any JSON value.
</p>
</dd>
<dt>
<code>actions</code>
</dt>
<dd>
<p>
An array of JSON objects consisting of the following members, all derived from
the {{NotificationAction}} dictionary and to be maintained in tandem.
</p>
<dl>
<dt>
<code>action</code> (required)
</dt>
<dd>
<p>
A string.
</p>
</dd>
<dt>
<code>title</code> (required)
</dt>
<dd>
<p>
A string.
</p>
</dd>
<dt>
<code>navigate</code> (required)
</dt>
<dd>
<p>
A string that holds a URL.
</p>
</dd>
<dt>
<code>icon</code>
</dt>
<dd>
<p>
A string that holds a URL.
</p>
</dd>
</dl>
</dd>
</dl>
</dd>
<dt>
<code>mutable</code>
</dt>
<dd>
<p>
A boolean. When true causes a <code>push</code> event to be dispatched to a service
worker (if any) containing the {{Notification}} object described by the
<a>declarative push message</a>.
</p>
</dd>
</dl>
</section>
<section>
<h3>
Parser
</h3>
<p>
A <dfn>declarative push message parser result</dfn> is a [=/tuple=] consisting of a
<dfn data-dfn-for="declarative push message parser result">notification</dfn> (a
[=/notification=]) and a <dfn data-dfn-for=
"declarative push message parser result">mutable</dfn> (a boolean).
</p>
<p>
The <dfn>declarative push message parser</dfn> given a [=/byte sequence=]
<var>bytes</var>, [=/origin=] <var>origin</var>, [=/URL=] <var>baseURL</var>, and
{{EpochTimeStamp}} <var>fallbackTimestamp</var> runs these steps. They return failure
or a [=/declarative push message parser result=].
</p>
<ol>
<li>
<p>
Let <var>message</var> be the result of [=parse JSON bytes to an Infra
value|parsing JSON bytes to an Infra value=] given <var>bytes</var>. If that throws
an exception, then return failure.
</p>
</li>
<li>
<p data-cite="INFRA">
If <var>message</var> is not a [=/map=], then return failure.
</p>
</li>
<li>
<p>
If <var>message</var>["`web_push`"] does not [=map/exist=] or is not 8030, then
return failure.
</p>
</li>
<li>
<p>
If <var>message</var>["`notification`"] does not [=map/exist=], then return
failure.
</p>
</li>
<li>
<p>
Let <var>notificationInput</var> be <var>message</var>["`notification`"].
</p>
</li>
<li>
<p data-cite="INFRA">
If <var>notificationInput</var> is not a [=/map=], then return failure.
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`title`"] does not [=map/exist=] or is not a
string, then return failure.
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`navigate`"] does not [=map/exist=] or is not a
string, then return failure.
</p>
</li>
<!-- We could also handle this the same way as any other NotificationOptions members as we still need to check that the final notification has a navigation URL regardless, but it seems better to illustrate early failures are possible. -->
<li>
<p>
Let <var>notificationTitle</var> be <var>notificationInput</var>["`title`"].
</p>
</li>
<li>
<p>
Let <var>notificationOptions</var> be a {{NotificationOptions}} dictionary.
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`dir`"] [=map/exists=] and is "`auto`", "`ltr`",
or "`rtl`", then set <var>notificationOptions</var>["{{NotificationOptions/dir}}"]
to <var>notificationInput</var>["`dir`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`lang`"] [=map/exists=] and is a string, then set
<var>notificationOptions</var>["{{NotificationOptions/lang}}"] to
<var>notificationInput</var>["`lang`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`body`"] [=map/exists=] and is a string, then set
<var>notificationOptions</var>["{{NotificationOptions/body}}"] to
<var>notificationInput</var>["`body`"].
</p>
</li>
<li>
<p>
Set <var>notificationOptions</var>["{{NotificationOptions/navigate}}"] to
<var>notificationInput</var>["`navigate`"], [=string/converted=].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`tag`"] [=map/exists=] and is a string, then set
<var>notificationOptions</var>["{{NotificationOptions/tag}}"] to
<var>notificationInput</var>["`tag`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`image`"] [=map/exists=] and is a string, then set
<var>notificationOptions</var>["{{NotificationOptions/image}}"] to
<var>notificationInput</var>["`image`"], [=string/converted=].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`icon`"] [=map/exists=] and is a string, then set
<var>notificationOptions</var>["{{NotificationOptions/icon}}"] to
<var>notificationInput</var>["`icon`"], [=string/converted=].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`badge`"] [=map/exists=] and is a string, then set
<var>notificationOptions</var>["{{NotificationOptions/badge}}"] to
<var>notificationInput</var>["`badge`"], [=string/converted=].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`vibrate`"] [=map/exists=] and is a [=/list=] of
which each [=list/item=] is a [=/32-bit unsigned integer=], then set
<var>notificationOptions</var>["{{NotificationOptions/vibrate}}"] to
<var>notificationInput</var>["`vibrate`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`timestamp`"] [=map/exists=] and is a [=/64-bit
unsigned integer=], then set
<var>notificationOptions</var>["{{NotificationOptions/timestamp}}"] to
<var>notificationInput</var>["`timestamp`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`renotify`"] [=map/exists=] and is a boolean, then
set <var>notificationOptions</var>["{{NotificationOptions/renotify}}"] to
<var>notificationInput</var>["`renotify`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`silent`"] [=map/exists=] and is a boolean, then
set <var>notificationOptions</var>["{{NotificationOptions/silent}}"] to
<var>notificationInput</var>["`silent`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`requireInteraction`"] [=map/exists=] and is a
boolean, then set
<var>notificationOptions</var>["{{NotificationOptions/requireInteraction}}"] to
<var>notificationInput</var>["`requireInteraction`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`data`"] [=map/exists=], then set
<var>notificationOptions</var>["{{NotificationOptions/data}}"] to the result of
running <a>convert an Infra value to a JSON-compatible JavaScript value</a> given
<var>notificationInput</var>["`data`"].
</p>
</li>
<li>
<p>
If <var>notificationInput</var>["`actions`"] [=map/exists=] and is a [=/list=]:
</p>
<ol>
<li>
<p>
Let <var>notificationActions</var> be « ».
</p>
</li>
<li>
<p>
[=list/For each=] <var>actionInput</var> of
<var>notificationInput</var>["`actions`"]:
</p>
<ol>
<li>
<p>
If <var>actionInput</var>["`action`"] does not [=map/exist=] or is not a
string, then [=iteration/continue=].
</p>
</li>
<li>
<p>
If <var>actionInput</var>["`title`"] does not [=map/exist=] or is not a
string, then [=iteration/continue=].
</p>
</li>
<li>
<p>
If <var>actionInput</var>["`navigate`"] does not [=map/exist=] or is not a
string, then [=iteration/continue=].
</p>
</li>
<!-- We still need to check the final action for a navigation URL regardless, but failing early seems good as per above. -->
<li>
<p>
Let <var>actionNavigate</var> be <var>actionInput</var>["`navigate`"],
[=string/converted=].
</p>
</li>
<li>
<p>
Let <var>notificationAction</var> be the {{NotificationAction}} dictionary
«[ "{{NotificationAction/action}}" → <var>actionInput</var>["`action`"],
"{{NotificationAction/title}}" → <var>actionInput</var>["`title`"],
"{{NotificationAction/navigate}}" → <var>actionNavigate</var> ]».
</p>
</li>
<!-- Initialize the dictionary mostly at once here to account for required members. -->
<li>
<p>
If <var>actionInput</var>["`icon`"] [=map/exists=] and is a string, then
set <var>notificationAction</var>["{{NotificationAction/icon}}"] to
<var>actionInput</var>["`icon`"], [=string/converted=].
</p>
</li>
<li>
<p>
[=list/Append=] <var>notificationAction</var> to
<var>notificationActions</var>.
</p>
</li>
</ol>
</li>
<li>
<p>
Set <var>notificationOptions</var>["{{NotificationOptions/actions}}"] to
<var>notificationActions</var>.
</p>
</li>
</ol>
</li>
<li>
<p>
Let <var>notification</var> be the result of <a data-lt=
"create a notification">creating a notification</a> given
<var>notificationTitle</var>, <var>notificationOptions</var>, <var>origin</var>,
<var>baseURL</var>, and <var>fallbackTimestamp</var>. If this throws an exception,
then return failure.
</p>
</li>
<li>
<p>
If <var>notification</var>'s [=notification/navigation URL=] is null, then return
failure.
</p>
</li>
<li>
<p>
If the [=notification action/navigation URL=] of any [=/notification action=] of
<var>notification</var>'s [=notification/actions=] is null, then return failure.
</p>
</li>
<li>
<p>
Let <var>mutable</var> be false.
</p>
</li>
<li>
<p>
If <var>message</var>["`mutable`"] [=map/exists=] and
<var>message</var>["`mutable`"] is a boolean, then set <var>mutable</var> to
<var>message</var>["`mutable`"].
</p>
</li>
<li>
<p>
Return (<var>notification</var>, <var>mutable</var>).
</p>
</li>
</ol>
</section>
</section>
<section>
<h2>
Push subscription
</h2>
<p>
A <dfn>push subscription</dfn> is a message delivery context established between the
<a>user agent</a> and the <a>push service</a> on behalf of a web application.
</p>
<p>
A [=push subscription=] has an associated <dfn data-dfn-for=
"push subscription">scope</dfn>, which is a [=/URL=].
</p>
<p>
A [=push subscription=] is considered to have a <dfn data-dfn-for=
"push subscription">window-accessible scope</dfn> when its [=push subscription/scope=]'s
[=url/path=] is a [=/list=] of [=list/size=] 1 and [=push subscription/scope=]'s
[=url/path=][0] is the empty string.
</p>
<p class="note">
I.e., the [=url/path=] component of the [=/URL=] serializes as "`/`".
</p>
<p>
A <a>push subscription</a> has an associated <dfn>push endpoint</dfn>. It MUST be the
absolute URL exposed by the <a>push service</a> where the <a>application server</a> can
send <a>push messages</a> to. A <a>push endpoint</a> MUST uniquely identify the <a>push
subscription</a>.
</p>
<p>
A <a>push subscription</a> MAY have an associated <dfn>subscription expiration
time</dfn>. When set, it MUST be the time, in milliseconds since 00:00:00 UTC on 1
January 1970, at which the subscription will be <a>deactivated</a>. The <a>user agent</a>
SHOULD attempt to <a>refresh</a> the push subscription before the subscription expires.
</p>
<p>
A <a>push subscription</a> has internal slots for a P-256 <a>ECDH</a> key pair and an
authentication secret in accordance with [[RFC8291]]. These slots MUST be populated when
creating the <a>push subscription</a>.
</p>
<p>
If the <a>user agent</a> has to change the keys of a [=push subscription=] for any reason
and the [=push subscription=]'s [=associated service worker registration=] is non-null,
it MUST [=refresh=] the [=push subscription=].
</p>
<p>
To <dfn>create a push subscription</dfn>, given an {{PushSubscriptionOptionsInit}}
|optionsDictionary:PushSubscriptionOptionsInit|:
</p>
<ol class="algorithm">
<li>Let |subscription:PushSubscription| be a new {{PushSubscription}}.
</li>
<li>Let |options:PushSubscriptionOptions| be a newly created {{PushSubscriptionOptions}}
object, initializing its attributes with the corresponding members and values of
|optionsDictionary|.
</li>
<li>Set |subscription|'s {{PushSubscription/options}} attribute to |options|.
</li>
<li>Generate a new P-256 <a>ECDH</a> key pair [[ANSI-X9-62]]. Store the private key in an
internal slot on |subscription|; this value MUST NOT be made available to applications.
The public key is also stored in an internal slot and can be retrieved by calling the
{{PushSubscription/getKey()}} method of the {{PushSubscription}} with an argument of
{{PushEncryptionKeyName/"p256dh"}}.
</li>
<li>Generate a new authentication secret, which is a sequence of octets as defined in
[[RFC8291]]. Store the authentication secret in an internal slot on |subscription|. This
key can be retrieved by calling the {{PushSubscription/getKey()}} method of the
{{PushSubscription}} with an argument of {{PushEncryptionKeyName/"auth"}}.
</li>
<li>Request a new <a>push subscription</a>. Include the
{{PushSubscriptionOptions/applicationServerKey}} attribute of |options| when it has been
set. Rethrow any [=exceptions=].
</li>
<li>When the <a>push subscription</a> request has completed successfully:
<ol>
<li>Set |subscription|'s {{PushSubscription/endpoint}} attribute to the <a>push
subscription</a>'s <a>push endpoint</a>.
</li>
<li>If provided by the <a>push subscription</a>, set |subscription|'s
{{PushSubscription/expirationTime}}.
</li>
</ol>
</li>
<li>Return |subscription|.
</li>
</ol>
<section>
<h2>
Relationship to service worker registrations
</h2>
<p>
A [=push subscription=]'s <dfn>associated service worker registration</dfn> is the
[=service worker registration=] whose [=service worker registration/scope URL=]
[=URL/equals=] the [=push subscription=]'s [=push subscription/scope=], if any;
otherwise null.
</p>
<p class="note">
A [=push subscription=]'s [=associated service worker registration=] can only be null
when it has a [=push subscription/window-accessible scope=].
</p>
<p>
And vice versa, a [=service worker registration=]'s <dfn>associated push
subscription</dfn> is the [=push subscription=] whose [=push subscription/scope=]
[=URL/equals=] the [=service worker registration=]'s [=service worker
registration/scope URL=], if any; otherwise null.
</p>
</section>
<section>
<h2>
Subscription refreshes
</h2>
<p>
A <a>user agent</a> or <a>push service</a> MAY choose to <dfn>refresh</dfn> a <a>push
subscription</a> whose [=associated service worker registration=] is non-null at any
time, for example because it has reached a certain age.
</p>
<p>
When this happens, the <a>user agent</a> MUST run the steps to <a>create a push
subscription</a> given the <a>PushSubscriptionOptions</a> that were provided for
creating the current <a>push subscription</a>, and set the new [=push subscription=]'s
[=push subscription/scope=] to the original subscription's [=push subscription/scope=].
The new <a>push subscription</a> MUST have a key pair that's different from the
original subscription.
</p>
<p>
When successful, <a>user agent</a> then MUST <a>fire the "`pushsubscriptionchange`"
event</a> with the <a>service worker registration</a> associated with the <a>push
subscription</a> as |registration|, a {{PushSubscription}} instance representing the
initial <a>push subscription</a> as |oldSubscription| and a {{PushSubscription}}
instance representing the new <a>push subscription</a> as |newSubscription|.
</p>
<p>
To allow for time to propagate changes to <a>application servers</a>, a <a>user
agent</a> MAY continue to accept messages for an old <a>push subscription</a> for a
brief time after a refresh. Once messages have been received for a refreshed <a>push
subscription</a>, any old <a>push subscriptions</a> MUST be <a>deactivated</a>.
</p>
<p>
If the <a>user agent</a> is not able to refresh the <a>push subscription</a>, it SHOULD
periodically retry the refresh. When the <a>push subscription</a> can no longer be
used, for example because it has expired, the <a>user agent</a> MUST <a>fire the
"`pushsubscriptionchange`" event</a> with the <a>service worker registration</a>
associated with the <a>push subscription</a> as |registration|, a {{PushSubscription}}
instance representing the deactivating <a>push subscription</a> as |oldSubscription|
and `null` as the |newSubscription|.
</p>
</section>
<section>
<h2>
Subscription deactivation
</h2>
<p>
When a <a>push subscription</a> is <dfn data-lt="deactivate">deactivated</dfn>, both
the <a>user agent</a> and the <a>push service</a> MUST delete any stored copies of its
details. Subsequent <a>push messages</a> for this <a>push subscription</a> MUST NOT be
delivered.
</p>
<p>
A <a>push subscription</a> without a [=push subscription/window-accessible scope=] MUST
be <a>deactivated</a> when its associated <a>service worker registration</a> is
unregistered, though a <a>push subscription</a> MAY be <a>deactivated</a> earlier.
</p>
<p class="note">
A <a>push subscription</a> without a [=push subscription/window-accessible scope=] is
removed when <a>service worker registration</a> is cleared.
</p>
</section>
</section>
<section>
<h2>
Push service
</h2>
<p>
The term <dfn>push service</dfn> refers to a system that allows <a>application
servers</a> to send <a>push messages</a> to a web application. A push service serves the
<a>push endpoint</a> or <a data-lt="push endpoints">endpoints</a> for the <a>push
subscriptions</a> it serves.
</p>
<p>
The <a>user agent</a> connects to the <a>push service</a> used to create <a>push
subscriptions</a>. <a>User agents</a> MAY limit the choice of <a>push services</a>
available. Reasons for doing so include performance-related concerns such as service
availability (including whether services are blocked by firewalls in specific countries,
or networks at workplaces and the like), reliability, impact on battery lifetime, and
agreements to steer metadata to, or away from, specific <a>push services</a>.
</p>
</section>
<section>
<h2>
Permission
</h2>
<p>
The Push API is a [=powerful feature=] identified by the [=powerful feature/name=]
<dfn class="permission export">"push"</dfn>.
</p>
<p>
For integration with the [[[Permissions]]] specification, this specification defines the
{{PushPermissionDescriptor}} [=powerful feature/permission descriptor type=].
</p>
<pre class="idl">
dictionary PushPermissionDescriptor : PermissionDescriptor {
boolean userVisibleOnly = false;
};
</pre>
<p data-dfn-for="PushPermissionDescriptor">
The <dfn>userVisibleOnly</dfn> has the same semantics as
{{PushSubscriptionOptionsInit/userVisibleOnly}}.
</p>
<p>
`{name: "push", userVisibleOnly: false}` is [=PermissionDescriptor/stronger than=]
`{name: "push", userVisibleOnly: true}`.
</p>
</section>
</section>
<section>
<h2>
Security and privacy considerations
</h2>
<p>
The contents of a <a>push message</a> are encrypted [[RFC8291]]. However, the <a>push
service</a> is still exposed to the metadata of messages sent by an <a>application
server</a> to a <a>user agent</a> over a <a>push subscription</a>. This includes the
timing, frequency, and size of messages. Other than changing <a>push services</a>, which
user agents may disallow, the only known mitigation is to increase the apparent message
size by padding.
</p>
<p>
There is no guarantee that a <a>push message</a> was sent by an <a>application server</a>
having the same origin as the web application. The <a>application server</a> is able to
share the details necessary to use a <a>push subscription</a> with a third party at its own
discretion.
</p>
<p>
The following requirements are intended to protect the privacy and security of the user as
far as possible, and subject to meeting that goal, to protect the integrity of the
<a>application server</a>'s communication with the user.
</p>
<p>
The Push API may have to wake up the Service Worker associated with the <a>service worker
registration</a> in order to run the developer-provided event handlers. This can cause
resource usage, such as network traffic, that the <a>user agent</a> SHOULD attribute to the
web application that created the <a>push subscription</a>.
</p>
<p>
The <a>user agent</a> MAY consider the <a>PushSubscriptionOptions</a> when acquiring
permission or determining the permission status.
</p>
<p>
When a permission is revoked, the <a>user agent</a> MAY <a>fire the
"`pushsubscriptionchange`" event</a> for subscriptions created with that permission, with
the <a>service worker registration</a> associated with the <a>push subscription</a> as
|registration|, a {{PushSubscription}} instance representing the <a>push subscription</a>
as |oldSubscription|, and `null` as |newSubscription|. The <a>user agent</a> MUST
<a>deactivate</a> the affected subscriptions in parallel.
</p>
<p>
The <a>push endpoint</a> MUST NOT expose information about the user to be derived by actors
other than the <a>push service</a>, such as the user's device, identity or location. See
the Privacy Considerations in [[RFC8030]] for the exact requirements.
</p>
<p>
The <a>push endpoint</a> of a <a>deactivated</a> <a>push subscription</a> MUST NOT be
reused for a new <a>push subscription</a>. This prevents the creation of a persistent
identifier that the user cannot remove. This also prevents reuse of the details of one
<a>push subscription</a> to send <a>push messages</a> to another <a>push subscription</a>.
</p>
</section>
<section class="informative" id="pushframework">
<h2>
Push Framework
</h2>
<p>
A <a>push message</a> is sent from an <a>application server</a> to a web application as
follows:
</p>
<ul>
<li>the <a>application server</a> requests that the <a>push service</a> deliver a <a>push
message</a> using the [[RFC8030]]. This request uses the <a>push endpoint</a> included in
the <a>push subscription</a>;
</li>
<li>the <a>push service</a> delivers the message to a specific <a>user agent</a>,
identifying the <a>push endpoint</a> in the message;
</li>
<li>the <a>user agent</a> identifies the intended <a>Service Worker</a> and activates it as
necessary, and delivers the <a>push message</a> to the <a>Service Worker</a>.
</li>
</ul>
<p>
This overall framework allows <a>application servers</a> to activate a <a>Service
Worker</a> in response to events at the <a>application server</a>. Information about those
events can be included in the <a>push message</a>, which allows the web application to
react appropriately to those events, potentially without needing to initiate network
requests.
</p>
<p>
The following code and diagram illustrate a hypothetical use of the push API.
</p>
<section class="informative">
<h2>