-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
63 lines (58 loc) · 2.42 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="max-width: 700px; margin: 0 auto 0 auto;">
<button id="swinstall">Install Service Worker</button>
<button id="swuninstall">Uninstall Service Worker</button>
<div id="js-log" style="height: 400px; overflow: scroll; color: white; background: black; font-family: monospace; line-height: 150%; font-size: 12px; padding: 7px;"></div>
<a href="http://mattandre.ws">mattandre.ws</a> <a href="http://twitter.com/andrewsmatt">@andrewsmatt</a>
</div>
<script>
window.addEventListener('message', function() {
debugger;
});
function log() {
var el = document.createElement('div');
el.innerHTML = Array.prototype.join.call(arguments, '<br />');
document.getElementById('js-log').appendChild(el);
}
var swRegistration = null;
if (navigator.serviceWorker) {
log("Browser supports Service Worker");
if (navigator.serviceWorker.current) {
log("Current Service Worker state: \\o/");
log('Go to chrome://serviceworker-internals/ to see Service Worker debug output');
} else {
log("No Service Worker active...");
}
document.getElementById('swinstall').addEventListener('click', function() {
log('About to try to install a Service Worker');
navigator.serviceWorker.register('./worker.js', { scope: 'serviceworker-simple' })
.then(function(serviceWorker) {
swRegistration = serviceWorker;
log('Successfully installed ServiceWorker');
log('Go to chrome://serviceworker-internals/ to see Service Worker debug output');
serviceWorker.addEventListener('statechange', function(event) {
log("Worker state is now "+event.target.state);
});
}, function(why) {
log('Failed to install:' + why);
});
});
document.getElementById('swuninstall').addEventListener('click', function() {
log('About to try to uninstall a Service Worker');
swRegistration.unregister()
.then(function() {
log('Successfully uninstalled ServiceWorker');
}, function(why) {
log('Failed to uninstall'+why);
});
});
} else {
log("Browser does not support Service Worker, are you using Chrome Canary? Is the Service Worker flag switched on? chrome://flags/#enable-service-worker");
}
</script>
</body>
</html>