blob: 2b7511c7889912c6e781450ceed5652ad5c0c759 (
plain)
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
|
"use strict";
function handleRequest(request, response) {
response.setHeader("Content-Type", "html", false);
// Check the params and set the cross-origin-opener policy headers if needed
const query = new URLSearchParams(request.queryString);
if (query.get("crossOriginIsolated") === "true") {
response.setHeader("Cross-Origin-Opener-Policy", "same-origin", false);
}
// We always want the iframe to have a different host from the top-level document.
const iframeHost =
request.host === "example.com" ? "example.org" : "example.com";
const iframeOrigin = `${request.scheme}://${iframeHost}`;
const IFRAME_HTML = `
<!doctype html>
<html>
<head>
<meta charset=utf8>
<script>
globalThis.initialMatchesPrefersDarkColorScheme =
window.matchMedia("(prefers-color-scheme: dark)").matches;
globalThis.initialMatchesCoarsePointer =
window.matchMedia("(pointer: coarse)").matches;
globalThis.initialDevicePixelRatio = window.devicePixelRatio;
globalThis.initialUserAgent = navigator.userAgent;
</script>
<style>
html { background: cyan;}
button {
font-size: 2em;
padding-inline: 1em;
}
@media (prefers-color-scheme: dark) {
html {background: darkred;}
}
</style>
</head>
<body>
<h1>Iframe</h1>
<button>Target</button>
</body>
</html>`;
const HTML = `
<!doctype html>
<html>
<head>
<meta charset=utf8>
<title>test</title>
<script type="application/javascript">
"use strict";
/*
* Store the result of dark color-scheme match very early in the document loading process
* so we can assert in tests that the simulation starts early enough.
*/
globalThis.initialMatchesPrefersDarkColorScheme =
window.matchMedia("(prefers-color-scheme: dark)").matches;
globalThis.initialMatchesCoarsePointer =
window.matchMedia("(pointer: coarse)").matches;
globalThis.initialDevicePixelRatio = window.devicePixelRatio
globalThis.initialUserAgent = navigator.userAgent;
</script>
<style>
iframe {
display: block;
margin-top: 1em;
}
button {
font-size: 2em;
padding-inline: 1em;
}
@media (prefers-color-scheme: dark) {
html {
background-color: darkblue;
}
}
</style>
</head>
<body>
<h1>Test color-scheme simulation</h1>
<button>Target</button>
<iframe src='${iframeOrigin}/document-builder.sjs?html=${encodeURI(
IFRAME_HTML
)}'></iframe>
</body>
</html>`;
response.write(HTML);
}
|