workbox-window
Advanced tools
Comparing version 7.0.0 to 7.1.0
@@ -5,4 +5,5 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.workbox = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
// @ts-ignore | ||
try { | ||
@@ -35,11 +36,8 @@ self['workbox:window:7.0.0'] && _(); | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
function messageSW(sw, data) { | ||
return new Promise(function (resolve) { | ||
var messageChannel = new MessageChannel(); | ||
messageChannel.port1.onmessage = function (event) { | ||
resolve(event.data); | ||
}; | ||
sw.postMessage(data, [messageChannel.port2]); | ||
@@ -49,2 +47,16 @@ }); | ||
function _toPrimitive(t, r) { | ||
if ("object" != typeof t || !t) return t; | ||
var e = t[Symbol.toPrimitive]; | ||
if (void 0 !== e) { | ||
var i = e.call(t, r || "default"); | ||
if ("object" != typeof i) return i; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return ("string" === r ? String : Number)(t); | ||
} | ||
function _toPropertyKey(t) { | ||
var i = _toPrimitive(t, "string"); | ||
return "symbol" == typeof i ? i : i + ""; | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -56,18 +68,25 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -81,36 +100,27 @@ if (!o) return; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (it) return (it = it.call(o)).next.bind(it); | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
it = o[Symbol.iterator](); | ||
return it.next.bind(it); | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
// @ts-ignore | ||
try { | ||
@@ -135,3 +145,2 @@ self['workbox:core:7.0.0'] && _(); | ||
*/ | ||
var Deferred = | ||
@@ -143,3 +152,2 @@ /** | ||
var _this = this; | ||
this.promise = new Promise(function (resolve, reject) { | ||
@@ -162,3 +170,2 @@ _this.resolve = resolve; | ||
**/ | ||
function dontWaitFor(promise) { | ||
@@ -181,3 +188,2 @@ // Effective no-op. | ||
} | ||
var inGroup = false; | ||
@@ -191,12 +197,8 @@ var methodToColorMap = { | ||
groupEnd: null // No colored prefix on groupEnd | ||
}; | ||
var print = function print(method, args) { | ||
var _console2; | ||
if (self.__WB_DISABLE_DEV_LOGS) { | ||
return; | ||
} | ||
if (method === 'groupCollapsed') { | ||
@@ -207,32 +209,23 @@ // Safari doesn't print all console.groupCollapsed() arguments: | ||
var _console; | ||
(_console = console)[method].apply(_console, args); | ||
return; | ||
} | ||
} | ||
var styles = ["background: " + methodToColorMap[method], "border-radius: 0.5em", "color: white", "font-weight: bold", "padding: 2px 0.5em"]; // When in a group, the workbox prefix is not displayed. | ||
var styles = ["background: " + methodToColorMap[method], "border-radius: 0.5em", "color: white", "font-weight: bold", "padding: 2px 0.5em"]; | ||
// When in a group, the workbox prefix is not displayed. | ||
var logPrefix = inGroup ? [] : ['%cworkbox', styles.join(';')]; | ||
(_console2 = console)[method].apply(_console2, logPrefix.concat(args)); | ||
if (method === 'groupCollapsed') { | ||
inGroup = true; | ||
} | ||
if (method === 'groupEnd') { | ||
inGroup = false; | ||
} | ||
}; // eslint-disable-next-line @typescript-eslint/ban-types | ||
}; | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
var api = {}; | ||
var loggerMethods = Object.keys(methodToColorMap); | ||
var _loop = function _loop() { | ||
var key = _loggerMethods[_i]; | ||
var method = key; | ||
api[method] = function () { | ||
@@ -242,11 +235,8 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
} | ||
print(method, args); | ||
}; | ||
}; | ||
for (var _i = 0, _loggerMethods = loggerMethods; _i < _loggerMethods.length; _i++) { | ||
_loop(); | ||
} | ||
return api; | ||
@@ -262,3 +252,2 @@ }(); | ||
*/ | ||
/** | ||
@@ -279,9 +268,5 @@ * A minimal `EventTarget` shim. | ||
*/ | ||
var _proto = WorkboxEventTarget.prototype; | ||
_proto.addEventListener = function addEventListener(type, listener) { | ||
var foo = this._getEventListenersByType(type); | ||
foo.add(listener); | ||
@@ -293,5 +278,3 @@ } | ||
* @private | ||
*/ | ||
; | ||
*/; | ||
_proto.removeEventListener = function removeEventListener(type, listener) { | ||
@@ -303,10 +286,6 @@ this._getEventListenersByType(type).delete(listener); | ||
* @private | ||
*/ | ||
; | ||
*/; | ||
_proto.dispatchEvent = function dispatchEvent(event) { | ||
event.target = this; | ||
var listeners = this._getEventListenersByType(event.type); | ||
for (var _iterator = _createForOfIteratorHelperLoose(listeners), _step; !(_step = _iterator()).done;) { | ||
@@ -324,5 +303,3 @@ var listener = _step.value; | ||
* @private | ||
*/ | ||
; | ||
*/; | ||
_proto._getEventListenersByType = function _getEventListenersByType(type) { | ||
@@ -332,6 +309,4 @@ if (!this._eventListenerRegistry.has(type)) { | ||
} | ||
return this._eventListenerRegistry.get(type); | ||
}; | ||
return WorkboxEventTarget; | ||
@@ -356,6 +331,5 @@ }(); | ||
*/ | ||
function urlsMatch(url1, url2) { | ||
var _location = location, | ||
href = _location.href; | ||
href = _location.href; | ||
return new URL(url1, href).href === new URL(url2, href).href; | ||
@@ -377,3 +351,2 @@ } | ||
*/ | ||
var WorkboxEvent = function WorkboxEvent(type, props) { | ||
@@ -384,2 +357,3 @@ this.type = type; | ||
// The time a SW must be in the waiting phase before we can conclude | ||
// `skipWaiting()` wasn't called. This 200 amount wasn't scientifically | ||
@@ -392,11 +366,9 @@ // chosen, but it seems to avoid false positives in my testing. | ||
} | ||
if (!value || !value.then) { | ||
value = Promise.resolve(value); | ||
} | ||
return then ? value.then(then) : value; | ||
} | ||
var WAITING_TIMEOUT_DURATION = 200; // The amount of time after a registration that we can reasonably conclude | ||
var WAITING_TIMEOUT_DURATION = 200; | ||
// The amount of time after a registration that we can reasonably conclude | ||
// that the registration didn't trigger an update. | ||
@@ -409,3 +381,2 @@ | ||
} | ||
try { | ||
@@ -418,8 +389,7 @@ return Promise.resolve(f.apply(this, args)); | ||
} | ||
var REGISTRATION_TIMEOUT_DURATION = 60000; // The de facto standard message that a service worker should be listening for | ||
var REGISTRATION_TIMEOUT_DURATION = 60000; | ||
// The de facto standard message that a service worker should be listening for | ||
// to trigger a call to skipWaiting(). | ||
function _empty() {} | ||
var SKIP_WAITING_MESSAGE = { | ||
@@ -446,6 +416,3 @@ type: 'SKIP_WAITING' | ||
} | ||
var Workbox = /*#__PURE__*/function (_WorkboxEventTarget) { | ||
_inheritsLoose(Workbox, _WorkboxEventTarget); | ||
/** | ||
@@ -465,11 +432,9 @@ * Creates a new Workbox instance with a script URL and service worker | ||
var _this; | ||
if (registerOptions === void 0) { | ||
registerOptions = {}; | ||
} | ||
_this = _WorkboxEventTarget.call(this) || this; | ||
_this._registerOptions = {}; | ||
_this._updateFoundCount = 0; // Deferreds we can resolve later. | ||
_this._updateFoundCount = 0; | ||
// Deferreds we can resolve later. | ||
_this._swDeferred = new Deferred(); | ||
@@ -483,7 +448,7 @@ _this._activeDeferred = new Deferred(); | ||
*/ | ||
_this._onUpdateFound = function () { | ||
// `this._registration` will never be `undefined` after an update is found. | ||
var registration = _this._registration; | ||
var installingSW = registration.installing; // If the script URL passed to `navigator.serviceWorker.register()` is | ||
var installingSW = registration.installing; | ||
// If the script URL passed to `navigator.serviceWorker.register()` is | ||
// different from the current controlling SW's script URL, we know any | ||
@@ -500,17 +465,19 @@ // successful registration calls will trigger an `updatefound` event. | ||
// To minimize the possibility of a false positive, we use the logic here: | ||
var updateLikelyTriggeredExternally = // Since we enforce only calling `register()` once, and since we don't | ||
var updateLikelyTriggeredExternally = | ||
// Since we enforce only calling `register()` once, and since we don't | ||
// add the `updatefound` event listener until the `register()` call, if | ||
// `_updateFoundCount` is > 0 then it means this method has already | ||
// been called, thus this SW must be external | ||
_this._updateFoundCount > 0 || // If the script URL of the installing SW is different from this | ||
_this._updateFoundCount > 0 || | ||
// If the script URL of the installing SW is different from this | ||
// instance's script URL, we know it's definitely not from our | ||
// registration. | ||
!urlsMatch(installingSW.scriptURL, _this._scriptURL.toString()) || // If all of the above are false, then we use a time-based heuristic: | ||
!urlsMatch(installingSW.scriptURL, _this._scriptURL.toString()) || | ||
// If all of the above are false, then we use a time-based heuristic: | ||
// Any `updatefound` event that occurs long after our registration is | ||
// assumed to be external. | ||
performance.now() > _this._registrationTime + REGISTRATION_TIMEOUT_DURATION ? // If any of the above are not true, we assume the update was | ||
performance.now() > _this._registrationTime + REGISTRATION_TIMEOUT_DURATION ? | ||
// If any of the above are not true, we assume the update was | ||
// triggered by this instance. | ||
true : false; | ||
if (updateLikelyTriggeredExternally) { | ||
@@ -523,9 +490,6 @@ _this._externalSW = installingSW; | ||
_this._sw = installingSW; | ||
_this._ownSWs.add(installingSW); | ||
_this._swDeferred.resolve(installingSW); // The `installing` state isn't something we have a dedicated | ||
_this._swDeferred.resolve(installingSW); | ||
// The `installing` state isn't something we have a dedicated | ||
// callback for, but we do log messages for it in development. | ||
{ | ||
@@ -538,9 +502,8 @@ if (navigator.serviceWorker.controller) { | ||
} | ||
} // Increment the `updatefound` count, so future invocations of this | ||
} | ||
// Increment the `updatefound` count, so future invocations of this | ||
// method can be sure they were triggered externally. | ||
++_this._updateFoundCount; // Add a `statechange` listener regardless of whether this update was | ||
++_this._updateFoundCount; | ||
// Add a `statechange` listener regardless of whether this update was | ||
// triggered externally, since we have callbacks for both. | ||
installingSW.addEventListener('statechange', _this._onStateChange); | ||
@@ -552,4 +515,2 @@ }; | ||
*/ | ||
_this._onStateChange = function (originalEvent) { | ||
@@ -566,9 +527,6 @@ // `this._registration` will never be `undefined` after an update is found. | ||
}; | ||
if (!isExternal && _this._isUpdate) { | ||
eventProps.isUpdate = true; | ||
} | ||
_this.dispatchEvent(new WorkboxEvent(state, eventProps)); | ||
if (state === 'installed') { | ||
@@ -587,3 +545,2 @@ // This timeout is used to ignore cases where the service worker calls | ||
_this.dispatchEvent(new WorkboxEvent('waiting', eventProps)); | ||
{ | ||
@@ -600,3 +557,2 @@ if (isExternal) { | ||
clearTimeout(_this._waitingTimeout); | ||
if (!isExternal) { | ||
@@ -606,3 +562,2 @@ _this._activeDeferred.resolve(sw); | ||
} | ||
{ | ||
@@ -616,5 +571,3 @@ switch (state) { | ||
} | ||
break; | ||
case 'activated': | ||
@@ -625,3 +578,2 @@ if (isExternal) { | ||
logger.log('Registered service worker activated.'); | ||
if (sw !== navigator.serviceWorker.controller) { | ||
@@ -631,5 +583,3 @@ logger.warn('The registered service worker is active but ' + 'not yet controlling the page. Reload or run ' + '`clients.claim()` in the service worker.'); | ||
} | ||
break; | ||
case 'redundant': | ||
@@ -641,3 +591,2 @@ if (sw === _this._compatibleControllingSW) { | ||
} | ||
break; | ||
@@ -651,11 +600,9 @@ } | ||
*/ | ||
_this._onControllerChange = function (originalEvent) { | ||
var sw = _this._sw; | ||
var isExternal = sw !== navigator.serviceWorker.controller; // Unconditionally dispatch the controlling event, with isExternal set | ||
var isExternal = sw !== navigator.serviceWorker.controller; | ||
// Unconditionally dispatch the controlling event, with isExternal set | ||
// to distinguish between controller changes due to the initial registration | ||
// vs. an update-check or other tab's registration. | ||
// See https://github.com/GoogleChrome/workbox/issues/2786 | ||
_this.dispatchEvent(new WorkboxEvent('controlling', { | ||
@@ -667,3 +614,2 @@ isExternal: isExternal, | ||
})); | ||
if (!isExternal) { | ||
@@ -673,3 +619,2 @@ { | ||
} | ||
_this._controllingDeferred.resolve(sw); | ||
@@ -682,4 +627,2 @@ } | ||
*/ | ||
_this._onMessage = _async(function (originalEvent) { | ||
@@ -689,6 +632,6 @@ // Can't change type 'any' of data. | ||
var data = originalEvent.data, | ||
ports = originalEvent.ports, | ||
source = originalEvent.source; // Wait until there's an "own" service worker. This is used to buffer | ||
ports = originalEvent.ports, | ||
source = originalEvent.source; | ||
// Wait until there's an "own" service worker. This is used to buffer | ||
// `message` events that may be received prior to calling `register()`. | ||
return _await(_this.getSW(), function () { | ||
@@ -713,6 +656,6 @@ if (_this._ownSWs.has(source)) { | ||
_this._scriptURL = scriptURL; | ||
_this._registerOptions = registerOptions; // Add a message listener immediately since messages received during | ||
_this._registerOptions = registerOptions; | ||
// Add a message listener immediately since messages received during | ||
// page load are buffered only until the DOMContentLoaded event: | ||
// https://github.com/GoogleChrome/workbox/issues/2202 | ||
navigator.serviceWorker.addEventListener('message', _this._onMessage); | ||
@@ -731,22 +674,17 @@ return _this; | ||
*/ | ||
_inheritsLoose(Workbox, _WorkboxEventTarget); | ||
var _proto = Workbox.prototype; | ||
_proto.register = function register(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_ref$immediate = _ref.immediate, | ||
immediate = _ref$immediate === void 0 ? false : _ref$immediate; | ||
_ref$immediate = _ref.immediate, | ||
immediate = _ref$immediate === void 0 ? false : _ref$immediate; | ||
try { | ||
var _this3 = this; | ||
var _this2 = this; | ||
if ("dev" !== 'production') { | ||
if (_this3._registrationTime) { | ||
if (_this2._registrationTime) { | ||
logger.error('Cannot re-register a Workbox instance after it has ' + 'been registered. Create a new instance instead.'); | ||
return; | ||
return _await(); | ||
} | ||
} | ||
return _invoke(function () { | ||
return _await(_invoke(function () { | ||
if (!immediate && document.readyState !== 'complete') { | ||
@@ -760,23 +698,20 @@ return _awaitIgnored(new Promise(function (res) { | ||
// at registration time. | ||
_this3._isUpdate = Boolean(navigator.serviceWorker.controller); // Before registering, attempt to determine if a SW is already controlling | ||
_this2._isUpdate = Boolean(navigator.serviceWorker.controller); | ||
// Before registering, attempt to determine if a SW is already controlling | ||
// the page, and if that SW script (and version, if specified) matches this | ||
// instance's script. | ||
_this3._compatibleControllingSW = _this3._getControllingSWIfCompatible(); | ||
return _await(_this3._registerScript(), function (_this2$_registerScrip) { | ||
_this3._registration = _this2$_registerScrip; | ||
_this2._compatibleControllingSW = _this2._getControllingSWIfCompatible(); | ||
return _await(_this2._registerScript(), function (_this2$_registerScrip) { | ||
_this2._registration = _this2$_registerScrip; | ||
// If we have a compatible controller, store the controller as the "own" | ||
// SW, resolve active/controlling deferreds and add necessary listeners. | ||
if (_this3._compatibleControllingSW) { | ||
_this3._sw = _this3._compatibleControllingSW; | ||
_this3._activeDeferred.resolve(_this3._compatibleControllingSW); | ||
_this3._controllingDeferred.resolve(_this3._compatibleControllingSW); | ||
_this3._compatibleControllingSW.addEventListener('statechange', _this3._onStateChange, { | ||
if (_this2._compatibleControllingSW) { | ||
_this2._sw = _this2._compatibleControllingSW; | ||
_this2._activeDeferred.resolve(_this2._compatibleControllingSW); | ||
_this2._controllingDeferred.resolve(_this2._compatibleControllingSW); | ||
_this2._compatibleControllingSW.addEventListener('statechange', _this2._onStateChange, { | ||
once: true | ||
}); | ||
} // If there's a waiting service worker with a matching URL before the | ||
} | ||
// If there's a waiting service worker with a matching URL before the | ||
// `updatefound` event fires, it likely means that this site is open | ||
@@ -786,18 +721,14 @@ // in another tab, or the user refreshed the page (and thus the previous | ||
// https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#waiting | ||
var waitingSW = _this3._registration.waiting; | ||
if (waitingSW && urlsMatch(waitingSW.scriptURL, _this3._scriptURL.toString())) { | ||
var waitingSW = _this2._registration.waiting; | ||
if (waitingSW && urlsMatch(waitingSW.scriptURL, _this2._scriptURL.toString())) { | ||
// Store the waiting SW as the "own" Sw, even if it means overwriting | ||
// a compatible controller. | ||
_this3._sw = waitingSW; // Run this in the next microtask, so any code that adds an event | ||
_this2._sw = waitingSW; | ||
// Run this in the next microtask, so any code that adds an event | ||
// listener after awaiting `register()` will get this event. | ||
dontWaitFor(Promise.resolve().then(function () { | ||
_this3.dispatchEvent(new WorkboxEvent('waiting', { | ||
_this2.dispatchEvent(new WorkboxEvent('waiting', { | ||
sw: waitingSW, | ||
wasWaitingBeforeRegister: true | ||
})); | ||
if ("dev" !== 'production') { | ||
@@ -807,16 +738,12 @@ logger.warn('A service worker was already waiting to activate ' + 'before this script was registered...'); | ||
})); | ||
} // If an "own" SW is already set, resolve the deferred. | ||
if (_this3._sw) { | ||
_this3._swDeferred.resolve(_this3._sw); | ||
_this3._ownSWs.add(_this3._sw); | ||
} | ||
// If an "own" SW is already set, resolve the deferred. | ||
if (_this2._sw) { | ||
_this2._swDeferred.resolve(_this2._sw); | ||
_this2._ownSWs.add(_this2._sw); | ||
} | ||
if ("dev" !== 'production') { | ||
logger.log('Successfully registered service worker.', _this3._scriptURL.toString()); | ||
logger.log('Successfully registered service worker.', _this2._scriptURL.toString()); | ||
if (navigator.serviceWorker.controller) { | ||
if (_this3._compatibleControllingSW) { | ||
if (_this2._compatibleControllingSW) { | ||
logger.debug('A service worker with the same script URL ' + 'is already controlling this page.'); | ||
@@ -827,9 +754,7 @@ } else { | ||
} | ||
var currentPageIsOutOfScope = function currentPageIsOutOfScope() { | ||
var scopeURL = new URL(_this3._registerOptions.scope || _this3._scriptURL.toString(), document.baseURI); | ||
var scopeURL = new URL(_this2._registerOptions.scope || _this2._scriptURL.toString(), document.baseURI); | ||
var scopeURLBasePath = new URL('./', scopeURL.href).pathname; | ||
return !location.pathname.startsWith(scopeURLBasePath); | ||
}; | ||
if (currentPageIsOutOfScope()) { | ||
@@ -839,9 +764,7 @@ logger.warn('The current page is not in scope for the registered ' + 'service worker. Was this a mistake?'); | ||
} | ||
_this3._registration.addEventListener('updatefound', _this3._onUpdateFound); | ||
navigator.serviceWorker.addEventListener('controllerchange', _this3._onControllerChange); | ||
return _this3._registration; | ||
_this2._registration.addEventListener('updatefound', _this2._onUpdateFound); | ||
navigator.serviceWorker.addEventListener('controllerchange', _this2._onControllerChange); | ||
return _this2._registration; | ||
}); | ||
}); | ||
})); | ||
} catch (e) { | ||
@@ -855,17 +778,13 @@ return Promise.reject(e); | ||
; | ||
_proto.update = function update() { | ||
try { | ||
var _this5 = this; | ||
if (!_this5._registration) { | ||
var _this3 = this; | ||
if (!_this3._registration) { | ||
if ("dev" !== 'production') { | ||
logger.error('Cannot update a Workbox instance without ' + 'being registered. Register the Workbox instance first.'); | ||
} | ||
return; | ||
} // Try to update registration | ||
return _awaitIgnored(_this5._registration.update()); | ||
return _await(); | ||
} | ||
// Try to update registration | ||
return _await(_awaitIgnored(_this3._registration.update())); | ||
} catch (e) { | ||
@@ -885,3 +804,2 @@ return Promise.reject(e); | ||
; | ||
/** | ||
@@ -923,8 +841,6 @@ * Resolves with a reference to a service worker that matches the script URL | ||
; | ||
_proto.messageSW = function messageSW$1(data) { | ||
try { | ||
var _this7 = this; | ||
return _await(_this7.getSW(), function (sw) { | ||
var _this4 = this; | ||
return _await(_this4.getSW(), function (sw) { | ||
return messageSW(sw, data); | ||
@@ -944,3 +860,2 @@ }); | ||
; | ||
_proto.messageSkipWaiting = function messageSkipWaiting() { | ||
@@ -957,8 +872,5 @@ if (this._registration && this._registration.waiting) { | ||
* @return {ServiceWorker|undefined} | ||
*/ | ||
; | ||
*/; | ||
_proto._getControllingSWIfCompatible = function _getControllingSWIfCompatible() { | ||
var controller = navigator.serviceWorker.controller; | ||
if (controller && urlsMatch(controller.scriptURL, this._scriptURL.toString())) { | ||
@@ -975,18 +887,15 @@ return controller; | ||
* @private | ||
*/ | ||
; | ||
*/; | ||
_proto._registerScript = function _registerScript() { | ||
try { | ||
var _this9 = this; | ||
return _catch(function () { | ||
var _this5 = this; | ||
return _await(_catch(function () { | ||
// this._scriptURL may be a TrustedScriptURL, but there's no support for | ||
// passing that to register() in lib.dom right now. | ||
// https://github.com/GoogleChrome/workbox/issues/2855 | ||
return _await(navigator.serviceWorker.register(_this9._scriptURL, _this9._registerOptions), function (reg) { | ||
return _await(navigator.serviceWorker.register(_this5._scriptURL, _this5._registerOptions), function (reg) { | ||
// Keep track of when registration happened, so it can be used in the | ||
// `this._onUpdateFound` heuristic. Also use the presence of this | ||
// property as a way to see if `.register()` has been called. | ||
_this9._registrationTime = performance.now(); | ||
_this5._registrationTime = performance.now(); | ||
return reg; | ||
@@ -997,7 +906,6 @@ }); | ||
logger.error(error); | ||
} // Re-throw the error. | ||
} | ||
// Re-throw the error. | ||
throw error; | ||
}); | ||
})); | ||
} catch (e) { | ||
@@ -1007,4 +915,3 @@ return Promise.reject(e); | ||
}; | ||
_createClass(Workbox, [{ | ||
return _createClass(Workbox, [{ | ||
key: "active", | ||
@@ -1026,3 +933,2 @@ get: function get() { | ||
*/ | ||
}, { | ||
@@ -1034,17 +940,11 @@ key: "controlling", | ||
}]); | ||
return Workbox; | ||
}(WorkboxEventTarget); | ||
function _invoke(body, then) { | ||
var result = body(); | ||
if (result && result.then) { | ||
return result.then(then); | ||
} | ||
return then(result); | ||
} // The jsdoc comments below outline the events this instance may dispatch: | ||
// ----------------------------------------------------------------------- | ||
/** | ||
@@ -1062,3 +962,2 @@ * The `message` event is dispatched any time a `postMessage` is received. | ||
*/ | ||
/** | ||
@@ -1086,3 +985,2 @@ * The `installed` event is dispatched if the state of a | ||
*/ | ||
/** | ||
@@ -1115,3 +1013,2 @@ * The `waiting` event is dispatched if the state of a | ||
*/ | ||
/** | ||
@@ -1138,3 +1035,2 @@ * The `controlling` event is dispatched if a | ||
*/ | ||
/** | ||
@@ -1158,3 +1054,2 @@ * The `activated` event is dispatched if the state of a | ||
*/ | ||
/** | ||
@@ -1176,4 +1071,2 @@ * The `redundant` event is dispatched if the state of a | ||
*/ | ||
function _catch(body, recover) { | ||
@@ -1185,7 +1078,5 @@ try { | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
@@ -1200,3 +1091,3 @@ } | ||
}))); | ||
})); | ||
//# sourceMappingURL=workbox-window.dev.umd.js.map |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).workbox={})}(this,(function(n){"use strict";try{self["workbox:window:7.0.0"]&&_()}catch(n){}function t(n,t){return new Promise((function(r){var e=new MessageChannel;e.port1.onmessage=function(n){r(n.data)},n.postMessage(t,[e.port2])}))}function r(n,t){for(var r=0;r<t.length;r++){var e=t[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,e.key,e)}}function e(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=new Array(t);r<t;r++)e[r]=n[r];return e}function i(n,t){var r;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(r=function(n,t){if(n){if("string"==typeof n)return e(n,t);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(n,t):void 0}}(n))||t&&n&&"number"==typeof n.length){r&&(n=r);var i=0;return function(){return i>=n.length?{done:!0}:{done:!1,value:n[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=n[Symbol.iterator]()).next.bind(r)}try{self["workbox:core:7.0.0"]&&_()}catch(n){}var o=function(){var n=this;this.promise=new Promise((function(t,r){n.resolve=t,n.reject=r}))};function u(n,t){var r=location.href;return new URL(n,r).href===new URL(t,r).href}var a=function(n,t){this.type=n,Object.assign(this,t)};function c(n,t,r){return r?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function f(){}var s={type:"SKIP_WAITING"};function v(n,t){if(!t)return n&&n.then?n.then(f):Promise.resolve()}var h=function(n){var e,i;function f(t,r){var e,i;return void 0===r&&(r={}),(e=n.call(this)||this).nn={},e.tn=0,e.rn=new o,e.en=new o,e.on=new o,e.un=0,e.an=new Set,e.cn=function(){var n=e.fn,t=n.installing;e.tn>0||!u(t.scriptURL,e.sn.toString())||performance.now()>e.un+6e4?(e.vn=t,n.removeEventListener("updatefound",e.cn)):(e.hn=t,e.an.add(t),e.rn.resolve(t)),++e.tn,t.addEventListener("statechange",e.ln)},e.ln=function(n){var t=e.fn,r=n.target,i=r.state,o=r===e.vn,u={sw:r,isExternal:o,originalEvent:n};!o&&e.dn&&(u.isUpdate=!0),e.dispatchEvent(new a(i,u)),"installed"===i?e.mn=self.setTimeout((function(){"installed"===i&&t.waiting===r&&e.dispatchEvent(new a("waiting",u))}),200):"activating"===i&&(clearTimeout(e.mn),o||e.en.resolve(r))},e.wn=function(n){var t=e.hn,r=t!==navigator.serviceWorker.controller;e.dispatchEvent(new a("controlling",{isExternal:r,originalEvent:n,sw:t,isUpdate:e.dn})),r||e.on.resolve(t)},e.gn=(i=function(n){var t=n.data,r=n.ports,i=n.source;return c(e.getSW(),(function(){e.an.has(i)&&e.dispatchEvent(new a("message",{data:t,originalEvent:n,ports:r,sw:i}))}))},function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{return Promise.resolve(i.apply(this,n))}catch(n){return Promise.reject(n)}}),e.sn=t,e.nn=r,navigator.serviceWorker.addEventListener("message",e.gn),e}i=n,(e=f).prototype=Object.create(i.prototype),e.prototype.constructor=e,e.__proto__=i;var h,l,d,m=f.prototype;return m.register=function(n){var t=(void 0===n?{}:n).immediate,r=void 0!==t&&t;try{var e=this;return function(n,t){var r=n();if(r&&r.then)return r.then(t);return t(r)}((function(){if(!r&&"complete"!==document.readyState)return v(new Promise((function(n){return window.addEventListener("load",n)})))}),(function(){return e.dn=Boolean(navigator.serviceWorker.controller),e.yn=e.pn(),c(e.bn(),(function(n){e.fn=n,e.yn&&(e.hn=e.yn,e.en.resolve(e.yn),e.on.resolve(e.yn),e.yn.addEventListener("statechange",e.ln,{once:!0}));var t=e.fn.waiting;return t&&u(t.scriptURL,e.sn.toString())&&(e.hn=t,Promise.resolve().then((function(){e.dispatchEvent(new a("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})).then((function(){}))),e.hn&&(e.rn.resolve(e.hn),e.an.add(e.hn)),e.fn.addEventListener("updatefound",e.cn),navigator.serviceWorker.addEventListener("controllerchange",e.wn),e.fn}))}))}catch(n){return Promise.reject(n)}},m.update=function(){try{return this.fn?v(this.fn.update()):void 0}catch(n){return Promise.reject(n)}},m.getSW=function(){return void 0!==this.hn?Promise.resolve(this.hn):this.rn.promise},m.messageSW=function(n){try{return c(this.getSW(),(function(r){return t(r,n)}))}catch(n){return Promise.reject(n)}},m.messageSkipWaiting=function(){this.fn&&this.fn.waiting&&t(this.fn.waiting,s)},m.pn=function(){var n=navigator.serviceWorker.controller;return n&&u(n.scriptURL,this.sn.toString())?n:void 0},m.bn=function(){try{var n=this;return function(n,t){try{var r=n()}catch(n){return t(n)}if(r&&r.then)return r.then(void 0,t);return r}((function(){return c(navigator.serviceWorker.register(n.sn,n.nn),(function(t){return n.un=performance.now(),t}))}),(function(n){throw n}))}catch(n){return Promise.reject(n)}},h=f,(l=[{key:"active",get:function(){return this.en.promise}},{key:"controlling",get:function(){return this.on.promise}}])&&r(h.prototype,l),d&&r(h,d),f}(function(){function n(){this.Pn=new Map}var t=n.prototype;return t.addEventListener=function(n,t){this.jn(n).add(t)},t.removeEventListener=function(n,t){this.jn(n).delete(t)},t.dispatchEvent=function(n){n.target=this;for(var t,r=i(this.jn(n.type));!(t=r()).done;){(0,t.value)(n)}},t.jn=function(n){return this.Pn.has(n)||this.Pn.set(n,new Set),this.Pn.get(n)},n}());n.Workbox=h,n.WorkboxEvent=a,n.messageSW=t,Object.defineProperty(n,"__esModule",{value:!0})})); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).workbox={})}(this,(function(t){"use strict";try{self["workbox:window:7.0.0"]&&_()}catch(t){}function n(t,n){return new Promise((function(r){var e=new MessageChannel;e.port1.onmessage=function(t){r(t.data)},t.postMessage(n,[e.port2])}))}function r(t){var n=function(t,n){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.call(t,n||"default");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:n+""}function e(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,r(i.key),i)}}function i(t,n){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},i(t,n)}function o(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=new Array(n);r<n;r++)e[r]=t[r];return e}function u(t,n){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,n){if(t){if("string"==typeof t)return o(t,n);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){r&&(t=r);var e=0;return function(){return e>=t.length?{done:!0}:{done:!1,value:t[e++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}try{self["workbox:core:7.0.0"]&&_()}catch(t){}var a=function(){var t=this;this.promise=new Promise((function(n,r){t.resolve=n,t.reject=r}))};function c(t,n){var r=location.href;return new URL(t,r).href===new URL(n,r).href}var f=function(t,n){this.type=t,Object.assign(this,n)};function s(t,n,r){return r?n?n(t):t:(t&&t.then||(t=Promise.resolve(t)),n?t.then(n):t)}function v(){}var h={type:"SKIP_WAITING"};function l(t,n){if(!n)return t&&t.then?t.then(v):Promise.resolve()}var d=function(t){function r(n,r){var e,i;return void 0===r&&(r={}),(e=t.call(this)||this).At={},e.It=0,e.Tt=new a,e.Mt=new a,e.Bt=new a,e.Lt=0,e.Nt=new Set,e.Gt=function(){var t=e.Kt,n=t.installing;e.It>0||!c(n.scriptURL,e.zt.toString())||performance.now()>e.Lt+6e4?(e.Dt=n,t.removeEventListener("updatefound",e.Gt)):(e.Ft=n,e.Nt.add(n),e.Tt.resolve(n)),++e.It,n.addEventListener("statechange",e.Ht)},e.Ht=function(t){var n=e.Kt,r=t.target,i=r.state,o=r===e.Dt,u={sw:r,isExternal:o,originalEvent:t};!o&&e.Jt&&(u.isUpdate=!0),e.dispatchEvent(new f(i,u)),"installed"===i?e.Qt=self.setTimeout((function(){"installed"===i&&n.waiting===r&&e.dispatchEvent(new f("waiting",u))}),200):"activating"===i&&(clearTimeout(e.Qt),o||e.Mt.resolve(r))},e.Vt=function(t){var n=e.Ft,r=n!==navigator.serviceWorker.controller;e.dispatchEvent(new f("controlling",{isExternal:r,originalEvent:t,sw:n,isUpdate:e.Jt})),r||e.Bt.resolve(n)},e.Xt=(i=function(t){var n=t.data,r=t.ports,i=t.source;return s(e.getSW(),(function(){e.Nt.has(i)&&e.dispatchEvent(new f("message",{data:n,originalEvent:t,ports:r,sw:i}))}))},function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];try{return Promise.resolve(i.apply(this,t))}catch(t){return Promise.reject(t)}}),e.zt=n,e.At=r,navigator.serviceWorker.addEventListener("message",e.Xt),e}var o,u;u=t,(o=r).prototype=Object.create(u.prototype),o.prototype.constructor=o,i(o,u);var v,d,m,y=r.prototype;return y.register=function(t){var n=(void 0===t?{}:t).immediate,r=void 0!==n&&n;try{var e=this;return s(function(t,n){var r=t();if(r&&r.then)return r.then(n);return n(r)}((function(){if(!r&&"complete"!==document.readyState)return l(new Promise((function(t){return window.addEventListener("load",t)})))}),(function(){return e.Jt=Boolean(navigator.serviceWorker.controller),e.Yt=e.Zt(),s(e.tn(),(function(t){e.Kt=t,e.Yt&&(e.Ft=e.Yt,e.Mt.resolve(e.Yt),e.Bt.resolve(e.Yt),e.Yt.addEventListener("statechange",e.Ht,{once:!0}));var n=e.Kt.waiting;return n&&c(n.scriptURL,e.zt.toString())&&(e.Ft=n,Promise.resolve().then((function(){e.dispatchEvent(new f("waiting",{sw:n,wasWaitingBeforeRegister:!0}))})).then((function(){}))),e.Ft&&(e.Tt.resolve(e.Ft),e.Nt.add(e.Ft)),e.Kt.addEventListener("updatefound",e.Gt),navigator.serviceWorker.addEventListener("controllerchange",e.Vt),e.Kt}))})))}catch(t){return Promise.reject(t)}},y.update=function(){try{return this.Kt?s(l(this.Kt.update())):s()}catch(t){return Promise.reject(t)}},y.getSW=function(){return void 0!==this.Ft?Promise.resolve(this.Ft):this.Tt.promise},y.messageSW=function(t){try{return s(this.getSW(),(function(r){return n(r,t)}))}catch(t){return Promise.reject(t)}},y.messageSkipWaiting=function(){this.Kt&&this.Kt.waiting&&n(this.Kt.waiting,h)},y.Zt=function(){var t=navigator.serviceWorker.controller;return t&&c(t.scriptURL,this.zt.toString())?t:void 0},y.tn=function(){try{var t=this;return s(function(t,n){try{var r=t()}catch(t){return n(t)}if(r&&r.then)return r.then(void 0,n);return r}((function(){return s(navigator.serviceWorker.register(t.zt,t.At),(function(n){return t.Lt=performance.now(),n}))}),(function(t){throw t})))}catch(t){return Promise.reject(t)}},v=r,(d=[{key:"active",get:function(){return this.Mt.promise}},{key:"controlling",get:function(){return this.Bt.promise}}])&&e(v.prototype,d),m&&e(v,m),Object.defineProperty(v,"prototype",{writable:!1}),v}(function(){function t(){this.nn=new Map}var n=t.prototype;return n.addEventListener=function(t,n){this.rn(t).add(n)},n.removeEventListener=function(t,n){this.rn(t).delete(n)},n.dispatchEvent=function(t){t.target=this;for(var n,r=u(this.rn(t.type));!(n=r()).done;){(0,n.value)(t)}},n.rn=function(t){return this.nn.has(t)||this.nn.set(t,new Set),this.nn.get(t)},t}());t.Workbox=d,t.WorkboxEvent=f,t.messageSW=n,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=workbox-window.prod.umd.js.map |
{ | ||
"name": "workbox-window", | ||
"version": "7.0.0", | ||
"version": "7.1.0", | ||
"license": "MIT", | ||
@@ -28,5 +28,5 @@ "author": "Google's Web DevRel Team", | ||
"@types/trusted-types": "^2.0.2", | ||
"workbox-core": "7.0.0" | ||
"workbox-core": "7.1.0" | ||
}, | ||
"gitHead": "c1d11636823e5e3a89520f7a531970a39304b14a" | ||
"gitHead": "9e69c4269c35e2db9fbba4d13e4e6206c7b66d2a" | ||
} |
// @ts-ignore | ||
try{self['workbox:window:7.0.0']&&_()}catch(e){} | ||
try{self['workbox:window:7.1.0']&&_()}catch(e){} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
576750
4917
+ Addedworkbox-core@7.1.0(transitive)
- Removedworkbox-core@7.0.0(transitive)
Updatedworkbox-core@7.1.0