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 // e.data -> 'chrome.tabs.onUpdated callback'. |
| 26 window.domAutomationController.send(e.data); |
| 27 }; |
| 28 var url = chrome.extension.getURL('on_updated.html'); |
| 29 chrome.tabs.create({url: url}); |
| 30 }; |
OLD | NEW |