-
Notifications
You must be signed in to change notification settings - Fork 4
/
draft_spec.2022.08.10.html
1622 lines (1524 loc) · 115 KB
/
draft_spec.2022.08.10.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
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">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<title>Document Picture-in-Picture Specification</title>
<meta content="w3c/UD" name="w3c-status">
<link href="https://www.w3.org/StyleSheets/TR/2021/W3C-UD" rel="stylesheet">
<link href="https://www.w3.org/2008/site/images/favicon.ico" rel="icon">
<meta content="Bikeshed version e8a706a4b, updated Fri Jul 15 11:08:03 2022 -0700" name="generator">
<link href="http://example.com/url-this-spec-will-live-at" rel="canonical">
<style>/* style-autolinks */
.css.css, .property.property, .descriptor.descriptor {
color: var(--a-normal-text);
font-size: inherit;
font-family: inherit;
}
.css::before, .property::before, .descriptor::before {
content: "‘";
}
.css::after, .property::after, .descriptor::after {
content: "’";
}
.property, .descriptor {
/* Don't wrap property and descriptor names */
white-space: nowrap;
}
.type { /* CSS value <type> */
font-style: italic;
}
pre .property::before, pre .property::after {
content: "";
}
[data-link-type="property"]::before,
[data-link-type="propdesc"]::before,
[data-link-type="descriptor"]::before,
[data-link-type="value"]::before,
[data-link-type="function"]::before,
[data-link-type="at-rule"]::before,
[data-link-type="selector"]::before,
[data-link-type="maybe"]::before {
content: "‘";
}
[data-link-type="property"]::after,
[data-link-type="propdesc"]::after,
[data-link-type="descriptor"]::after,
[data-link-type="value"]::after,
[data-link-type="function"]::after,
[data-link-type="at-rule"]::after,
[data-link-type="selector"]::after,
[data-link-type="maybe"]::after {
content: "’";
}
[data-link-type].production::before,
[data-link-type].production::after,
.prod [data-link-type]::before,
.prod [data-link-type]::after {
content: "";
}
[data-link-type=element],
[data-link-type=element-attr] {
font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace;
font-size: .9em;
}
[data-link-type=element]::before { content: "<" }
[data-link-type=element]::after { content: ">" }
[data-link-type=biblio] {
white-space: pre;
}</style>
<style>/* style-colors */
/* Any --*-text not paired with a --*-bg is assumed to have a transparent bg */
:root {
color-scheme: light dark;
--text: black;
--bg: white;
--unofficial-watermark: url(https://www.w3.org/StyleSheets/TR/2016/logos/UD-watermark);
--logo-bg: #1a5e9a;
--logo-active-bg: #c00;
--logo-text: white;
--tocnav-normal-text: #707070;
--tocnav-normal-bg: var(--bg);
--tocnav-hover-text: var(--tocnav-normal-text);
--tocnav-hover-bg: #f8f8f8;
--tocnav-active-text: #c00;
--tocnav-active-bg: var(--tocnav-normal-bg);
--tocsidebar-text: var(--text);
--tocsidebar-bg: #f7f8f9;
--tocsidebar-shadow: rgba(0,0,0,.1);
--tocsidebar-heading-text: hsla(203,20%,40%,.7);
--toclink-text: var(--text);
--toclink-underline: #3980b5;
--toclink-visited-text: var(--toclink-text);
--toclink-visited-underline: #054572;
--heading-text: #005a9c;
--hr-text: var(--text);
--algo-border: #def;
--del-text: red;
--del-bg: transparent;
--ins-text: #080;
--ins-bg: transparent;
--a-normal-text: #034575;
--a-normal-underline: #bbb;
--a-visited-text: var(--a-normal-text);
--a-visited-underline: #707070;
--a-hover-bg: rgba(75%, 75%, 75%, .25);
--a-active-text: #c00;
--a-active-underline: #c00;
--blockquote-border: silver;
--blockquote-bg: transparent;
--blockquote-text: currentcolor;
--issue-border: #e05252;
--issue-bg: #fbe9e9;
--issue-text: var(--text);
--issueheading-text: #831616;
--example-border: #e0cb52;
--example-bg: #fcfaee;
--example-text: var(--text);
--exampleheading-text: #574b0f;
--note-border: #52e052;
--note-bg: #e9fbe9;
--note-text: var(--text);
--noteheading-text: hsl(120, 70%, 30%);
--notesummary-underline: silver;
--assertion-border: #aaa;
--assertion-bg: #eee;
--assertion-text: black;
--advisement-border: orange;
--advisement-bg: #fec;
--advisement-text: var(--text);
--advisementheading-text: #b35f00;
--warning-border: red;
--warning-bg: hsla(40,100%,50%,0.95);
--warning-text: var(--text);
--amendment-border: #330099;
--amendment-bg: #F5F0FF;
--amendment-text: var(--text);
--amendmentheading-text: #220066;
--def-border: #8ccbf2;
--def-bg: #def;
--def-text: var(--text);
--defrow-border: #bbd7e9;
--datacell-border: silver;
--indexinfo-text: #707070;
--indextable-hover-text: black;
--indextable-hover-bg: #f7f8f9;
--outdatedspec-bg: rgba(0, 0, 0, .5);
--outdatedspec-text: black;
--outdated-bg: maroon;
--outdated-text: white;
--outdated-shadow: red;
--editedrec-bg: darkorange;
}</style>
<style>/* style-counters */
body {
counter-reset: example figure issue;
}
.issue {
counter-increment: issue;
}
.issue:not(.no-marker)::before {
content: "Issue " counter(issue);
}
.example {
counter-increment: example;
}
.example:not(.no-marker)::before {
content: "Example " counter(example);
}
.invalid.example:not(.no-marker)::before,
.illegal.example:not(.no-marker)::before {
content: "Invalid Example" counter(example);
}
figcaption {
counter-increment: figure;
}
figcaption:not(.no-marker)::before {
content: "Figure " counter(figure) " ";
}</style>
<style>/* style-dfn-panel */
:root {
--dfnpanel-bg: #ddd;
--dfnpanel-text: var(--text);
}
.dfn-panel {
position: absolute;
z-index: 35;
height: auto;
width: -webkit-fit-content;
width: fit-content;
max-width: 300px;
max-height: 500px;
overflow: auto;
padding: 0.5em 0.75em;
font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
background: var(--dfnpanel-bg);
color: var(--dfnpanel-text);
border: outset 0.2em;
}
.dfn-panel:not(.on) { display: none; }
.dfn-panel * { margin: 0; padding: 0; text-indent: 0; }
.dfn-panel > b { display: block; }
.dfn-panel a { color: var(--dfnpanel-text); }
.dfn-panel a:not(:hover) { text-decoration: none !important; border-bottom: none !important; }
.dfn-panel > b + b { margin-top: 0.25em; }
.dfn-panel ul { padding: 0; }
.dfn-panel li { list-style: inside; }
.dfn-panel.activated {
display: inline-block;
position: fixed;
left: .5em;
bottom: 2em;
margin: 0 auto;
max-width: calc(100vw - 1.5em - .4em - .5em);
max-height: 30vh;
}
.dfn-paneled { cursor: pointer; }
</style>
<style>/* style-issues */
a[href].issue-return {
float: right;
float: inline-end;
color: var(--issueheading-text);
font-weight: bold;
text-decoration: none;
}
</style>
<style>/* style-md-lists */
/* This is a weird hack for me not yet following the commonmark spec
regarding paragraph and lists. */
[data-md] > :first-child {
margin-top: 0;
}
[data-md] > :last-child {
margin-bottom: 0;
}</style>
<style>/* style-selflinks */
:root {
--selflink-text: white;
--selflink-bg: gray;
--selflink-hover-text: black;
}
.heading, .issue, .note, .example, li, dt {
position: relative;
}
a.self-link {
position: absolute;
top: 0;
left: calc(-1 * (3.5rem - 26px));
width: calc(3.5rem - 26px);
height: 2em;
text-align: center;
border: none;
transition: opacity .2s;
opacity: .5;
}
a.self-link:hover {
opacity: 1;
}
.heading > a.self-link {
font-size: 83%;
}
li > a.self-link {
left: calc(-1 * (3.5rem - 26px) - 2em);
}
dfn > a.self-link {
top: auto;
left: auto;
opacity: 0;
width: 1.5em;
height: 1.5em;
background: var(--selflink-bg);
color: var(--selflink-text);
font-style: normal;
transition: opacity .2s, background-color .2s, color .2s;
}
dfn:hover > a.self-link {
opacity: 1;
}
dfn > a.self-link:hover {
color: var(--selflink-hover-text);
}
a.self-link::before { content: "¶"; }
.heading > a.self-link::before { content: "§"; }
dfn > a.self-link::before { content: "#"; }
</style>
<style>/* style-syntax-highlighting */
pre.idl.highlight {
background: var(--borderedblock-bg, var(--def-bg));
}
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
.highlight:not(.idl) { background: rgba(0, 0, 0, .03); }
c-[a] { color: #990055 } /* Keyword.Declaration */
c-[b] { color: #990055 } /* Keyword.Type */
c-[c] { color: #708090 } /* Comment */
c-[d] { color: #708090 } /* Comment.Multiline */
c-[e] { color: #0077aa } /* Name.Attribute */
c-[f] { color: #669900 } /* Name.Tag */
c-[g] { color: #222222 } /* Name.Variable */
c-[k] { color: #990055 } /* Keyword */
c-[l] { color: #000000 } /* Literal */
c-[m] { color: #000000 } /* Literal.Number */
c-[n] { color: #0077aa } /* Name */
c-[o] { color: #999999 } /* Operator */
c-[p] { color: #999999 } /* Punctuation */
c-[s] { color: #a67f59 } /* Literal.String */
c-[t] { color: #a67f59 } /* Literal.String.Single */
c-[u] { color: #a67f59 } /* Literal.String.Double */
c-[cp] { color: #708090 } /* Comment.Preproc */
c-[c1] { color: #708090 } /* Comment.Single */
c-[cs] { color: #708090 } /* Comment.Special */
c-[kc] { color: #990055 } /* Keyword.Constant */
c-[kn] { color: #990055 } /* Keyword.Namespace */
c-[kp] { color: #990055 } /* Keyword.Pseudo */
c-[kr] { color: #990055 } /* Keyword.Reserved */
c-[ld] { color: #000000 } /* Literal.Date */
c-[nc] { color: #0077aa } /* Name.Class */
c-[no] { color: #0077aa } /* Name.Constant */
c-[nd] { color: #0077aa } /* Name.Decorator */
c-[ni] { color: #0077aa } /* Name.Entity */
c-[ne] { color: #0077aa } /* Name.Exception */
c-[nf] { color: #0077aa } /* Name.Function */
c-[nl] { color: #0077aa } /* Name.Label */
c-[nn] { color: #0077aa } /* Name.Namespace */
c-[py] { color: #0077aa } /* Name.Property */
c-[ow] { color: #999999 } /* Operator.Word */
c-[mb] { color: #000000 } /* Literal.Number.Bin */
c-[mf] { color: #000000 } /* Literal.Number.Float */
c-[mh] { color: #000000 } /* Literal.Number.Hex */
c-[mi] { color: #000000 } /* Literal.Number.Integer */
c-[mo] { color: #000000 } /* Literal.Number.Oct */
c-[sb] { color: #a67f59 } /* Literal.String.Backtick */
c-[sc] { color: #a67f59 } /* Literal.String.Char */
c-[sd] { color: #a67f59 } /* Literal.String.Doc */
c-[se] { color: #a67f59 } /* Literal.String.Escape */
c-[sh] { color: #a67f59 } /* Literal.String.Heredoc */
c-[si] { color: #a67f59 } /* Literal.String.Interpol */
c-[sx] { color: #a67f59 } /* Literal.String.Other */
c-[sr] { color: #a67f59 } /* Literal.String.Regex */
c-[ss] { color: #a67f59 } /* Literal.String.Symbol */
c-[vc] { color: #0077aa } /* Name.Variable.Class */
c-[vg] { color: #0077aa } /* Name.Variable.Global */
c-[vi] { color: #0077aa } /* Name.Variable.Instance */
c-[il] { color: #000000 } /* Literal.Number.Integer.Long */
</style>
<style>/* style-darkmode */
@media (prefers-color-scheme: dark) {
:root {
--text: #ddd;
--bg: black;
--unofficial-watermark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cg fill='%23100808' transform='translate(200 200) rotate(-45) translate(-200 -200)' stroke='%23100808' stroke-width='3'%3E%3Ctext x='50%25' y='220' style='font: bold 70px sans-serif; text-anchor: middle; letter-spacing: 6px;'%3EUNOFFICIAL%3C/text%3E%3Ctext x='50%25' y='305' style='font: bold 70px sans-serif; text-anchor: middle; letter-spacing: 6px;'%3EDRAFT%3C/text%3E%3C/g%3E%3C/svg%3E");
--logo-bg: #1a5e9a;
--logo-active-bg: #c00;
--logo-text: white;
--tocnav-normal-text: #999;
--tocnav-normal-bg: var(--bg);
--tocnav-hover-text: var(--tocnav-normal-text);
--tocnav-hover-bg: #080808;
--tocnav-active-text: #f44;
--tocnav-active-bg: var(--tocnav-normal-bg);
--tocsidebar-text: var(--text);
--tocsidebar-bg: #080808;
--tocsidebar-shadow: rgba(255,255,255,.1);
--tocsidebar-heading-text: hsla(203,20%,40%,.7);
--toclink-text: var(--text);
--toclink-underline: #6af;
--toclink-visited-text: var(--toclink-text);
--toclink-visited-underline: #054572;
--heading-text: #8af;
--hr-text: var(--text);
--algo-border: #456;
--del-text: #f44;
--del-bg: transparent;
--ins-text: #4a4;
--ins-bg: transparent;
--a-normal-text: #6af;
--a-normal-underline: #555;
--a-visited-text: var(--a-normal-text);
--a-visited-underline: var(--a-normal-underline);
--a-hover-bg: rgba(25%, 25%, 25%, .2);
--a-active-text: #f44;
--a-active-underline: var(--a-active-text);
--borderedblock-bg: rgba(255, 255, 255, .05);
--blockquote-border: silver;
--blockquote-bg: var(--borderedblock-bg);
--blockquote-text: currentcolor;
--issue-border: #e05252;
--issue-bg: var(--borderedblock-bg);
--issue-text: var(--text);
--issueheading-text: hsl(0deg, 70%, 70%);
--example-border: hsl(50deg, 90%, 60%);
--example-bg: var(--borderedblock-bg);
--example-text: var(--text);
--exampleheading-text: hsl(50deg, 70%, 70%);
--note-border: hsl(120deg, 100%, 35%);
--note-bg: var(--borderedblock-bg);
--note-text: var(--text);
--noteheading-text: hsl(120, 70%, 70%);
--notesummary-underline: silver;
--assertion-border: #444;
--assertion-bg: var(--borderedblock-bg);
--assertion-text: var(--text);
--advisement-border: orange;
--advisement-bg: #222218;
--advisement-text: var(--text);
--advisementheading-text: #f84;
--warning-border: red;
--warning-bg: hsla(40,100%,20%,0.95);
--warning-text: var(--text);
--amendment-border: #330099;
--amendment-bg: #080010;
--amendment-text: var(--text);
--amendmentheading-text: #cc00ff;
--def-border: #8ccbf2;
--def-bg: #080818;
--def-text: var(--text);
--defrow-border: #136;
--datacell-border: silver;
--indexinfo-text: #aaa;
--indextable-hover-text: var(--text);
--indextable-hover-bg: #181818;
--outdatedspec-bg: rgba(255, 255, 255, .5);
--outdatedspec-text: black;
--outdated-bg: maroon;
--outdated-text: white;
--outdated-shadow: red;
--editedrec-bg: darkorange;
}
/* In case a transparent-bg image doesn't expect to be on a dark bg,
which is quite common in practice... */
img { background: white; }
}
@media (prefers-color-scheme: dark) {
:root {
--selflink-text: black;
--selflink-bg: silver;
--selflink-hover-text: white;
}
}
@media (prefers-color-scheme: dark) {
:root {
--dfnpanel-bg: #222;
--dfnpanel-text: var(--text);
}
}
@media (prefers-color-scheme: dark) {
.highlight:not(.idl) { background: rgba(255, 255, 255, .05); }
c-[a] { color: #d33682 } /* Keyword.Declaration */
c-[b] { color: #d33682 } /* Keyword.Type */
c-[c] { color: #2aa198 } /* Comment */
c-[d] { color: #2aa198 } /* Comment.Multiline */
c-[e] { color: #268bd2 } /* Name.Attribute */
c-[f] { color: #b58900 } /* Name.Tag */
c-[g] { color: #cb4b16 } /* Name.Variable */
c-[k] { color: #d33682 } /* Keyword */
c-[l] { color: #657b83 } /* Literal */
c-[m] { color: #657b83 } /* Literal.Number */
c-[n] { color: #268bd2 } /* Name */
c-[o] { color: #657b83 } /* Operator */
c-[p] { color: #657b83 } /* Punctuation */
c-[s] { color: #6c71c4 } /* Literal.String */
c-[t] { color: #6c71c4 } /* Literal.String.Single */
c-[u] { color: #6c71c4 } /* Literal.String.Double */
c-[ch] { color: #2aa198 } /* Comment.Hashbang */
c-[cp] { color: #2aa198 } /* Comment.Preproc */
c-[cpf] { color: #2aa198 } /* Comment.PreprocFile */
c-[c1] { color: #2aa198 } /* Comment.Single */
c-[cs] { color: #2aa198 } /* Comment.Special */
c-[kc] { color: #d33682 } /* Keyword.Constant */
c-[kn] { color: #d33682 } /* Keyword.Namespace */
c-[kp] { color: #d33682 } /* Keyword.Pseudo */
c-[kr] { color: #d33682 } /* Keyword.Reserved */
c-[ld] { color: #657b83 } /* Literal.Date */
c-[nc] { color: #268bd2 } /* Name.Class */
c-[no] { color: #268bd2 } /* Name.Constant */
c-[nd] { color: #268bd2 } /* Name.Decorator */
c-[ni] { color: #268bd2 } /* Name.Entity */
c-[ne] { color: #268bd2 } /* Name.Exception */
c-[nf] { color: #268bd2 } /* Name.Function */
c-[nl] { color: #268bd2 } /* Name.Label */
c-[nn] { color: #268bd2 } /* Name.Namespace */
c-[py] { color: #268bd2 } /* Name.Property */
c-[ow] { color: #657b83 } /* Operator.Word */
c-[mb] { color: #657b83 } /* Literal.Number.Bin */
c-[mf] { color: #657b83 } /* Literal.Number.Float */
c-[mh] { color: #657b83 } /* Literal.Number.Hex */
c-[mi] { color: #657b83 } /* Literal.Number.Integer */
c-[mo] { color: #657b83 } /* Literal.Number.Oct */
c-[sa] { color: #6c71c4 } /* Literal.String.Affix */
c-[sb] { color: #6c71c4 } /* Literal.String.Backtick */
c-[sc] { color: #6c71c4 } /* Literal.String.Char */
c-[dl] { color: #6c71c4 } /* Literal.String.Delimiter */
c-[sd] { color: #6c71c4 } /* Literal.String.Doc */
c-[se] { color: #6c71c4 } /* Literal.String.Escape */
c-[sh] { color: #6c71c4 } /* Literal.String.Heredoc */
c-[si] { color: #6c71c4 } /* Literal.String.Interpol */
c-[sx] { color: #6c71c4 } /* Literal.String.Other */
c-[sr] { color: #6c71c4 } /* Literal.String.Regex */
c-[ss] { color: #6c71c4 } /* Literal.String.Symbol */
c-[fm] { color: #268bd2 } /* Name.Function.Magic */
c-[vc] { color: #cb4b16 } /* Name.Variable.Class */
c-[vg] { color: #cb4b16 } /* Name.Variable.Global */
c-[vi] { color: #cb4b16 } /* Name.Variable.Instance */
c-[vm] { color: #cb4b16 } /* Name.Variable.Magic */
c-[il] { color: #657b83 } /* Literal.Number.Integer.Long */
}
</style>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2021/logos/W3C" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">Document Picture-in-Picture Specification</h1>
<p id="w3c-state"><a href="https://www.w3.org/standards/types#UD">Unofficial Proposal Draft</a>, <time class="dt-updated" datetime="2022-08-10">10 August 2022</time></p>
<details open>
<summary>More details about this document</summary>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="http://example.com/url-this-spec-will-live-at">http://example.com/url-this-spec-will-live-at</a>
<dt>Issue Tracking:
<dd><a href="https://github.com/w3c/document-pip/issues/">GitHub</a>
<dt class="editor">Editor:
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:steimel@google.com">Tommy Steimel</a> (<span class="p-org org">Google Inc.</span>)
</dl>
</div>
</details>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright"><a href="https://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2022 <a href="https://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="https://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="https://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="https://www.keio.ac.jp/">Keio</a>, <a href="https://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="https://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="https://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document" rel="license">permissive document license</a> rules apply. </p>
<hr title="Separator for header">
</div>
<div class="p-summary" data-fill-with="abstract">
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<p>This specification enables web developers to populate an HTMLDocument
in an always-on-top window.</p>
</div>
<h2 class="no-num no-toc no-ref heading settled" id="sotd"><span class="content">Status of this document</span></h2>
<div data-fill-with="status">
<p> <em>This section describes the status of this document at the time of its publication. A list of current <abbr title="World Wide Web Consortium">W3C</abbr> publications and the latest revision of this technical report can be found in the <a href="https://www.w3.org/TR/"><abbr title="World Wide Web Consortium">W3C</abbr> technical reports index</a> at https://www.w3.org/TR/.</em> </p>
<p> Feedback and comments on this specification are welcome. <a href="https://github.com/w3c/document-pip/issues">GitHub Issues</a> are preferred for discussion on this specification. Alternatively, you can send comments to the Media Working Group’s mailing-list, <a href="mailto:public-media-wg@w3.org">public-media-wg@w3.org</a> (<a href="https://lists.w3.org/Archives/Public/public-media-wg/">archives</a>).
This draft highlights some of the pending issues that are still to be discussed in the working group.
No decision has been taken on the outcome of these issues including whether they are valid. </p>
<p> This document was produced by a group operating under the <a class="css" data-link-type="property" href="https://www.w3.org/Consortium/Patent-Policy/" id="sotd_patent">W3C Patent Policy</a>. <abbr title="World Wide Web Consortium">W3C</abbr> maintains a <a href="https://www.w3.org/groups/wg/media/ipr" rel="disclosure">public list of any patent disclosures</a> made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains <a href="https://www.w3.org/Consortium/Patent-Policy/#def-essential">Essential Claim(s)</a> must disclose the information in accordance with <a href="https://www.w3.org/Consortium/Patent-Policy/#sec-Disclosure">section 6 of the <abbr title="World Wide Web Consortium">W3C</abbr> Patent Policy</a>. </p>
<p> This document is governed by the <a href="https://www.w3.org/2021/Process-20211102/" id="w3c_process_revision">2 November 2021 W3C Process Document</a>. </p>
<p></p>
</div>
<div data-fill-with="at-risk"></div>
<nav data-fill-with="table-of-contents" id="toc">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<ol class="toc" role="directory">
<li><a href="#intro"><span class="secno">1</span> <span class="content">Introduction</span></a>
<li><a href="#dependencies"><span class="secno">2</span> <span class="content">Dependencies</span></a>
<li>
<a href="#security-privacy-considerations"><span class="secno">3</span> <span class="content">Security and Privacy Considerations</span></a>
<ol class="toc">
<li><a href="#secure-context"><span class="secno">3.1</span> <span class="content">Secure Context</span></a>
<li><a href="#spoofing"><span class="secno">3.2</span> <span class="content">Spoofing</span></a>
<li><a href="#fingerprinting"><span class="secno">3.3</span> <span class="content">Fingerprinting</span></a>
</ol>
<li>
<a href="#concepts"><span class="secno">4</span> <span class="content">Concepts</span></a>
<ol class="toc">
<li><a href="#open-pip"><span class="secno">4.1</span> <span class="content">Open DocumentPictureInPictureWindow</span></a>
<li><a href="#close-pip"><span class="secno">4.2</span> <span class="content">Close DocumentPictureInPictureWindow</span></a>
<li><a href="#concept-set-aspect-ratio"><span class="secno">4.3</span> <span class="content">Set Aspect Ratio</span></a>
<li><a href="#concept-lock-aspect-ratio"><span class="secno">4.4</span> <span class="content">Lock Aspect Ratio</span></a>
<li><a href="#pip-support"><span class="secno">4.5</span> <span class="content">Document Picture-in-Picture Support</span></a>
<li><a href="#one-pip-window"><span class="secno">4.6</span> <span class="content">One PiP Window</span></a>
<li><a href="#relative-urls"><span class="secno">4.7</span> <span class="content">Relative URLs</span></a>
</ol>
<li><a href="#api"><span class="secno">5</span> <span class="content">API</span></a>
<li>
<a href="#examples"><span class="secno">6</span> <span class="content">Examples</span></a>
<ol class="toc">
<li>
<a href="#example-video-player"><span class="secno">6.1</span> <span class="content">Extracting a video player into PiP</span></a>
<ol class="toc">
<li><a href="#example-video-player-html"><span class="secno">6.1.1</span> <span class="content">HTML</span></a>
<li><a href="#example-video-player-js"><span class="secno">6.1.2</span> <span class="content">JavaScript</span></a>
</ol>
<li><a href="#example-access-elements"><span class="secno">6.2</span> <span class="content">Accessing elements on the PiP Window</span></a>
<li><a href="#example-listen-events"><span class="secno">6.3</span> <span class="content">Listening to events on the PiP Window</span></a>
<li><a href="#example-exiting-pip"><span class="secno">6.4</span> <span class="content">Exiting PiP</span></a>
<li><a href="#example-aspect-ratio"><span class="secno">6.5</span> <span class="content">Changing aspect ratio</span></a>
<li><a href="#example-elements-out-on-close"><span class="secno">6.6</span> <span class="content">Getting elements out of the PiP window when it closes</span></a>
</ol>
<li><a href="#acknowledgments"><span class="secno">7</span> <span class="content">Acknowledgments</span></a>
<li>
<a href="#w3c-conformance"><span class="secno"></span> <span class="content">Conformance</span></a>
<ol class="toc">
<li><a href="#w3c-conventions"><span class="secno"></span> <span class="content">Document conventions</span></a>
<li><a href="#w3c-conformant-algorithms"><span class="secno"></span> <span class="content">Conformant Algorithms</span></a>
</ol>
<li>
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ol class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
</ol>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ol class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
</ol>
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
</ol>
</nav>
<main>
<h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content">Introduction</span><a class="self-link" href="#intro"></a></h2>
<p><em>This section is non-normative.</em></p>
<p>There currently exists a Web API for putting an <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/media.html#htmlvideoelement" id="ref-for-htmlvideoelement">HTMLVideoElement</a></code> into a
Picture-in-Picture window (<code>requestPictureInPicture()</code>). This limits
a website’s ability to provide a custom picture-in-picture experience (PiP). We
want to expand upon that functionality by providing the website with a full <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#document" id="ref-for-document">Document</a></code> on an always-on-top window.</p>
<p>This new window will be much like a blank same-origin window opened via the
existing <a class="idl-code" data-link-type="method" href="https://html.spec.whatwg.org/multipage/window-object.html#dom-open" id="ref-for-dom-open">open()</a> method on <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/window-object.html#window" id="ref-for-window">Window</a></code>, with some minor
differences:</p>
<ul>
<li data-md>
<p>The PiP window will float on top of other windows.</p>
<li data-md>
<p>The PiP window will never outlive the opening window.</p>
<li data-md>
<p>The website cannot set the position of the PiP window.</p>
<li data-md>
<p>The PiP window cannot be navigated (any `window.history` or `window.location`
calls that change to a new document will close the PiP window).</p>
<li data-md>
<p>The PiP window cannot open more windows.</p>
</ul>
<h2 class="heading settled" data-level="2" id="dependencies"><span class="secno">2. </span><span class="content">Dependencies</span><a class="self-link" href="#dependencies"></a></h2>
<p>The IDL fragments in this specification must be interpreted as required for
conforming IDL fragments, as described in the Web IDL specification. <a data-link-type="biblio" href="#biblio-webidl">[WEBIDL]</a></p>
<h2 class="heading settled" data-level="3" id="security-privacy-considerations"><span class="secno">3. </span><span class="content">Security and Privacy Considerations</span><a class="self-link" href="#security-privacy-considerations"></a></h2>
<h3 class="heading settled" data-level="3.1" id="secure-context"><span class="secno">3.1. </span><span class="content">Secure Context</span><a class="self-link" href="#secure-context"></a></h3>
<p>The API is limited to <a data-link-type="biblio" href="#biblio-secure-contexts">[SECURE-CONTEXTS]</a>.</p>
<p>TODO: Why? Especially given that both the original PiP API and the window.open()
API are allowed on non-secure contexts.</p>
<h3 class="heading settled" data-level="3.2" id="spoofing"><span class="secno">3.2. </span><span class="content">Spoofing</span><a class="self-link" href="#spoofing"></a></h3>
<p>It is RECOMMENDED that the user agent provides enough UI on the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow">DocumentPictureInPictureWindow</a></code> to prevent malicious websites from abusing
the ability to float on top of other windows to spoof other websites or system
UI. The website’s inability to directly set the location or size of the PiP
window helps alleviate some avenues of abuse.</p>
<p>It is RECOMMENDED that the user agent makes it clear to the user which origin is
controlling the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①">DocumentPictureInPictureWindow</a></code> at all times.</p>
<h3 class="heading settled" data-level="3.3" id="fingerprinting"><span class="secno">3.3. </span><span class="content">Fingerprinting</span><a class="self-link" href="#fingerprinting"></a></h3>
<p>When a PiP window is closed and then later re-opened, it can be useful for the
user agent to re-use size and location of the previous PiP window (modulo
aspect-ratio constraints) to provide a smoother user experience. However, it is
RECOMMENDED that the user agent does not re-use size/location across different
origins as this may provide malicious websites an avenue for fingerprinting
a user.</p>
<h2 class="heading settled" data-level="4" id="concepts"><span class="secno">4. </span><span class="content">Concepts</span><a class="self-link" href="#concepts"></a></h2>
<h3 class="heading settled" data-level="4.1" id="open-pip"><span class="secno">4.1. </span><span class="content">Open DocumentPictureInPictureWindow</span><a class="self-link" href="#open-pip"></a></h3>
<p>When the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="open-documentpictureinpicturewindow">open DocumentPictureInPictureWindow</dfn> algorithm is invoked
with <var>options</var> on <var>pictureInPicture</var> of type <code class="idl"><a data-link-type="idl" href="#pictureinpicture" id="ref-for-pictureinpicture">PictureInPicture</a></code>, the user
agent MUST run the following steps:</p>
<ol>
<li data-md>
<p>If <a data-link-type="dfn" href="#document-picture-in-picture-support" id="ref-for-document-picture-in-picture-support">Document Picture-in-Picture support</a> is <code>false</code>, throw a <code class="idl"><a data-link-type="idl" href="https://webidl.spec.whatwg.org/#notsupportederror" id="ref-for-notsupportederror">NotSupportedError</a></code> and abort these steps.</p>
<li data-md>
<p>If the <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#concept-relevant-global" id="ref-for-concept-relevant-global">relevant global object</a> of <a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#this" id="ref-for-this">this</a> does not have <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/interaction.html#transient-activation" id="ref-for-transient-activation">transient activation</a>, throw a <code class="idl"><a data-link-type="idl" href="https://webidl.spec.whatwg.org/#notallowederror" id="ref-for-notallowederror">NotAllowedError</a></code> and abort these
steps.</p>
<li data-md>
<p>The user agent MAY choose to close any existing <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow②">DocumentPictureInPictureWindow</a></code>s or <a data-link-type="idl" href="https://w3c.github.io/picture-in-picture/#pictureinpicturewindow">PictureInPictureWindow</a>s.</p>
<li data-md>
<p>Let <var>target browsing context</var> be a new <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/browsers.html#browsing-context" id="ref-for-browsing-context">browsing context</a> navigated to
the <code>about:blank</code> <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url" id="ref-for-concept-url">URL</a>.</p>
<li data-md>
<p>If |options["initialAspectRatio"]| exists and is greater than zero:</p>
<ol>
<li data-md>
<p>OPTIONALLY, clamp or ignore |options["initialAspectRatio"]| if it is too
large or too small in order to fit a user-friendly window size.</p>
<li data-md>
<p>Set the window size for the <var>target browsing context</var> to a <var>width</var> and <var>height</var> such that <var>width</var> divided by <var>height</var> is approximately
|options["initialAspectRatio"]|.</p>
<li data-md>
<p>If |options["lockAspectRatio"]| exists and is <code>true</code>, then the
window should be configured such that when a user resizes it, the aspect
ratio of the window should remain constant.</p>
</ol>
<li data-md>
<p>Configure the window containing <var>target browsing context</var> to float on top of
other windows.</p>
<li data-md>
<p>Let <var>pipWindow</var> be a <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow③">DocumentPictureInPictureWindow</a></code> object with the <code class="idl"><a data-link-type="idl" href="#dom-documentpictureinpicturewindow-document" id="ref-for-dom-documentpictureinpicturewindow-document">document</a></code> attribute set to <var>target
browsing context</var>’s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window" id="ref-for-concept-document-window">associated Document</a>.</p>
<li data-md>
<p><a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task" id="ref-for-queue-a-task">Queue a task</a> to <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-event-fire" id="ref-for-concept-event-fire">fire an event</a> named <code class="idl"><a data-link-type="idl" href="#eventdef-pictureinpicture-enterpictureinpicture" id="ref-for-eventdef-pictureinpicture-enterpictureinpicture">enterpictureinpicture</a></code> using <code class="idl"><a data-link-type="idl" href="#documentpictureinpictureevent" id="ref-for-documentpictureinpictureevent">DocumentPictureInPictureEvent</a></code> on <var>pictureInPicture</var> with its <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-event-bubbles" id="ref-for-dom-event-bubbles">bubbles</a></code> attribute initialized to <code>true</code> and its <code class="idl"><a data-link-type="idl" href="#dom-documentpictureinpictureevent-pictureinpicturewindow" id="ref-for-dom-documentpictureinpictureevent-pictureinpicturewindow">pictureInPictureWindow</a></code> attribute
initialized to <var>pipWindow</var>.</p>
<li data-md>
<p>Return <var>pipWindow</var>.</p>
</ol>
<p class="note" role="note"> While the aspect ratio of the window can be configured by the website, the
initial size and position is left to the discretion of the user agent. </p>
<h3 class="heading settled" data-level="4.2" id="close-pip"><span class="secno">4.2. </span><span class="content">Close DocumentPictureInPictureWindow</span><a class="self-link" href="#close-pip"></a></h3>
<p>The window represented by a <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow④">DocumentPictureInPictureWindow</a></code> object can be
closed for a few reasons: the <a class="idl-code" data-link-type="method" href="https://html.spec.whatwg.org/multipage/window-object.html#dom-window-close" id="ref-for-dom-window-close">close()</a> method on the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/window-object.html#window" id="ref-for-window①">Window</a></code> object, the user clicking a close button on the window UI, the user
agent deciding to close the window because another PiP window is opening, the
user agent closing the window because the opener window has closed, etc. When
the window represented by a <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow⑤">DocumentPictureInPictureWindow</a></code> object is closed
for any reason, the user agent MUST run the following steps:</p>
<ol>
<li data-md>
<p>Let <var>pipWindow</var> be the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow⑥">DocumentPictureInPictureWindow</a></code> which is closing.</p>
<li data-md>
<p>Let <var>pictureInPicture</var> be the <code class="idl"><a data-link-type="idl" href="#pictureinpicture" id="ref-for-pictureinpicture①">PictureInPicture</a></code> object on which <code class="idl"><a data-link-type="idl" href="#dom-pictureinpicture-requestwindow" id="ref-for-dom-pictureinpicture-requestwindow">requestWindow()</a></code> was called to create <var>pipWindow</var>.</p>
<li data-md>
<p><a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task" id="ref-for-queue-a-task①">Queue a task</a> to <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#concept-event-fire" id="ref-for-concept-event-fire①">fire an event</a> named <code class="idl"><a data-link-type="idl" href="#eventdef-pictureinpicture-leavepictureinpicture" id="ref-for-eventdef-pictureinpicture-leavepictureinpicture">leavepictureinpicture</a></code> using <code class="idl"><a data-link-type="idl" href="#documentpictureinpictureevent" id="ref-for-documentpictureinpictureevent①">DocumentPictureInPictureEvent</a></code> on <var>pictureInPicture</var> with its <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#dom-event-bubbles" id="ref-for-dom-event-bubbles①">bubbles</a></code> attribute initialized to <code>true</code> and its <code class="idl"><a data-link-type="idl" href="#dom-documentpictureinpictureevent-pictureinpicturewindow" id="ref-for-dom-documentpictureinpictureevent-pictureinpicturewindow①">pictureInPictureWindow</a></code> attribute
initialized to <var>pipWindow</var>.</p>
</ol>
<p class="note" role="note"> The user agent MUST fire the <code class="idl"><a data-link-type="idl" href="#eventdef-pictureinpicture-leavepictureinpicture" id="ref-for-eventdef-pictureinpicture-leavepictureinpicture①">leavepictureinpicture</a></code> event before unloading
the <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#document" id="ref-for-document①">Document</a></code> associated with the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow⑦">DocumentPictureInPictureWindow</a></code> to give
the website a chance to move any elements they need back into the original
window. </p>
<h3 class="heading settled" data-level="4.3" id="concept-set-aspect-ratio"><span class="secno">4.3. </span><span class="content">Set Aspect Ratio</span><a class="self-link" href="#concept-set-aspect-ratio"></a></h3>
<p>When the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="set-aspect-ratio">set aspect ratio</dfn> algorithm is invoked with <var>aspectRatio</var> on <var>pipWindow</var> of type <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow⑧">DocumentPictureInPictureWindow</a></code>, the user agent MUST run
the following steps:</p>
<ol>
<li data-md>
<p>If <var>aspectRatio</var> <= 0, throw a <code class="idl"><a data-link-type="idl" href="https://webidl.spec.whatwg.org/#exceptiondef-rangeerror" id="ref-for-exceptiondef-rangeerror">RangeError</a></code> and abort these steps.</p>
<li data-md>
<p>If <var>pipWindow</var> has already closed, throw an <code class="idl"><a data-link-type="idl" href="https://webidl.spec.whatwg.org/#invalidstateerror" id="ref-for-invalidstateerror">InvalidStateError</a></code> and abort
these steps.</p>
<li data-md>
<p>OPTIONALLY, clamp or ignore <var>aspectRatio</var> if it is too large or too small in
order to fit a user-friendly window size.</p>
<li data-md>
<p>Resize the window represented by <var>pipWindow</var> to a <var>width</var> and <var>height</var> such
that <var>width</var> divided by <var>height</var> is approximately <var>aspectRatio</var> or the
alternative value determined in step 3.</p>
</ol>
<p class="note" role="note"> It is RECOMMENDED that when resizing to the new aspect ratio the user agent
attempt to keep the total area and position of the window as consistent to the
original total area and position as possible. </p>
<h3 class="heading settled" data-level="4.4" id="concept-lock-aspect-ratio"><span class="secno">4.4. </span><span class="content">Lock Aspect Ratio</span><a class="self-link" href="#concept-lock-aspect-ratio"></a></h3>
<p>When the <dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="set-lock-aspect-ratio">set lock aspect ratio</dfn> algorithm is invoked with <var>lockAspectRatio</var> on <var>pipWindow</var> of type <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow⑨">DocumentPictureInPictureWindow</a></code>, the
user agent MUST run the following steps:</p>
<ol>
<li data-md>
<p>If <var>pipWindow</var> has already closed, throw an <code class="idl"><a data-link-type="idl" href="https://webidl.spec.whatwg.org/#invalidstateerror" id="ref-for-invalidstateerror①">InvalidStateError</a></code> and abort
these steps.</p>
<li data-md>
<p>If <var>lockAspectRatio</var> is <code>true</code>, then the window represented by <var>pipWindow</var> should be configured such that when a user resizes it, the
aspect ratio of the window should remain constant.</p>
<li data-md>
<p>If <var>lockAspectRatio</var> is <code>false</code>, the the window represented by <var>pipWindow</var> should no longer be configured to keep the aspect ratio
constant.</p>
</ol>
<h3 class="heading settled" data-level="4.5" id="pip-support"><span class="secno">4.5. </span><span class="content">Document Picture-in-Picture Support</span><a class="self-link" href="#pip-support"></a></h3>
<p><dfn class="dfn-paneled" data-dfn-type="dfn" data-noexport id="document-picture-in-picture-support">Document Picture-in-Picture Support</dfn> is <code>false</code> if there’s
a user preference that disables it or a platform limitation. It is <code>true</code> otherwise.</p>
<h3 class="heading settled" data-level="4.6" id="one-pip-window"><span class="secno">4.6. </span><span class="content">One PiP Window</span><a class="self-link" href="#one-pip-window"></a></h3>
<p>Whether only one window is allowed in Picture-in-Picture mode is left to the
implementation and the platform. As such, what happens when there is a
Picture-in-Picture request while a <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①⓪">DocumentPictureInPictureWindow</a></code> or <a data-link-type="idl" href="https://w3c.github.io/picture-in-picture/#pictureinpicturewindow">PictureInPictureWindow</a> is already open will be left as an implementation detail: the current window
could be closed, the Picture-in-Picture request could be rejected, or multiple
Picture-in-Picture windows could be created. Regardless, the user agent MUST
fire the appropriate events in order to notify the websites of the
Picture-in-Picture status changes.</p>
<h3 class="heading settled" data-level="4.7" id="relative-urls"><span class="secno">4.7. </span><span class="content">Relative URLs</span><a class="self-link" href="#relative-urls"></a></h3>
<p>A primary use case of <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①①">DocumentPictureInPictureWindow</a></code> is to put existing
elements (e.g. an <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/media.html#htmlvideoelement" id="ref-for-htmlvideoelement①">HTMLVideoElement</a></code>) into an always-on-top window so the user
can continue to see them while multitasking. However, sometimes these elements
have attributes that use a <a data-link-type="dfn" href="https://url.spec.whatwg.org/#relative-url-string" id="ref-for-relative-url-string">relative-URL string</a> (e.g. <a class="idl-code" data-link-type="attribute" href="https://html.spec.whatwg.org/multipage/media.html#dom-media-src" id="ref-for-dom-media-src">src</a>). Since the <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#document" id="ref-for-document②">Document</a></code> in a <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①②">DocumentPictureInPictureWindow</a></code> is always navigated to the <code>about:blank</code> <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url" id="ref-for-concept-url①">URL</a>, these <a data-link-type="dfn" href="https://url.spec.whatwg.org/#relative-url-string" id="ref-for-relative-url-string①">relative-URL string</a>s would
break. To prevent this, the user agent MUST parse <a data-link-type="dfn" href="https://url.spec.whatwg.org/#relative-url-string" id="ref-for-relative-url-string②">relative-URL string</a>s as
if they were being parsed on the <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#document" id="ref-for-document③">Document</a></code> that opened the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①③">DocumentPictureInPictureWindow</a></code>.</p>
<h2 class="heading settled" data-level="5" id="api"><span class="secno">5. </span><span class="content">API</span><a class="self-link" href="#api"></a></h2>
<pre class="idl highlight def">[<a class="idl-code" data-link-type="extended-attribute" href="https://webidl.spec.whatwg.org/#Exposed" id="ref-for-Exposed"><c- g>Exposed</c-></a>=<c- n>Window</c->]
<c- b>partial</c-> <c- b>interface</c-> <a class="idl-code" data-link-type="interface" href="https://html.spec.whatwg.org/multipage/system-state.html#navigator" id="ref-for-navigator"><c- g>Navigator</c-></a> {
[<a class="idl-code" data-link-type="extended-attribute" href="https://webidl.spec.whatwg.org/#SameObject" id="ref-for-SameObject"><c- g>SameObject</c-></a>] <c- b>readonly</c-> <c- b>attribute</c-> <a data-link-type="idl-name" href="#pictureinpicture" id="ref-for-pictureinpicture②"><c- n>PictureInPicture</c-></a> <dfn class="idl-code" data-dfn-for="Navigator" data-dfn-type="attribute" data-export data-readonly data-type="PictureInPicture" id="dom-navigator-pictureinpicture"><code><c- g>pictureInPicture</c-></code><a class="self-link" href="#dom-navigator-pictureinpicture"></a></dfn>;
};
[<a class="idl-code" data-link-type="extended-attribute" href="https://webidl.spec.whatwg.org/#Exposed" id="ref-for-Exposed①"><c- g>Exposed</c-></a>=<c- n>Window</c->]
<c- b>interface</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="interface" data-export id="pictureinpicture"><code><c- g>PictureInPicture</c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#eventtarget" id="ref-for-eventtarget"><c- n>EventTarget</c-></a> {
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-promise" id="ref-for-idl-promise"><c- b>Promise</c-></a><<a data-link-type="idl-name" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①④"><c- n>DocumentPictureInPictureWindow</c-></a>> <dfn class="dfn-paneled idl-code" data-dfn-for="PictureInPicture" data-dfn-type="method" data-export data-lt="requestWindow(options)|requestWindow()" id="dom-pictureinpicture-requestwindow"><code><c- g>requestWindow</c-></code></dfn>(
<c- b>optional</c-> <a data-link-type="idl-name" href="#dictdef-pictureinpicturewindowoptions" id="ref-for-dictdef-pictureinpicturewindowoptions"><c- n>PictureInPictureWindowOptions</c-></a> <dfn class="idl-code" data-dfn-for="PictureInPicture/requestWindow(options), PictureInPicture/requestWindow()" data-dfn-type="argument" data-export id="dom-pictureinpicture-requestwindow-options-options"><code><c- g>options</c-></code><a class="self-link" href="#dom-pictureinpicture-requestwindow-options-options"></a></dfn> = {});
<c- b>attribute</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler"><c- n>EventHandler</c-></a> <dfn class="idl-code" data-dfn-for="PictureInPicture" data-dfn-type="attribute" data-export data-type="EventHandler" id="dom-pictureinpicture-onenterpictureinpicture"><code><c- g>onenterpictureinpicture</c-></code><a class="self-link" href="#dom-pictureinpicture-onenterpictureinpicture"></a></dfn>;
<c- b>attribute</c-> <a data-link-type="idl-name" href="https://html.spec.whatwg.org/multipage/webappapis.html#eventhandler" id="ref-for-eventhandler①"><c- n>EventHandler</c-></a> <dfn class="idl-code" data-dfn-for="PictureInPicture" data-dfn-type="attribute" data-export data-type="EventHandler" id="dom-pictureinpicture-onleavepictureinpicture"><code><c- g>onleavepictureinpicture</c-></code><a class="self-link" href="#dom-pictureinpicture-onleavepictureinpicture"></a></dfn>;
};
<c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-pictureinpicturewindowoptions"><code><c- g>PictureInPictureWindowOptions</c-></code></dfn> {
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-float" id="ref-for-idl-float"><c- b>float</c-></a> <dfn class="idl-code" data-default="0.0" data-dfn-for="PictureInPictureWindowOptions" data-dfn-type="dict-member" data-export data-type="float " id="dom-pictureinpicturewindowoptions-initialaspectratio"><code><c- g>initialAspectRatio</c-></code><a class="self-link" href="#dom-pictureinpicturewindowoptions-initialaspectratio"></a></dfn> = 0.0;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean"><c- b>boolean</c-></a> <dfn class="idl-code" data-default="false" data-dfn-for="PictureInPictureWindowOptions" data-dfn-type="dict-member" data-export data-type="boolean " id="dom-pictureinpicturewindowoptions-lockaspectratio"><code><c- g>lockAspectRatio</c-></code><a class="self-link" href="#dom-pictureinpicturewindowoptions-lockaspectratio"></a></dfn> = <c- b>false</c->;
};
<c- b>interface</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="interface" data-export id="documentpictureinpicturewindow"><code><c- g>DocumentPictureInPictureWindow</c-></code></dfn> {
<c- b>readonly</c-> <c- b>attribute</c-> <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#document" id="ref-for-document④"><c- n>Document</c-></a>? <dfn class="dfn-paneled idl-code" data-dfn-for="DocumentPictureInPictureWindow" data-dfn-type="attribute" data-export data-readonly data-type="Document?" id="dom-documentpictureinpicturewindow-document"><code><c- g>document</c-></code></dfn>;
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-promise" id="ref-for-idl-promise①"><c- b>Promise</c-></a><<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-undefined" id="ref-for-idl-undefined"><c- b>undefined</c-></a>> <dfn class="dfn-paneled idl-code" data-dfn-for="DocumentPictureInPictureWindow" data-dfn-type="method" data-export data-lt="setAspectRatio(aspectRatio)" id="dom-documentpictureinpicturewindow-setaspectratio"><code><c- g>setAspectRatio</c-></code></dfn>(<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-float" id="ref-for-idl-float①"><c- b>float</c-></a> <dfn class="idl-code" data-dfn-for="DocumentPictureInPictureWindow/setAspectRatio(aspectRatio)" data-dfn-type="argument" data-export id="dom-documentpictureinpicturewindow-setaspectratio-aspectratio-aspectratio"><code><c- g>aspectRatio</c-></code><a class="self-link" href="#dom-documentpictureinpicturewindow-setaspectratio-aspectratio-aspectratio"></a></dfn>);
<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-promise" id="ref-for-idl-promise②"><c- b>Promise</c-></a><<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-undefined" id="ref-for-idl-undefined①"><c- b>undefined</c-></a>> <dfn class="dfn-paneled idl-code" data-dfn-for="DocumentPictureInPictureWindow" data-dfn-type="method" data-export data-lt="setLockAspectRatio(lockAspectRatio)" id="dom-documentpictureinpicturewindow-setlockaspectratio"><code><c- g>setLockAspectRatio</c-></code></dfn>(<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-boolean" id="ref-for-idl-boolean①"><c- b>boolean</c-></a> <dfn class="idl-code" data-dfn-for="DocumentPictureInPictureWindow/setLockAspectRatio(lockAspectRatio)" data-dfn-type="argument" data-export id="dom-documentpictureinpicturewindow-setlockaspectratio-lockaspectratio-lockaspectratio"><code><c- g>lockAspectRatio</c-></code><a class="self-link" href="#dom-documentpictureinpicturewindow-setlockaspectratio-lockaspectratio-lockaspectratio"></a></dfn>);
};
[<a class="idl-code" data-link-type="extended-attribute" href="https://webidl.spec.whatwg.org/#Exposed" id="ref-for-Exposed②"><c- g>Exposed</c-></a>=<c- n>Window</c->]
<c- b>interface</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="interface" data-export id="documentpictureinpictureevent"><code><c- g>DocumentPictureInPictureEvent</c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#event" id="ref-for-event"><c- n>Event</c-></a> {
<dfn class="idl-code" data-dfn-for="DocumentPictureInPictureEvent" data-dfn-type="constructor" data-export data-lt="DocumentPictureInPictureEvent(type, eventInitDict)|constructor(type, eventInitDict)" id="dom-documentpictureinpictureevent-documentpictureinpictureevent"><code><c- g>constructor</c-></code><a class="self-link" href="#dom-documentpictureinpictureevent-documentpictureinpictureevent"></a></dfn>(<a class="idl-code" data-link-type="interface" href="https://webidl.spec.whatwg.org/#idl-DOMString" id="ref-for-idl-DOMString"><c- b>DOMString</c-></a> <dfn class="idl-code" data-dfn-for="DocumentPictureInPictureEvent/DocumentPictureInPictureEvent(type, eventInitDict), DocumentPictureInPictureEvent/constructor(type, eventInitDict)" data-dfn-type="argument" data-export id="dom-documentpictureinpictureevent-documentpictureinpictureevent-type-eventinitdict-type"><code><c- g>type</c-></code><a class="self-link" href="#dom-documentpictureinpictureevent-documentpictureinpictureevent-type-eventinitdict-type"></a></dfn>, <a data-link-type="idl-name" href="#dictdef-documentpictureinpictureeventinit" id="ref-for-dictdef-documentpictureinpictureeventinit"><c- n>DocumentPictureInPictureEventInit</c-></a> <dfn class="idl-code" data-dfn-for="DocumentPictureInPictureEvent/DocumentPictureInPictureEvent(type, eventInitDict), DocumentPictureInPictureEvent/constructor(type, eventInitDict)" data-dfn-type="argument" data-export id="dom-documentpictureinpictureevent-documentpictureinpictureevent-type-eventinitdict-eventinitdict"><code><c- g>eventInitDict</c-></code><a class="self-link" href="#dom-documentpictureinpictureevent-documentpictureinpictureevent-type-eventinitdict-eventinitdict"></a></dfn>);
[<a class="idl-code" data-link-type="extended-attribute" href="https://webidl.spec.whatwg.org/#SameObject" id="ref-for-SameObject①"><c- g>SameObject</c-></a>] <c- b>readonly</c-> <c- b>attribute</c-> <a data-link-type="idl-name" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①⑤"><c- n>DocumentPictureInPictureWindow</c-></a>
<dfn class="dfn-paneled idl-code" data-dfn-for="DocumentPictureInPictureEvent" data-dfn-type="attribute" data-export data-readonly data-type="DocumentPictureInPictureWindow" id="dom-documentpictureinpictureevent-pictureinpicturewindow"><code><c- g>pictureInPictureWindow</c-></code></dfn>;
};
<c- b>dictionary</c-> <dfn class="dfn-paneled idl-code" data-dfn-type="dictionary" data-export id="dictdef-documentpictureinpictureeventinit"><code><c- g>DocumentPictureInPictureEventInit</c-></code></dfn> : <a data-link-type="idl-name" href="https://dom.spec.whatwg.org/#dictdef-eventinit" id="ref-for-dictdef-eventinit"><c- n>EventInit</c-></a> {
<c- b>required</c-> <a data-link-type="idl-name" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①⑥"><c- n>DocumentPictureInPictureWindow</c-></a> <dfn class="idl-code" data-dfn-for="DocumentPictureInPictureEventInit" data-dfn-type="dict-member" data-export data-type="DocumentPictureInPictureWindow " id="dom-documentpictureinpictureeventinit-pictureinpicturewindow"><code><c- g>pictureInPictureWindow</c-></code><a class="self-link" href="#dom-documentpictureinpictureeventinit-pictureinpicturewindow"></a></dfn>;
};
</pre>
<p> A <code class="idl"><a data-link-type="idl" href="#pictureinpicture" id="ref-for-pictureinpicture③">PictureInPicture</a></code> object allows websites to create and open a new <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①⑦">DocumentPictureInPictureWindow</a></code> as well as listen for events related to
opening and closing a <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①⑧">DocumentPictureInPictureWindow</a></code>. </p>
<p>The <code class="idl"><a data-link-type="idl" href="#dom-pictureinpicture-requestwindow" id="ref-for-dom-pictureinpicture-requestwindow①">requestWindow(options)</a></code> method, when invoked, MUST return <a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#a-new-promise" id="ref-for-a-new-promise">a new promise</a> <var>promise</var> and run the following steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel" id="ref-for-in-parallel">in parallel</a>:</p>
<ol>
<li data-md>
<p>Run the <a data-link-type="dfn" href="#open-documentpictureinpicturewindow" id="ref-for-open-documentpictureinpicturewindow">open DocumentPictureInPictureWindow</a> algorithm with <var>options</var>.</p>
<li data-md>
<p>If the previous step threw an exception, reject <var>promise</var> with that exception
and abort these steps.</p>
<li data-md>
<p>Return <var>promise</var> with the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow①⑨">DocumentPictureInPictureWindow</a></code> from step 1.</p>
</ol>
<p></p>
<p> A <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow②⓪">DocumentPictureInPictureWindow</a></code> object represents an always-on-top PiP
window opened by <code class="idl"><a data-link-type="idl" href="#dom-pictureinpicture-requestwindow" id="ref-for-dom-pictureinpicture-requestwindow②">requestWindow()</a></code>. It gives the website a handle into the <code class="idl"><a data-link-type="idl" href="https://dom.spec.whatwg.org/#document" id="ref-for-document⑤">Document</a></code> contained in the window. </p>
<p> The <code class="idl"><a data-link-type="idl" href="#dom-documentpictureinpicturewindow-setaspectratio" id="ref-for-dom-documentpictureinpicturewindow-setaspectratio">setAspectRatio(aspectRatio)</a></code> method, when invoked, MUST return <a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#a-new-promise" id="ref-for-a-new-promise①">a new promise</a> <var>promise</var> and run the following steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel" id="ref-for-in-parallel①">in parallel</a>: </p>
<ol>
<li data-md>
<p>Run the <a data-link-type="dfn" href="#set-aspect-ratio" id="ref-for-set-aspect-ratio">set aspect ratio</a> algorithm with <var>aspectRatio</var>.</p>
<li data-md>
<p>If the previous step threw an exception, reject <var>promise</var> with that exception
and abort these steps.</p>
<li data-md>
<p>Resolve and return <var>promise</var>.</p>
</ol>
<p></p>
<p> The <code class="idl"><a data-link-type="idl" href="#dom-documentpictureinpicturewindow-setlockaspectratio" id="ref-for-dom-documentpictureinpicturewindow-setlockaspectratio">setLockAspectRatio(lockAspectRatio)</a></code> method, when invoked, MUST return <a data-link-type="dfn" href="https://webidl.spec.whatwg.org/#a-new-promise" id="ref-for-a-new-promise②">a new promise</a> <var>promise</var> and run the following steps <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#in-parallel" id="ref-for-in-parallel②">in parallel</a>: </p>
<ol>
<li data-md>
<p>Run the <a data-link-type="dfn" href="#set-lock-aspect-ratio" id="ref-for-set-lock-aspect-ratio">set lock aspect ratio</a> algorithm with <var>lockAspectRatio</var>.</p>
<li data-md>
<p>If the previous step threw an exception, reject <var>promise</var> with that exception
and abort these steps.</p>
<li data-md>
<p>Resolve and return <var>promise</var>.</p>
</ol>
<p></p>
<dl>
<dt data-md><dfn class="dfn-paneled idl-code" data-dfn-for="PictureInPicture" data-dfn-type="event" data-export id="eventdef-pictureinpicture-enterpictureinpicture"><code>enterpictureinpicture</code></dfn>
<dd data-md>
<p>Fired on <code class="idl"><a data-link-type="idl" href="#pictureinpicture" id="ref-for-pictureinpicture④">PictureInPicture</a></code> when a PiP window is opened.</p>
<dt data-md><dfn class="dfn-paneled idl-code" data-dfn-for="PictureInPicture" data-dfn-type="event" data-export id="eventdef-pictureinpicture-leavepictureinpicture"><code>leavepictureinpicture</code></dfn>
<dd data-md>
<p>Fired on <code class="idl"><a data-link-type="idl" href="#pictureinpicture" id="ref-for-pictureinpicture⑤">PictureInPicture</a></code> when a PiP window is closed.</p>
</dl>
<h2 class="heading settled" data-level="6" id="examples"><span class="secno">6. </span><span class="content">Examples</span><a class="self-link" href="#examples"></a></h2>
<p><em>This section is non-normative</em></p>
<h3 class="heading settled" data-level="6.1" id="example-video-player"><span class="secno">6.1. </span><span class="content">Extracting a video player into PiP</span><a class="self-link" href="#example-video-player"></a></h3>
<h4 class="heading settled" data-level="6.1.1" id="example-video-player-html"><span class="secno">6.1.1. </span><span class="content">HTML</span><a class="self-link" href="#example-video-player-html"></a></h4>
<pre class="lang-html highlight"><c- p><</c-><c- f>body</c-><c- p>></c->
<c- p><</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"player-container"</c-><c- p>></c->
<c- p><</c-><c- f>div</c-> <c- e>id</c-><c- o>=</c-><c- s>"player"</c-><c- p>></c->
<c- p><</c-><c- f>video</c-> <c- e>id</c-><c- o>=</c-><c- s>"video"</c-> <c- e>src</c-><c- o>=</c-><c- s>"foo.webm"</c-><c- p>></</c-><c- f>video</c-><c- p>></c->
<c- d><!-- More player elements here. --></c->
<c- p></</c-><c- f>div</c-><c- p>></c->
<c- p></</c-><c- f>div</c-><c- p>></c->
<c- p><</c-><c- f>input</c-> <c- e>type</c-><c- o>=</c-><c- s>"button"</c-> <c- e>onclick</c-><c- o>=</c-><c- s>"enterPiP();"</c-> <c- e>value</c-><c- o>=</c-><c- s>"Enter PiP"</c-> <c- p>/></c->
<c- p></</c-><c- f>body</c-><c- p>></c->
</pre>
<h4 class="heading settled" data-level="6.1.2" id="example-video-player-js"><span class="secno">6.1.2. </span><span class="content">JavaScript</span><a class="self-link" href="#example-video-player-js"></a></h4>
<pre class="lang-javascript highlight"><c- c1>// Handle to the picture-in-picture window.</c->
<c- a>let</c-> pipWindow <c- o>=</c-> <c- kc>null</c-><c- p>;</c->
<c- a>function</c-> enterPiP<c- p>()</c-> <c- p>{</c->
<c- a>const</c-> player <c- o>=</c-> document<c- p>.</c->querySelector<c- p>(</c-><c- t>'#player'</c-><c- p>);</c->
<c- c1>// Lock the aspect ratio so the window is always properly sized to the video.</c->
<c- a>const</c-> pipOptions <c- o>=</c-> <c- p>{</c->
initialAspectRatio<c- o>:</c-> player<c- p>.</c->clientWidth <c- o>/</c-> player<c- p>.</c->clientHeight<c- p>,</c->
lockAspectRatio<c- o>:</c-> <c- kc>true</c-><c- p>,</c->
<c- p>};</c->
navigator<c- p>.</c->pictureInPicture<c- p>.</c->requestWindow<c- p>(</c->pipOptions<c- p>).</c->then<c- p>((</c->_pipWin<c- p>)</c-> <c- p>=></c-> <c- p>{</c->
pipWindow <c- o>=</c-> _pipWin<c- p>;</c->
<c- c1>// Style remaining container to imply the player is in PiP.</c->
playerContainer<c- p>.</c->classList<c- p>.</c->add<c- p>(</c-><c- t>'pip-mode'</c-><c- p>);</c->
<c- c1>// Add styles to the PiP window.</c->
<c- a>const</c-> styleLink <c- o>=</c-> document<c- p>.</c->createElement<c- p>(</c-><c- t>'link'</c-><c- p>);</c->
styleLink<c- p>.</c->href <c- o>=</c-> <c- t>'pip.css'</c-><c- p>;</c->
styleLink<c- p>.</c->rel <c- o>=</c-> <c- t>'stylesheet'</c-><c- p>;</c->
<c- a>const</c-> pipBody <c- o>=</c-> pipWindow<c- p>.</c->document<c- p>.</c->body<c- p>;</c->
pipBody<c- p>.</c->append<c- p>(</c->styleLink<c- p>);</c->
<c- c1>// Add player to the PiP window.</c->
pipBody<c- p>.</c->append<c- p>(</c->player<c- p>);</c->
<c- c1>// Listen for the PiP closing event to put the video back.</c->
navigator<c- p>.</c->pictureInPicture<c- p>.</c->addEventListener<c- p>(</c-><c- t>'leavepictureinpicture'</c-><c- p>,</c-> onLeavePiP<c- p>,</c-> <c- p>{</c-> once<c- o>:</c-> <c- kc>true</c-> <c- p>});</c->
<c- p>});</c->
<c- p>}</c->
<c- c1>// Called when the PiP window has closed.</c->
<c- a>function</c-> onLeavePiP<c- p>(</c->event<c- p>)</c-> <c- p>{</c->
<c- k>if</c-> <c- p>(</c->event<c- p>.</c->pictureInPictureWindow <c- o>!==</c-> pipWindow<c- p>)</c-> <c- p>{</c->
<c- k>return</c-><c- p>;</c->
<c- p>}</c->
<c- c1>// Remove PiP styling from the container.</c->
<c- a>const</c-> playerContainer <c- o>=</c-> document<c- p>.</c->querySelector<c- p>(</c-><c- t>'#player-container'</c-><c- p>);</c->
playerContainer<c- p>.</c->classList<c- p>.</c->remove<c- p>(</c-><c- t>'pip-mode'</c-><c- p>);</c->
<c- c1>// Add the player back to the main window.</c->
<c- a>const</c-> player <c- o>=</c-> pipWindow<c- p>.</c->document<c- p>.</c->querySelector<c- p>(</c-><c- t>'#player'</c-><c- p>);</c->
playerContainer<c- p>.</c->append<c- p>(</c->player<c- p>);</c->
pipWindow <c- o>=</c-> <c- kc>null</c-><c- p>;</c->
<c- p>}</c->
</pre>
<h3 class="heading settled" data-level="6.2" id="example-access-elements"><span class="secno">6.2. </span><span class="content">Accessing elements on the PiP Window</span><a class="self-link" href="#example-access-elements"></a></h3>
<p>The document attribute provides access to the DOM of the <code class="idl"><a data-link-type="idl" href="#documentpictureinpicturewindow" id="ref-for-documentpictureinpicturewindow②①">DocumentPictureInPictureWindow</a></code> object:</p>
<pre class="lang-javascript highlight"><c- a>const</c-> video <c- o>=</c-> pipWindow<c- p>.</c->document<c- p>.</c->querySelector<c- p>(</c-><c- t>'#video'</c-><c- p>);</c->
video<c- p>.</c->loop <c- o>=</c-> <c- kc>true</c-><c- p>;</c->
</pre>
<h3 class="heading settled" data-level="6.3" id="example-listen-events"><span class="secno">6.3. </span><span class="content">Listening to events on the PiP Window</span><a class="self-link" href="#example-listen-events"></a></h3>
<p>As part of creating an improved picture-in-picture experience, websites will often want
customize buttons and controls that need to respond to user input events such as clicks.</p>
<pre class="lang-javascript highlight"><c- a>const</c-> video <c- o>=</c-> pipWindow<c- p>.</c->document<c- p>.</c->querySelector<c- p>(</c-><c- t>'#video'</c-><c- p>);</c->
<c- a>const</c-> muteButton <c- o>=</c-> pipWindow<c- p>.</c->document<c- p>.</c->createElement<c- p>(</c-><c- t>'button'</c-><c- p>);</c->
muteButton<c- p>.</c->textContent <c- o>=</c-> <c- t>'Toggle mute'</c-><c- p>;</c->
muteButton<c- p>.</c->addEventListener<c- p>(</c-><c- t>'click'</c-><c- p>,</c-> <c- p>()</c-> <c- p>=></c-> <c- p>{</c->
video<c- p>.</c->muted <c- o>=</c-> <c- o>!</c->video<c- p>.</c->muted<c- p>;</c->
<c- p>});</c->
pipWindow<c- p>.</c->document<c- p>.</c->body<c- p>.</c->append<c- p>(</c->muteButton<c- p>);</c->
</pre>
<h3 class="heading settled" data-level="6.4" id="example-exiting-pip"><span class="secno">6.4. </span><span class="content">Exiting PiP</span><a class="self-link" href="#example-exiting-pip"></a></h3>