From 5173bdc5424e7c874b3f2abfad706cea2e38ebc3 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Tue, 1 Nov 2016 16:01:36 -0700 Subject: [PATCH] Log service worker events and add extension API when SW updates e.g. you could use this extension API to show the user that an update is available and they should update. --- .../production-app.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/intermediate-representation-dir/production-app.js b/lib/intermediate-representation-dir/production-app.js index 664c295e22c1a..c650556e28af6 100644 --- a/lib/intermediate-representation-dir/production-app.js +++ b/lib/intermediate-representation-dir/production-app.js @@ -28,8 +28,22 @@ try { // Install service worker. runtime.install({ - onInstalled () { - console.log(`App is ready for offline usage`) + onInstalled: () => { + console.log("SW Event:", "onInstalled") + }, + onUpdating: () => { + console.log("SW Event:", "onUpdating") + }, + onUpdateReady: () => { + console.log("SW Event:", "onUpdateReady") + runtime.applyUpdate() + }, + onUpdated: () => { + console.log("SW Event:", "onUpdated") + apiRunner('swOnUpdated') + }, + onUninstalled: () => { + console.log("SW Event:", "onUninstalled") }, })