OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 var readyPromise = new Promise(function(resolve, reject) { | |
6 navigator.serviceWorker.register('sw.js').then(function() { | |
7 return navigator.serviceWorker.ready; | |
8 }).then(function(registration) { | |
9 resolve('ready'); | |
10 }).catch(function(err) { | |
11 reject(err); | |
12 }); | |
13 }); | |
14 | |
15 window.runServiceWorker = function() { | |
16 readyPromise.then(function(message) { | |
17 window.domAutomationController.send(message); | |
18 }).catch(function(err) { | |
19 window.domAutomationController.send('FAILURE'); | |
20 }); | |
21 }; | |
22 | |
23 window.createTabThenUpdate = function() { | |
24 navigator.serviceWorker.onmessage = function(e) { | |
25 if (e.data == 'chrome.tabs.onUpdated callback') { | |
Devlin
2017/06/20 20:31:19
nit: maybe just send e.data in call cases? If it'
lazyboy
2017/06/22 02:46:56
I was more interested in hinting about e.data's va
| |
26 window.domAutomationController.send(e.data); | |
27 } else { | |
28 window.domAutomationController.send('FAILURE'); | |
29 } | |
30 }; | |
31 var url = chrome.extension.getURL('on_updated.html'); | |
32 chrome.tabs.create({url: url}); | |
33 }; | |
OLD | NEW |