jekyll-pwa-workbox 0.0.7.alpha → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pwa-workbox.rb +1 -1
  3. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-background-sync.dev.js +12 -13
  4. data/lib/vendor/workbox-v5.0.0/workbox-background-sync.dev.js.map +1 -0
  5. data/lib/vendor/workbox-v5.0.0/workbox-background-sync.prod.js +2 -0
  6. data/lib/vendor/workbox-v5.0.0/workbox-background-sync.prod.js.map +1 -0
  7. data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.dev.js +288 -0
  8. data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.dev.js.map +1 -0
  9. data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.prod.js +2 -0
  10. data/lib/vendor/workbox-v5.0.0/workbox-broadcast-update.prod.js.map +1 -0
  11. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-cacheable-response.dev.js +6 -7
  12. data/lib/vendor/workbox-v5.0.0/workbox-cacheable-response.dev.js.map +1 -0
  13. data/lib/vendor/workbox-v5.0.0/workbox-cacheable-response.prod.js +2 -0
  14. data/lib/vendor/workbox-v5.0.0/workbox-cacheable-response.prod.js.map +1 -0
  15. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-core.dev.js +306 -67
  16. data/lib/vendor/workbox-v5.0.0/workbox-core.dev.js.map +1 -0
  17. data/lib/vendor/workbox-v5.0.0/workbox-core.prod.js +2 -0
  18. data/lib/vendor/workbox-v5.0.0/workbox-core.prod.js.map +1 -0
  19. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-expiration.dev.js +13 -14
  20. data/lib/vendor/workbox-v5.0.0/workbox-expiration.dev.js.map +1 -0
  21. data/lib/vendor/workbox-v5.0.0/workbox-expiration.prod.js +2 -0
  22. data/lib/vendor/workbox-v5.0.0/workbox-expiration.prod.js.map +1 -0
  23. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-navigation-preload.dev.js +4 -5
  24. data/lib/vendor/workbox-v5.0.0/workbox-navigation-preload.dev.js.map +1 -0
  25. data/lib/vendor/workbox-v5.0.0/workbox-navigation-preload.prod.js +2 -0
  26. data/lib/vendor/workbox-v5.0.0/workbox-navigation-preload.prod.js.map +1 -0
  27. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-offline-ga.dev.js +12 -13
  28. data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.dev.js.map +1 -0
  29. data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.prod.js +2 -0
  30. data/lib/vendor/workbox-v5.0.0/workbox-offline-ga.prod.js.map +1 -0
  31. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-precaching.dev.js +314 -86
  32. data/lib/vendor/workbox-v5.0.0/workbox-precaching.dev.js.map +1 -0
  33. data/lib/vendor/workbox-v5.0.0/workbox-precaching.prod.js +2 -0
  34. data/lib/vendor/workbox-v5.0.0/workbox-precaching.prod.js.map +1 -0
  35. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-range-requests.dev.js +8 -9
  36. data/lib/vendor/workbox-v5.0.0/workbox-range-requests.dev.js.map +1 -0
  37. data/lib/vendor/workbox-v5.0.0/workbox-range-requests.prod.js +2 -0
  38. data/lib/vendor/workbox-v5.0.0/workbox-range-requests.prod.js.map +1 -0
  39. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-routing.dev.js +79 -182
  40. data/lib/vendor/workbox-v5.0.0/workbox-routing.dev.js.map +1 -0
  41. data/lib/vendor/workbox-v5.0.0/workbox-routing.prod.js +2 -0
  42. data/lib/vendor/workbox-v5.0.0/workbox-routing.prod.js.map +1 -0
  43. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-strategies.dev.js +23 -227
  44. data/lib/vendor/workbox-v5.0.0/workbox-strategies.dev.js.map +1 -0
  45. data/lib/vendor/workbox-v5.0.0/workbox-strategies.prod.js +2 -0
  46. data/lib/vendor/workbox-v5.0.0/workbox-strategies.prod.js.map +1 -0
  47. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-streams.dev.js +16 -31
  48. data/lib/vendor/workbox-v5.0.0/workbox-streams.dev.js.map +1 -0
  49. data/lib/vendor/workbox-v5.0.0/workbox-streams.prod.js +2 -0
  50. data/lib/vendor/workbox-v5.0.0/workbox-streams.prod.js.map +1 -0
  51. data/lib/vendor/workbox-v5.0.0/workbox-sw.js +2 -0
  52. data/lib/vendor/workbox-v5.0.0/workbox-sw.js.map +1 -0
  53. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-window.dev.es5.mjs +317 -113
  54. data/lib/vendor/workbox-v5.0.0/workbox-window.dev.es5.mjs.map +1 -0
  55. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-window.dev.mjs +244 -44
  56. data/lib/vendor/workbox-v5.0.0/workbox-window.dev.mjs.map +1 -0
  57. data/lib/vendor/{workbox-v5.0.0.alpha1 → workbox-v5.0.0}/workbox-window.dev.umd.js +317 -113
  58. data/lib/vendor/workbox-v5.0.0/workbox-window.dev.umd.js.map +1 -0
  59. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.es5.mjs +2 -0
  60. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.es5.mjs.map +1 -0
  61. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.mjs +2 -0
  62. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.mjs.map +1 -0
  63. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.umd.js +2 -0
  64. data/lib/vendor/workbox-v5.0.0/workbox-window.prod.umd.js.map +1 -0
  65. metadata +70 -69
  66. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.dev.js.map +0 -1
  67. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js +0 -2
  68. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-background-sync.prod.js.map +0 -1
  69. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js +0 -486
  70. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.dev.js.map +0 -1
  71. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js +0 -2
  72. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-broadcast-update.prod.js.map +0 -1
  73. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.dev.js.map +0 -1
  74. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js +0 -2
  75. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-cacheable-response.prod.js.map +0 -1
  76. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.dev.js.map +0 -1
  77. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js +0 -2
  78. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-core.prod.js.map +0 -1
  79. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.dev.js.map +0 -1
  80. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js +0 -2
  81. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-expiration.prod.js.map +0 -1
  82. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.dev.js.map +0 -1
  83. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js +0 -2
  84. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-navigation-preload.prod.js.map +0 -1
  85. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.dev.js.map +0 -1
  86. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js +0 -2
  87. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-offline-ga.prod.js.map +0 -1
  88. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.dev.js.map +0 -1
  89. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js +0 -2
  90. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-precaching.prod.js.map +0 -1
  91. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.dev.js.map +0 -1
  92. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js +0 -2
  93. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-range-requests.prod.js.map +0 -1
  94. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.dev.js.map +0 -1
  95. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js +0 -2
  96. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-routing.prod.js.map +0 -1
  97. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.dev.js.map +0 -1
  98. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js +0 -2
  99. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-strategies.prod.js.map +0 -1
  100. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.dev.js.map +0 -1
  101. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js +0 -2
  102. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-streams.prod.js.map +0 -1
  103. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js +0 -2
  104. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-sw.js.map +0 -1
  105. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.es5.mjs.map +0 -1
  106. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.mjs.map +0 -1
  107. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.dev.umd.js.map +0 -1
  108. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs +0 -2
  109. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.es5.mjs.map +0 -1
  110. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs +0 -2
  111. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.mjs.map +0 -1
  112. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js +0 -2
  113. data/lib/vendor/workbox-v5.0.0.alpha1/workbox-window.prod.umd.js.map +0 -1
