| ... |
... |
@@ -1,9 +1,25 @@ |
| 1 |
1 |
if ('serviceWorker' in navigator) { |
| 2 |
2 |
navigator.serviceWorker.register('/bin/jsx/LiveTableServiceWorker?minify=false', { 'scope': '/bin/view/Membership'}) |
| 3 |
3 |
.then((reg) => { |
| 4 |
|
- reg.update(); |
|
4 |
+ reg.update(); |
|
5 |
+ if(reg.installing) { |
|
6 |
+ const sw = reg.installing || reg.waiting; |
|
7 |
+ sw.onstatechange = function() { |
|
8 |
+ if (sw.state === 'installed') { |
|
9 |
+ // SW installed. Reload for SW intercept serving SW-enabled page. |
|
10 |
+ window.location.reload(); |
|
11 |
+ } |
|
12 |
+ }; |
|
13 |
+ } else if (reg.active) { |
|
14 |
+ // something's not right or SW is bypassed. previously-installed SW should have redirected this request to different page |
|
15 |
+ throw(new Error('Service Worker is installed and not redirecting.')) |
|
16 |
+} |
|
17 |
+ |
|
18 |
+ // registration worked |
|
19 |
+ console.log('Registration succeeded. Scope is ' + reg.scope); |
| 5 |
5 |
}).catch((error) => { |
| 6 |
|
- console.error('Registration failed with ' + error); |
|
21 |
+ // registration failed |
|
22 |
+ console.log('Registration failed with ' + error); |
| 7 |
7 |
}); |
| 8 |
8 |
} |
| 9 |
9 |
|