-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
122 lines (113 loc) · 3.61 KB
/
demo.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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>sw-status Demo</title>
<link rel="import" href="sw-status.html">
<style>
#content {
margin: 0 0 0 300px;
padding: 5px;
}
#middle {
float: left;
width: 100%;
}
#lside {
float: left;
margin-left: -100%;
width: 300px;
border-right: solid 1px black;
}
#js-log {
min-height: 300px;
max-height: 800px;
width: 95%;
overflow-y: auto;
color: white;
background: black;
font-family: monospace;
line-height: 150%;
font-size: 12px;
padding: 7px;
padding-right: 0px;
margin-bottom: 10px;
}
ul {
padding-left: 20px;
}
#frame {
width: 100%;
height: 800px;
overflow-y: auto;
}
</style>
</head>
<body unresolved>
<div style="margin: 0 auto 0 auto;">
<div id="wrapper">
<div id="middle">
<div id="content">
<p>An example of using <code><sw-status></code>:</p>
<sw-status></sw-status>
</div>
</div>
<div id="lside">
<button id="install">Install Service Worker</button>
<button id="uninstall">Uninstall Service Worker</button>
<div id="log-wrapper">
<div> <b>Log</b></div>
<div id="js-log"> </div>
</div>
<p>
<ul>
<li>A page is not controlled by a ServiceWorker unless it is loaded after the ServiceWorker is registered.
<li>Ctrl-Shift-R will force the page to not be controlled by a ServiceWorker, even if one is registered.
<li>A page remains controlled by a ServiceWorker even after the worker is uninstalled.
<li>ServiceWorker spec is <a href="https://slightlyoff.github.io/ServiceWorker/spec/service_worker/">here</a>.
</ul>
</p>
</div>
</div>
</div>
<script>
function log() {
var el = document.createElement('div');
el.innerHTML = Array.prototype.join.call(
Array.prototype.map.call(arguments, function(x) { return "> " + x; }),
'<br />');
document.getElementById('js-log').appendChild(el);
}
if (navigator.serviceWorker) {
document.getElementById('install').addEventListener('click', function() {
navigator.serviceWorker.register(
'empty-sw.js', { scope: window.location.pathname })
.then(function(serviceWorker) {
log('Successfully installed ServiceWorker.');
}, function(why) {
log('Failed to install: ' + why);
});
});
document.getElementById('uninstall').addEventListener('click', function() {
navigator.serviceWorker.getRegistration(window.location.pathname)
.then(function(registration) {
if (!registration) {
log('No registration controlling page "' + window.location.pathname + '".');
return;
}
registration.unregister()
.then(function(yn) {
log('Unregistration ' + (yn ? 'successful.' : 'unsuccessful.'));
}, function(error) {
log('Error unregistering: ' + error);
});
}, function(error) {
log("Error getting registration: ", error);
});
});
} 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>