OLD | NEW |
---|---|
1 var port = null; | 1 var port = null; |
2 var in_scope_but_not_controlled = null; | |
3 | |
4 self.oninstall = function(e) { | |
5 clients.matchAll({ includeUncontrolled : true }).then(function(cs) { | |
6 return cs[0].navigate('blank.html'); | |
7 }) | |
8 .catch(function(e) { | |
9 in_scope_but_not_controlled = e.name.toString(); | |
nhiroki
2016/01/20 03:56:34
This might not work because there should be only a
zino
2016/01/20 17:24:05
Good catch!
| |
10 }); | |
11 }; | |
2 | 12 |
3 self.onmessage = function(e) { | 13 self.onmessage = function(e) { |
4 port = e.data.port; | 14 port = e.data.port; |
5 port.onmessage = on_message; | 15 port.onmessage = on_message; |
6 port.postMessage('ready'); | 16 port.postMessage(in_scope_but_not_controlled); |
7 }; | 17 }; |
8 | 18 |
9 function on_message(e) { | 19 function on_message(e) { |
10 var url = e.data; | 20 var url = e.data; |
11 var client; | 21 var client; |
12 | 22 |
13 self.clients.matchAll({ includeUncontrolled : true }).then(function(cs) { | 23 clients.matchAll({ includeUncontrolled : true }).then(function(cs) { |
14 cs.forEach(function(c) { c.frameType == 'nested' && (client = c); }); | 24 cs.forEach(function(c) { c.frameType == 'nested' && (client = c); }); |
15 return client.navigate(url); | 25 return client.navigate(url); |
16 }) | 26 }) |
17 .then(function(c) { | 27 .then(function(c) { |
18 if (!c) | 28 if (!c) |
19 port.postMessage(c); | 29 port.postMessage(c); |
20 else | 30 else |
21 port.postMessage(c.url); | 31 port.postMessage(c.url); |
22 }) | 32 }) |
23 .catch(function(e) { | 33 .catch(function(e) { |
24 port.postMessage(e.name); | 34 port.postMessage(e.name); |
25 }); | 35 }); |
26 } | 36 } |
OLD | NEW |