-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
49 lines (46 loc) · 1.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<head>
<script>
function log(...args) {
const text = args.map(arg => {
if (typeof arg == 'string') return arg
if (typeof arg == 'function') return String(arg)
try {
return JSON.stringify(arg, null, 2)
}
catch (e) {
return `<JSON error:${e}>`
}
}).join(' ')
document.body.append(Object.assign(document.createElement('pre'), {
textContent: text
}))
}
</script>
<script type="module">
window.sw = await navigator.serviceWorker.register("sw.js", { type: 'module' });
if (!navigator.serviceWorker.controller) {
await new Promise(resolve => navigator.serviceWorker.addEventListener('controllerchange', () => {
log('controllerchange', navigator.serviceWorker.controller)
resolve()
}, { once: true }))
}
log(navigator.serviceWorker.controller.scriptURL + ' ' + navigator.serviceWorker.controller.state);
navigator.serviceWorker.addEventListener('message', e => {
//log('message', e.data)
e.stopImmediatePropagation()
})
const response = await fetch('fake')
const reader = response.body.getReader()
log(new Date + '')
while (true) {
const { value, done } = await reader.read()
if (done) break
const text = new TextDecoder().decode(value).slice(0, 15)
log(value.length, text)
}
log(new Date + '')
log(...response.headers)
</script>
</head>
<body>
</body>