-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
33 lines (30 loc) · 904 Bytes
/
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
<html>
<head>
<title></title>
<script>
</script>
<style>
</style>
</head>
<body>
<h3>ServiceWorkerConsole (Gecko only for now. Chromium seems to have issues with MessageEvent.source)</h3>
<textarea id="src" onkeyup="sendToWorker(this.value)" cols="80" rows="10"></textarea><br>
<textarea id="result" readonly cols="80" rows="10"></textarea>
<script>
navigator.serviceWorker.register("sw.js");
navigator.serviceWorker.onmessage = function(e) {
document.getElementById("result").value = e.data;
}
var timerID = 0;
function sendToWorker(val) {
clearTimeout(timerID);
timerID = setTimeout(sendToWorkerNow, 500, val)
}
function sendToWorkerNow(val) {
navigator.serviceWorker.ready.then(function(p) {
p.active.postMessage(val);
})
}
</script>
</body>
</html>