@@ -4,9 +4,8 @@
4
4
  (global = global || self, factory(global.workbox = {}));
5
5
  }(this, function (exports) { 'use strict';
6
6
 
7
- // @ts-ignore
8
7
  try {
9
- self['workbox:window:5.0.0-alpha.0'] && _();
8
+ self['workbox:window:5.0.0'] && _();
10
9
  } catch (e) {}
11
10
 
12
11
  /*
@@ -28,7 +27,6 @@
28
27
  * @param {ServiceWorker} sw The service worker to send the message to.
29
28
  * @param {Object} data An object to send to the service worker.
30
29
  * @return {Promise<Object|undefined>}
31
- *
32
30
  * @memberof module:workbox-window
33
31
  */
34
32
 
@@ -66,9 +64,8 @@
66
64
  subClass.__proto__ = superClass;
67
65
  }
68
66
 
69
- // @ts-ignore
70
67
  try {
71
- self['workbox:core:5.0.0-alpha.1'] && _();
68
+ self['workbox:core:5.0.0'] && _();
72
69
  } catch (e) {}
73
70
 
74
71
  /*
@@ -100,6 +97,23 @@
100
97
  });
101
98
  };
102
99
 
100
+ /*
101
+ Copyright 2019 Google LLC
102
+ Use of this source code is governed by an MIT-style
103
+ license that can be found in the LICENSE file or at
104
+ https://opensource.org/licenses/MIT.
105
+ */
106
+ /**
107
+ * A helper function that prevents a promise from being flagged as unused.
108
+ *
109
+ * @private
110
+ **/
111
+
112
+ function dontWaitFor(promise) {
113
+ // Effective no-op.
114
+ promise.then(function () {});
115
+ }
116
+
103
117
  /*
104
118
  Copyright 2019 Google LLC
105
119
  Use of this source code is governed by an MIT-style
@@ -107,6 +121,12 @@
107
121
  https://opensource.org/licenses/MIT.
108
122
  */
109
123
  var logger = function () {
124
+ // Don't overwrite this value if it's already set.
125
+ // See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
126
+ if (!('__WB_DISABLE_DEV_LOGS' in self)) {
127
+ self.__WB_DISABLE_DEV_LOGS = false;
128
+ }
129
+
110
130
  var inGroup = false;
111
131
  var methodToColorMap = {
112
132
  debug: "#7f8c8d",
@@ -120,6 +140,10 @@
120
140
  var print = function print(method, args) {
121
141
  var _console2;
122
142
 
143
+ if (self.__WB_DISABLE_DEV_LOGS) {
144
+ return;
145
+ }
146
+
123
147
  if (method === 'groupCollapsed') {
124
148
  // Safari doesn't print all console.groupCollapsed() arguments:
125
149
  // https://bugs.webkit.org/show_bug.cgi?id=182754
@@ -151,7 +175,7 @@
151
175
  var loggerMethods = Object.keys(methodToColorMap);
152
176
 
153
177
  var _loop = function _loop() {
154
- var key = loggerMethods[_i];
178
+ var key = _loggerMethods[_i];
155
179
  var method = key;
156
180
 
157
181
  api[method] = function () {
@@ -163,7 +187,7 @@
163
187
  };
164
188
  };
165
189
 
166
- for (var _i = 0; _i < loggerMethods.length; _i++) {
190
+ for (var _i = 0, _loggerMethods = loggerMethods; _i < _loggerMethods.length; _i++) {
167
191
  _loop();
168
192
  }
169
193
 
@@ -177,18 +201,18 @@
177
201
  license that can be found in the LICENSE file or at
178
202
  https://opensource.org/licenses/MIT.
179
203
  */
204
+
180
205
  /**
181
206
  * A minimal `EventTarget` shim.
182
207
  * This is necessary because not all browsers support constructable
183
208
  * `EventTarget`, so using a real `EventTarget` will error.
184
209
  * @private
185
210
  */
186
-
187
211
  var WorkboxEventTarget =
188
212
  /*#__PURE__*/
189
213
  function () {
190
214
  function WorkboxEventTarget() {
191
- this._eventListenerRegistry = {};
215
+ this._eventListenerRegistry = new Map();
192
216
  }
193
217
  /**
194
218
  * @param {string} type
@@ -200,23 +224,25 @@
200
224
  var _proto = WorkboxEventTarget.prototype;
201
225
 
202
226
  _proto.addEventListener = function addEventListener(type, listener) {
203
- this._getEventListenersByType(type).add(listener);
204
- };
227
+ var foo = this._getEventListenersByType(type);
228
+
229
+ foo.add(listener);
230
+ }
205
231
  /**
206
232
  * @param {string} type
207
233
  * @param {Function} listener
208
234
  * @private
209
235
  */
210
-
236
+ ;
211
237
 
212
238
  _proto.removeEventListener = function removeEventListener(type, listener) {
213
239
  this._getEventListenersByType(type).delete(listener);
214
- };
240
+ }
215
241
  /**
216
242
  * @param {Object} event
217
243
  * @private
218
244
  */
219
-
245
+ ;
220
246
 
221
247
  _proto.dispatchEvent = function dispatchEvent(event) {
222
248
  event.target = this;
@@ -238,7 +264,7 @@
238
264
  var listener = _ref;
239
265
  listener(event);
240
266
  }
241
- };
267
+ }
242
268
  /**
243
269
  * Returns a Set of listeners associated with the passed event type.
244
270
  * If no handlers have been registered, an empty Set is returned.
@@ -247,10 +273,14 @@
247
273
  * @return {Set<ListenerCallback>} An array of handler functions.
248
274
  * @private
249
275
  */
250
-
276
+ ;
251
277
 
252
278
  _proto._getEventListenersByType = function _getEventListenersByType(type) {
253
- return this._eventListenerRegistry[type] = this._eventListenerRegistry[type] || new Set();
279
+ if (!this._eventListenerRegistry.has(type)) {
280
+ this._eventListenerRegistry.set(type, new Set());
281
+ }
282
+
283
+ return this._eventListenerRegistry.get(type);
254
284
  };
255
285
 
256
286
  return WorkboxEventTarget;
@@ -298,20 +328,24 @@
298
328
  Object.assign(this, props);
299
329
  };
300
330
 
301
- function _catch(body, recover) {
302
- try {
303
- var result = body();
304
- } catch (e) {
305
- return recover(e);
331
+ // `skipWaiting()` wasn't called. This 200 amount wasn't scientifically
332
+ // chosen, but it seems to avoid false positives in my testing.
333
+
334
+ function _await(value, then, direct) {
335
+ if (direct) {
336
+ return then ? then(value) : value;
306
337
  }
307
338
 
308
- if (result && result.then) {
309
- return result.then(void 0, recover);
339
+ if (!value || !value.then) {
340
+ value = Promise.resolve(value);
310
341
  }
311
342
 
312
- return result;
343
+ return then ? value.then(then) : value;
313
344
  }
314
345
 
346
+ var WAITING_TIMEOUT_DURATION = 200; // The amount of time after a registration that we can reasonably conclude
347
+ // that the registration didn't trigger an update.
348
+
315
349
  function _async(f) {
316
350
  return function () {
317
351
  for (var args = [], i = 0; i < arguments.length; i++) {
@@ -326,41 +360,6 @@
326
360
  };
327
361
  }
328
362
 
329
- function _invoke(body, then) {
330
- var result = body();
331
-
332
- if (result && result.then) {
333
- return result.then(then);
334
- }
335
-
336
- return then(result);
337
- }
338
-
339
- function _await(value, then, direct) {
340
- if (direct) {
341
- return then ? then(value) : value;
342
- }
343
-
344
- if (!value || !value.then) {
345
- value = Promise.resolve(value);
346
- }
347
-
348
- return then ? value.then(then) : value;
349
- }
350
-
351
- function _awaitIgnored(value, direct) {
352
- if (!direct) {
353
- return value && value.then ? value.then(_empty) : Promise.resolve();
354
- }
355
- }
356
-
357
- function _empty() {}
358
- // `skipWaiting()` wasn't called. This 200 amount wasn't scientifically
359
- // chosen, but it seems to avoid false positives in my testing.
360
-
361
- var WAITING_TIMEOUT_DURATION = 200; // The amount of time after a registration that we can reasonably conclude
362
- // that the registration didn't trigger an update.
363
-
364
363
  var REGISTRATION_TIMEOUT_DURATION = 60000;
365
364
  /**
366
365
  * A class to aid in handling service worker registration, updates, and
@@ -375,10 +374,11 @@
375
374
  * @fires [externalinstalled]{@link module:workbox-window.Workbox#externalinstalled}
376
375
  * @fires [externalwaiting]{@link module:workbox-window.Workbox#externalwaiting}
377
376
  * @fires [externalactivated]{@link module:workbox-window.Workbox#externalactivated}
378
- *
379
377
  * @memberof module:workbox-window
380
378
  */
381
379
 
380
+ function _empty() {}
381
+
382
382
  var Workbox =
383
383
  /*#__PURE__*/
384
384
  function (_WorkboxEventTarget) {
@@ -410,6 +410,7 @@
410
410
  _this._activeDeferred = new Deferred();
411
411
  _this._controllingDeferred = new Deferred();
412
412
  _this._registrationTime = 0;
413
+ _this._ownSWs = new Set();
413
414
  /**
414
415
  * @private
415
416
  */
@@ -452,6 +453,8 @@
452
453
  // SW is the one we registered, so we set it.
453
454
  _this._sw = installingSW;
454
455
 
456
+ _this._ownSWs.add(installingSW);
457
+
455
458
  _this._swDeferred.resolve(installingSW); // The `installing` state isn't something we have a dedicated
456
459
  // callback for, but we do log messages for it in development.
457
460
 
@@ -591,17 +594,32 @@
591
594
  */
592
595
 
593
596
 
594
- _this._onMessage = function (originalEvent) {
595
- var data = originalEvent.data;
596
-
597
- _this.dispatchEvent(new WorkboxEvent('message', {
598
- data: data,
599
- originalEvent: originalEvent
600
- }));
601
- };
597
+ _this._onMessage = _async(function (originalEvent) {
598
+ var data = originalEvent.data,
599
+ source = originalEvent.source; // Wait until there's an "own" service worker. This is used to buffer
600
+ // `message` events that may be received prior to calling `register()`.
602
601
 
602
+ return _await(_this.getSW(), function () {
603
+ if (_this._ownSWs.has(source)) {
604
+ _this.dispatchEvent(new WorkboxEvent('message', {
605
+ data: data,
606
+ sw: source,
607
+ originalEvent: originalEvent
608
+ }));
609
+ }
610
+ }); // If the service worker that sent the message is in the list of own
611
+ // service workers for this instance, dispatch a `message` event.
612
+ // NOTE: we check for all previously owned service workers rather than
613
+ // just the current one because some messages (e.g. cache updates) use
614
+ // a timeout when sent and may be delayed long enough for a service worker
615
+ // update to be found.
616
+ });
603
617
  _this._scriptURL = scriptURL;
604
- _this._registerOptions = registerOptions;
618
+ _this._registerOptions = registerOptions; // Add a message listener immediately since messages received during
619
+ // page load are buffered only until the DOMContentLoaded event:
620
+ // https://github.com/GoogleChrome/workbox/issues/2202
621
+
622
+ navigator.serviceWorker.addEventListener('message', _this._onMessage);
605
623
  return _this;
606
624
  }
607
625
  /**
@@ -634,7 +652,7 @@
634
652
  return _invoke(function () {
635
653
  if (!immediate && document.readyState !== 'complete') {
636
654
  return _awaitIgnored(new Promise(function (res) {
637
- return addEventListener('load', res);
655
+ return window.addEventListener('load', res);
638
656
  }));
639
657
  }
640
658
  }, function () {
@@ -657,14 +675,12 @@
657
675
 
658
676
  _this2._controllingDeferred.resolve(_this2._compatibleControllingSW);
659
677
 
660
- _this2._reportWindowReady(_this2._compatibleControllingSW);
661
-
662
678
  _this2._compatibleControllingSW.addEventListener('statechange', _this2._onStateChange, {
663
679
  once: true
664
680
  });
665
681
  } // If there's a waiting service worker with a matching URL before the
666
682
  // `updatefound` event fires, it likely means that this site is open
667
- // in another tab, or the user refreshed the page (and thus the prevoius
683
+ // in another tab, or the user refreshed the page (and thus the previous
668
684
  // page wasn't fully unloaded before this page started loading).
669
685
  // https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting
670
686
 
@@ -677,7 +693,7 @@
677
693
  _this2._sw = waitingSW; // Run this in the next microtask, so any code that adds an event
678
694
  // listener after awaiting `register()` will get this event.
679
695
 
680
- Promise.resolve().then(function () {
696
+ dontWaitFor(Promise.resolve().then(function () {
681
697
  _this2.dispatchEvent(new WorkboxEvent('waiting', {
682
698
  sw: waitingSW,
683
699
  wasWaitingBeforeRegister: true
@@ -686,12 +702,14 @@
686
702
  {
687
703
  logger.warn('A service worker was already waiting to activate ' + 'before this script was registered...');
688
704
  }
689
- });
705
+ }));
690
706
  } // If an "own" SW is already set, resolve the deferred.
691
707
 
692
708
 
693
709
  if (_this2._sw) {
694
710
  _this2._swDeferred.resolve(_this2._sw);
711
+
712
+ _this2._ownSWs.add(_this2._sw);
695
713
  }
696
714
 
697
715
  {
@@ -720,19 +738,29 @@
720
738
 
721
739
  navigator.serviceWorker.addEventListener('controllerchange', _this2._onControllerChange, {
722
740
  once: true
723
- }); // Add message listeners.
724
-
725
- if ('BroadcastChannel' in self) {
726
- _this2._broadcastChannel = new BroadcastChannel('workbox');
727
-
728
- _this2._broadcastChannel.addEventListener('message', _this2._onMessage);
729
- }
730
-
731
- navigator.serviceWorker.addEventListener('message', _this2._onMessage);
741
+ });
732
742
  return _this2._registration;
733
743
  });
734
744
  });
735
- });
745
+ })
746
+ /**
747
+ * Checks for updates of the registered service worker.
748
+ */
749
+ ;
750
+ _proto.update = _async(function () {
751
+ var _this3 = this;
752
+
753
+ if (!_this3._registration) {
754
+ {
755
+ logger.error('Cannot update a Workbox instance without ' + 'being registered. Register the Workbox instance first.');
756
+ }
757
+
758
+ return;
759
+ } // Try to update registration
760
+
761
+
762
+ return _awaitIgnored(_this3._registration.update());
763
+ })
736
764
  /**
737
765
  * Resolves to the service worker registered by this instance as soon as it
738
766
  * is active. If a service worker was already controlling at registration
@@ -742,6 +770,7 @@
742
770
  *
743
771
  * @return {Promise<ServiceWorker>}
744
772
  */
773
+ ;
745
774
 
746
775
  /**
747
776
  * Resolves with a reference to a service worker that matches the script URL
@@ -759,12 +788,12 @@
759
788
  * @return {Promise<ServiceWorker>}
760
789
  */
761
790
  _proto.getSW = _async(function () {
762
- var _this3 = this;
791
+ var _this4 = this;
763
792
 
764
793
  // If `this._sw` is set, resolve with that as we want `getSW()` to
765
794
  // return the correct (new) service worker if an update is found.
766
- return _this3._sw !== undefined ? _this3._sw : _this3._swDeferred.promise;
767
- });
795
+ return _this4._sw !== undefined ? _this4._sw : _this4._swDeferred.promise;
796
+ })
768
797
  /**
769
798
  * Sends the passed data object to the service worker registered by this
770
799
  * instance (via [`getSW()`]{@link module:workbox-window.Workbox#getSW}) and resolves
@@ -778,21 +807,22 @@
778
807
  * @param {Object} data An object to send to the service worker
779
808
  * @return {Promise<Object>}
780
809
  */
781
-
810
+ ;
782
811
  _proto.messageSW = _async(function (data) {
783
- var _this4 = this;
812
+ var _this5 = this;
784
813
 
785
- return _await(_this4.getSW(), function (sw) {
814
+ return _await(_this5.getSW(), function (sw) {
786
815
  return messageSW(sw, data);
787
816
  });
788
- });
817
+ })
789
818
  /**
790
819
  * Checks for a service worker already controlling the page and returns
791
- * it if its script URL matchs.
820
+ * it if its script URL matches.
792
821
  *
793
822
  * @private
794
823
  * @return {ServiceWorker|undefined}
795
824
  */
825
+ ;
796
826
 
797
827
  _proto._getControllingSWIfCompatible = function _getControllingSWIfCompatible() {
798
828
  var controller = navigator.serviceWorker.controller;
@@ -802,24 +832,24 @@
802
832
  } else {
803
833
  return undefined;
804
834
  }
805
- };
835
+ }
806
836
  /**
807
837
  * Registers a service worker for this instances script URL and register
808
838
  * options and tracks the time registration was complete.
809
839
  *
810
840
  * @private
811
841
  */
812
-
842
+ ;
813
843
 
814
844
  _proto._registerScript = _async(function () {
815
- var _this5 = this;
845
+ var _this6 = this;
816
846
 
817
847
  return _catch(function () {
818
- return _await(navigator.serviceWorker.register(_this5._scriptURL, _this5._registerOptions), function (reg) {
848
+ return _await(navigator.serviceWorker.register(_this6._scriptURL, _this6._registerOptions), function (reg) {
819
849
  // Keep track of when registration happened, so it can be used in the
820
850
  // `this._onUpdateFound` heuristic. Also use the presence of this
821
851
  // property as a way to see if `.register()` has been called.
822
- _this5._registrationTime = performance.now();
852
+ _this6._registrationTime = performance.now();
823
853
  return reg;
824
854
  });
825
855
  }, function (error) {
@@ -831,19 +861,6 @@
831
861
  throw error;
832
862
  });
833
863
  });
834
- /**
835
- * Sends a message to the passed service worker that the window is ready.
836
- *
837
- * @param {ServiceWorker} sw
838
- * @private
839
- */
840
-
841
- _proto._reportWindowReady = function _reportWindowReady(sw) {
842
- messageSW(sw, {
843
- type: 'WINDOW_READY',
844
- meta: 'workbox-window'
845
- });
846
- };
847
864
 
848
865
  _createClass(Workbox, [{
849
866
  key: "active",
@@ -871,7 +888,194 @@
871
888
  }]);
872
889
 
873
890
  return Workbox;
874
- }(WorkboxEventTarget); // The jsdoc comments below outline the events this instance may dispatch:
891
+ }(WorkboxEventTarget);
892
+
893
+ function _awaitIgnored(value, direct) {
894
+ if (!direct) {
895
+ return value && value.then ? value.then(_empty) : Promise.resolve();
896
+ }
897
+ } // The jsdoc comments below outline the events this instance may dispatch:
898
+ // -----------------------------------------------------------------------
899
+
900
+ /**
901
+ * The `message` event is dispatched any time a `postMessage` is received.
902
+ *
903
+ * @event module:workbox-window.Workbox#message
904
+ * @type {WorkboxEvent}
905
+ * @property {*} data The `data` property from the original `message` event.
906
+ * @property {Event} originalEvent The original [`message`]{@link https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent}
907
+ * event.
908
+ * @property {string} type `message`.
909
+ * @property {Workbox} target The `Workbox` instance.
910
+ */
911
+
912
+ /**
913
+ * The `installed` event is dispatched if the state of a
914
+ * [`Workbox`]{@link module:workbox-window.Workbox} instance's
915
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}
916
+ * changes to `installed`.
917
+ *
918
+ * Then can happen either the very first time a service worker is installed,
919
+ * or after an update to the current service worker is found. In the case
920
+ * of an update being found, the event's `isUpdate` property will be `true`.
921
+ *
922
+ * @event module:workbox-window.Workbox#installed
923
+ * @type {WorkboxEvent}
924
+ * @property {ServiceWorker} sw The service worker instance.
925
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
926
+ * event.
927
+ * @property {boolean|undefined} isUpdate True if a service worker was already
928
+ * controlling when this `Workbox` instance called `register()`.
929
+ * @property {string} type `installed`.
930
+ * @property {Workbox} target The `Workbox` instance.
931
+ */
932
+
933
+ /**
934
+ * The `waiting` event is dispatched if the state of a
935
+ * [`Workbox`]{@link module:workbox-window.Workbox} instance's
936
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}
937
+ * changes to `installed` and then doesn't immediately change to `activating`.
938
+ * It may also be dispatched if a service worker with the same
939
+ * [`scriptURL`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/scriptURL}
940
+ * was already waiting when the [`register()`]{@link module:workbox-window.Workbox#register}
941
+ * method was called.
942
+ *
943
+ * @event module:workbox-window.Workbox#waiting
944
+ * @type {WorkboxEvent}
945
+ * @property {ServiceWorker} sw The service worker instance.
946
+ * @property {Event|undefined} originalEvent The original
947
+ * [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
948
+ * event, or `undefined` in the case where the service worker was waiting
949
+ * to before `.register()` was called.
950
+ * @property {boolean|undefined} isUpdate True if a service worker was already
951
+ * controlling when this `Workbox` instance called `register()`.
952
+ * @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with
953
+ * a matching `scriptURL` was already waiting when this `Workbox`
954
+ * instance called `register()`.
955
+ * @property {string} type `waiting`.
956
+ * @property {Workbox} target The `Workbox` instance.
957
+ */
958
+
959
+ /**
960
+ * The `controlling` event is dispatched if a
961
+ * [`controllerchange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/oncontrollerchange}
962
+ * fires on the service worker [container]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer}
963
+ * and the [`scriptURL`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/scriptURL}
964
+ * of the new [controller]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/controller}
965
+ * matches the `scriptURL` of the `Workbox` instance's
966
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}.
967
+ *
968
+ * @event module:workbox-window.Workbox#controlling
969
+ * @type {WorkboxEvent}
970
+ * @property {ServiceWorker} sw The service worker instance.
971
+ * @property {Event} originalEvent The original [`controllerchange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/oncontrollerchange}
972
+ * event.
973
+ * @property {boolean|undefined} isUpdate True if a service worker was already
974
+ * controlling when this service worker was registered.
975
+ * @property {string} type `controlling`.
976
+ * @property {Workbox} target The `Workbox` instance.
977
+ */
978
+
979
+ /**
980
+ * The `activated` event is dispatched if the state of a
981
+ * [`Workbox`]{@link module:workbox-window.Workbox} instance's
982
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}
983
+ * changes to `activated`.
984
+ *
985
+ * @event module:workbox-window.Workbox#activated
986
+ * @type {WorkboxEvent}
987
+ * @property {ServiceWorker} sw The service worker instance.
988
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
989
+ * event.
990
+ * @property {boolean|undefined} isUpdate True if a service worker was already
991
+ * controlling when this `Workbox` instance called `register()`.
992
+ * @property {string} type `activated`.
993
+ * @property {Workbox} target The `Workbox` instance.
994
+ */
995
+
996
+ /**
997
+ * The `redundant` event is dispatched if the state of a
998
+ * [`Workbox`]{@link module:workbox-window.Workbox} instance's
999
+ * [registered service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-precaching#def-registered-sw}
1000
+ * changes to `redundant`.
1001
+ *
1002
+ * @event module:workbox-window.Workbox#redundant
1003
+ * @type {WorkboxEvent}
1004
+ * @property {ServiceWorker} sw The service worker instance.
1005
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
1006
+ * event.
1007
+ * @property {boolean|undefined} isUpdate True if a service worker was already
1008
+ * controlling when this `Workbox` instance called `register()`.
1009
+ * @property {string} type `redundant`.
1010
+ * @property {Workbox} target The `Workbox` instance.
1011
+ */
1012
+
1013
+ /**
1014
+ * The `externalinstalled` event is dispatched if the state of an
1015
+ * [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
1016
+ * changes to `installed`.
1017
+ *
1018
+ * @event module:workbox-window.Workbox#externalinstalled
1019
+ * @type {WorkboxEvent}
1020
+ * @property {ServiceWorker} sw The service worker instance.
1021
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
1022
+ * event.
1023
+ * @property {string} type `externalinstalled`.
1024
+ * @property {Workbox} target The `Workbox` instance.
1025
+ */
1026
+
1027
+ /**
1028
+ * The `externalwaiting` event is dispatched if the state of an
1029
+ * [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
1030
+ * changes to `waiting`.
1031
+ *
1032
+ * @event module:workbox-window.Workbox#externalwaiting
1033
+ * @type {WorkboxEvent}
1034
+ * @property {ServiceWorker} sw The service worker instance.
1035
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
1036
+ * event.
1037
+ * @property {string} type `externalwaiting`.
1038
+ * @property {Workbox} target The `Workbox` instance.
1039
+ */
1040
+
1041
+ /**
1042
+ * The `externalactivated` event is dispatched if the state of an
1043
+ * [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
1044
+ * changes to `activated`.
1045
+ *
1046
+ * @event module:workbox-window.Workbox#externalactivated
1047
+ * @type {WorkboxEvent}
1048
+ * @property {ServiceWorker} sw The service worker instance.
1049
+ * @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
1050
+ * event.
1051
+ * @property {string} type `externalactivated`.
1052
+ * @property {Workbox} target The `Workbox` instance.
1053
+ */
1054
+
1055
+
1056
+ function _invoke(body, then) {
1057
+ var result = body();
1058
+
1059
+ if (result && result.then) {
1060
+ return result.then(then);
1061
+ }
1062
+
1063
+ return then(result);
1064
+ }
1065
+
1066
+ function _catch(body, recover) {
1067
+ try {
1068
+ var result = body();
1069
+ } catch (e) {
1070
+ return recover(e);
1071
+ }
1072
+
1073
+ if (result && result.then) {
1074
+ return result.then(void 0, recover);
1075
+ }
1076
+
1077
+ return result;
1078
+ }
875
1079
 
876
1080
  exports.Workbox = Workbox;
877
1081
  exports.messageSW = messageSW;