Socket
Socket
Sign inDemoInstall

workbox-window

Package Overview
Dependencies
1
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.3 to 6.0.0-alpha.0

180

build/workbox-window.dev.umd.js

@@ -67,2 +67,39 @@ (function (global, factory) {

function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
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) {
var i = 0;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) return function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[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.");
}
i = o[Symbol.iterator]();
return i.next.bind(i);
}
try {

@@ -251,15 +288,4 @@ self['workbox:core:5.1.3'] && _();

for (var _iterator = listeners, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var listener = _ref;
for (var _iterator = _createForOfIteratorHelperLoose(listeners), _step; !(_step = _iterator()).done;) {
var listener = _step.value;
listener(event);

@@ -363,3 +389,10 @@ }

var REGISTRATION_TIMEOUT_DURATION = 60000;
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 = {
type: 'SKIP_WAITING'
};
/**

@@ -375,9 +408,10 @@ * A class to aid in handling service worker registration, updates, and

* @fires [redundant]{@link module:workbox-window.Workbox#redundant}
* @fires [externalinstalled]{@link module:workbox-window.Workbox#externalinstalled}
* @fires [externalwaiting]{@link module:workbox-window.Workbox#externalwaiting}
* @fires [externalactivated]{@link module:workbox-window.Workbox#externalactivated}
* @memberof module:workbox-window
*/
function _empty() {}
function _awaitIgnored(value, direct) {
if (!direct) {
return value && value.then ? value.then(_empty) : Promise.resolve();
}
}

@@ -490,5 +524,5 @@ var Workbox = /*#__PURE__*/function (_WorkboxEventTarget) {

var isExternal = sw === _this._externalSW;
var eventPrefix = isExternal ? 'external' : '';
var eventProps = {
sw: sw,
isExternal: isExternal,
originalEvent: originalEvent

@@ -501,3 +535,3 @@ };

_this.dispatchEvent(new WorkboxEvent(eventPrefix + state, eventProps));
_this.dispatchEvent(new WorkboxEvent(state, eventProps));

@@ -516,3 +550,3 @@ if (state === 'installed') {

if (state === 'installed' && registration.waiting === sw) {
_this.dispatchEvent(new WorkboxEvent(eventPrefix + 'waiting', eventProps));
_this.dispatchEvent(new WorkboxEvent('waiting', eventProps));

@@ -804,11 +838,5 @@ {

_proto.getSW = function getSW() {
try {
var _this7 = this;
// If `this._sw` is set, resolve with that as we want `getSW()` to
// return the correct (new) service worker if an update is found.
return _this7._sw !== undefined ? _this7._sw : _this7._swDeferred.promise;
} catch (e) {
return Promise.reject(e);
}
// If `this._sw` is set, resolve with that as we want `getSW()` to
// return the correct (new) service worker if an update is found.
return this._sw !== undefined ? Promise.resolve(this._sw) : this._swDeferred.promise;
}

@@ -832,5 +860,5 @@ /**

try {
var _this9 = this;
var _this7 = this;
return _await(_this9.getSW(), function (sw) {
return _await(_this7.getSW(), function (sw) {
return messageSW(sw, data);

@@ -843,2 +871,16 @@ });

/**
* Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's
* currently in the `waiting` state associated with the current registration.
*
* If there is no current registration or no service worker is `waiting`,
* calling this will have no effect.
*/
;
_proto.messageSkipWaiting = function messageSkipWaiting() {
if (this._registration && this._registration.waiting) {
messageSW(this._registration.waiting, SKIP_WAITING_MESSAGE);
}
}
/**
* Checks for a service worker already controlling the page and returns

@@ -871,10 +913,10 @@ * it if its script URL matches.

try {
var _this11 = this;
var _this9 = this;
return _catch(function () {
return _await(navigator.serviceWorker.register(_this11._scriptURL, _this11._registerOptions), function (reg) {
return _await(navigator.serviceWorker.register(_this9._scriptURL, _this9._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.
_this11._registrationTime = performance.now();
_this9._registrationTime = performance.now();
return reg;

@@ -923,6 +965,10 @@ });

function _awaitIgnored(value, direct) {
if (!direct) {
return value && value.then ? value.then(_empty) : Promise.resolve();
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:

@@ -960,2 +1006,4 @@ // -----------------------------------------------------------------------

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `installed`.

@@ -984,2 +1032,4 @@ * @property {Workbox} target The `Workbox` instance.

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with

@@ -1025,2 +1075,4 @@ * a matching `scriptURL` was already waiting when this `Workbox`

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `activated`.

@@ -1047,55 +1099,3 @@ * @property {Workbox} target The `Workbox` instance.

/**
* The `externalinstalled` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `installed`.
*
* @event module:workbox-window.Workbox#externalinstalled
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalinstalled`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalwaiting` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `waiting`.
*
* @event module:workbox-window.Workbox#externalwaiting
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalwaiting`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalactivated` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `activated`.
*
* @event module:workbox-window.Workbox#externalactivated
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalactivated`.
* @property {Workbox} target The `Workbox` instance.
*/
function _invoke(body, then) {
var result = body();
if (result && result.then) {
return result.then(then);
}
return then(result);
}
function _catch(body, recover) {

@@ -1102,0 +1102,0 @@ try {

@@ -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=n||self).workbox={})}(this,(function(n){"use strict";try{self["workbox:window:5.1.3"]&&_()}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)}}try{self["workbox:core:5.1.3"]&&_()}catch(n){}var e=function(){var n=this;this.promise=new Promise((function(t,r){n.resolve=t,n.reject=r}))};function i(n,t){var r=location.href;return new URL(n,r).href===new URL(t,r).href}var o=function(n,t){this.type=n,Object.assign(this,t)};function u(n,t,r){return r?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function c(){}var a=function(n){var c,a;function s(t,r){var c,a;return void 0===r&&(r={}),(c=n.call(this)||this).t={},c.i=0,c.o=new e,c.u=new e,c.s=new e,c.v=0,c.h=new Set,c.l=function(){var n=c.g,t=n.installing;c.i>0||!i(t.scriptURL,c.m)||performance.now()>c.v+6e4?(c.p=t,n.removeEventListener("updatefound",c.l)):(c.P=t,c.h.add(t),c.o.resolve(t)),++c.i,t.addEventListener("statechange",c.j)},c.j=function(n){var t=c.g,r=n.target,e=r.state,i=r===c.p,u=i?"external":"",a={sw:r,originalEvent:n};!i&&c.k&&(a.isUpdate=!0),c.dispatchEvent(new o(u+e,a)),"installed"===e?c.O=self.setTimeout((function(){"installed"===e&&t.waiting===r&&c.dispatchEvent(new o(u+"waiting",a))}),200):"activating"===e&&(clearTimeout(c.O),i||c.u.resolve(r))},c._=function(n){var t=c.P;t===navigator.serviceWorker.controller&&(c.dispatchEvent(new o("controlling",{sw:t,originalEvent:n,isUpdate:c.k})),c.s.resolve(t))},c.M=(a=function(n){var t=n.data,r=n.source;return u(c.getSW(),(function(){c.h.has(r)&&c.dispatchEvent(new o("message",{data:t,sw:r,originalEvent:n}))}))},function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{return Promise.resolve(a.apply(this,n))}catch(n){return Promise.reject(n)}}),c.m=t,c.t=r,navigator.serviceWorker.addEventListener("message",c.M),c}a=n,(c=s).prototype=Object.create(a.prototype),c.prototype.constructor=c,c.__proto__=a;var v,h,l,w=s.prototype;return w.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 f(new Promise((function(n){return window.addEventListener("load",n)})))}),(function(){return e.k=Boolean(navigator.serviceWorker.controller),e.R=e.S(),u(e.U(),(function(n){e.g=n,e.R&&(e.P=e.R,e.u.resolve(e.R),e.s.resolve(e.R),e.R.addEventListener("statechange",e.j,{once:!0}));var t=e.g.waiting;return t&&i(t.scriptURL,e.m)&&(e.P=t,Promise.resolve().then((function(){e.dispatchEvent(new o("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})).then((function(){}))),e.P&&(e.o.resolve(e.P),e.h.add(e.P)),e.g.addEventListener("updatefound",e.l),navigator.serviceWorker.addEventListener("controllerchange",e._,{once:!0}),e.g}))}))}catch(n){return Promise.reject(n)}},w.update=function(){try{return this.g?f(this.g.update()):void 0}catch(n){return Promise.reject(n)}},w.getSW=function(){try{return void 0!==this.P?this.P:this.o.promise}catch(n){return Promise.reject(n)}},w.messageSW=function(n){try{return u(this.getSW(),(function(r){return t(r,n)}))}catch(n){return Promise.reject(n)}},w.S=function(){var n=navigator.serviceWorker.controller;return n&&i(n.scriptURL,this.m)?n:void 0},w.U=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 u(navigator.serviceWorker.register(n.m,n.t),(function(t){return n.v=performance.now(),t}))}),(function(n){throw n}))}catch(n){return Promise.reject(n)}},v=s,(h=[{key:"active",get:function(){return this.u.promise}},{key:"controlling",get:function(){return this.s.promise}}])&&r(v.prototype,h),l&&r(v,l),s}(function(){function n(){this.B=new Map}var t=n.prototype;return t.addEventListener=function(n,t){this.L(n).add(t)},t.removeEventListener=function(n,t){this.L(n).delete(t)},t.dispatchEvent=function(n){n.target=this;var t=this.L(n.type),r=Array.isArray(t),e=0;for(t=r?t:t[Symbol.iterator]();;){var i;if(r){if(e>=t.length)break;i=t[e++]}else{if((e=t.next()).done)break;i=e.value}i(n)}},t.L=function(n){return this.B.has(n)||this.B.set(n,new Set),this.B.get(n)},n}());function f(n,t){if(!t)return n&&n.then?n.then(c):Promise.resolve()}n.Workbox=a,n.messageSW=t,Object.defineProperty(n,"__esModule",{value:!0})}));
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n=n||self).workbox={})}(this,(function(n){"use strict";try{self["workbox:window:5.1.3"]&&_()}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){var t=0;if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(n=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(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?e(n,t):void 0}}(n)))return function(){return t>=n.length?{done:!0}:{done:!1,value:n[t++]}};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(t=n[Symbol.iterator]()).next.bind(t)}try{self["workbox:core:5.1.3"]&&_()}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).t={},e.i=0,e.o=new o,e.u=new o,e.s=new o,e.v=0,e.h=new Set,e.l=function(){var n=e.m,t=n.installing;e.i>0||!u(t.scriptURL,e.g)||performance.now()>e.v+6e4?(e.p=t,n.removeEventListener("updatefound",e.l)):(e.P=t,e.h.add(t),e.o.resolve(t)),++e.i,t.addEventListener("statechange",e.j)},e.j=function(n){var t=e.m,r=n.target,i=r.state,o=r===e.p,u={sw:r,isExternal:o,originalEvent:n};!o&&e.S&&(u.isUpdate=!0),e.dispatchEvent(new a(i,u)),"installed"===i?e.A=self.setTimeout((function(){"installed"===i&&t.waiting===r&&e.dispatchEvent(new a("waiting",u))}),200):"activating"===i&&(clearTimeout(e.A),o||e.u.resolve(r))},e.I=function(n){var t=e.P;t===navigator.serviceWorker.controller&&(e.dispatchEvent(new a("controlling",{sw:t,originalEvent:n,isUpdate:e.S})),e.s.resolve(t))},e.O=(i=function(n){var t=n.data,r=n.source;return c(e.getSW(),(function(){e.h.has(r)&&e.dispatchEvent(new a("message",{data:t,sw:r,originalEvent:n}))}))},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.g=t,e.t=r,navigator.serviceWorker.addEventListener("message",e.O),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.S=Boolean(navigator.serviceWorker.controller),e._=e.M(),c(e.U(),(function(n){e.m=n,e._&&(e.P=e._,e.u.resolve(e._),e.s.resolve(e._),e._.addEventListener("statechange",e.j,{once:!0}));var t=e.m.waiting;return t&&u(t.scriptURL,e.g)&&(e.P=t,Promise.resolve().then((function(){e.dispatchEvent(new a("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})).then((function(){}))),e.P&&(e.o.resolve(e.P),e.h.add(e.P)),e.m.addEventListener("updatefound",e.l),navigator.serviceWorker.addEventListener("controllerchange",e.I,{once:!0}),e.m}))}))}catch(n){return Promise.reject(n)}},m.update=function(){try{return this.m?v(this.m.update()):void 0}catch(n){return Promise.reject(n)}},m.getSW=function(){return void 0!==this.P?Promise.resolve(this.P):this.o.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.m&&this.m.waiting&&t(this.m.waiting,s)},m.M=function(){var n=navigator.serviceWorker.controller;return n&&u(n.scriptURL,this.g)?n:void 0},m.U=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.g,n.t),(function(t){return n.v=performance.now(),t}))}),(function(n){throw n}))}catch(n){return Promise.reject(n)}},h=f,(l=[{key:"active",get:function(){return this.u.promise}},{key:"controlling",get:function(){return this.s.promise}}])&&r(h.prototype,l),d&&r(h,d),f}(function(){function n(){this.R=new Map}var t=n.prototype;return t.addEventListener=function(n,t){this.T(n).add(t)},t.removeEventListener=function(n,t){this.T(n).delete(t)},t.dispatchEvent=function(n){n.target=this;for(var t,r=i(this.T(n.type));!(t=r()).done;){(0,t.value)(n)}},t.T=function(n){return this.R.has(n)||this.R.set(n,new Set),this.R.get(n)},n}());n.Workbox=h,n.messageSW=t,Object.defineProperty(n,"__esModule",{value:!0})}));
//# sourceMappingURL=workbox-window.prod.umd.js.map
{
"name": "workbox-window",
"version": "5.1.3",
"version": "6.0.0-alpha.0",
"license": "MIT",

@@ -19,7 +19,2 @@ "author": "Google's Web DevRel Team",

],
"scripts": {
"build": "gulp build-packages --package workbox-window",
"version": "npm run build",
"prepare": "npm run build"
},
"workbox": {

@@ -33,5 +28,5 @@ "packageType": "window",

"dependencies": {
"workbox-core": "^5.1.3"
"workbox-core": "^6.0.0-alpha.0"
},
"gitHead": "fe4399505e02c3af6515fc8ffae8c58791f43f3c"
"gitHead": "3dfe1f4c5ed450bc4b7420321f1a113ff4382d1b"
}

@@ -23,2 +23,3 @@ /*

originalEvent?: Event;
isExternal?: boolean;

@@ -50,7 +51,2 @@ constructor(public type: K, props: Omit<WorkboxEventMap[K], 'target' | 'type'>) {

'controlling': WorkboxLifecycleEvent;
'externalinstalling': WorkboxLifecycleEvent;
'externalinstalled': WorkboxLifecycleEvent;
'externalwaiting': WorkboxLifecycleWaitingEvent;
'externalactivating': WorkboxLifecycleEvent;
'externalactivated': WorkboxLifecycleEvent;
'redundant': WorkboxLifecycleEvent;

@@ -57,0 +53,0 @@ }

@@ -30,2 +30,6 @@ /*

// The de facto standard message that a service worker should be listening for
// to trigger a call to skipWaiting().
const SKIP_WAITING_MESSAGE = {type: 'SKIP_WAITING'};
/**

@@ -41,5 +45,2 @@ * A class to aid in handling service worker registration, updates, and

* @fires [redundant]{@link module:workbox-window.Workbox#redundant}
* @fires [externalinstalled]{@link module:workbox-window.Workbox#externalinstalled}
* @fires [externalwaiting]{@link module:workbox-window.Workbox#externalwaiting}
* @fires [externalactivated]{@link module:workbox-window.Workbox#externalactivated}
* @memberof module:workbox-window

@@ -258,6 +259,8 @@ */

*/
async getSW(): Promise<ServiceWorker> {
getSW(): Promise<ServiceWorker> {
// If `this._sw` is set, resolve with that as we want `getSW()` to
// return the correct (new) service worker if an update is found.
return this._sw !== undefined ? this._sw : this._swDeferred.promise;
return this._sw !== undefined ?
Promise.resolve(this._sw) :
this._swDeferred.promise;
}

@@ -284,2 +287,15 @@

/**
* Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's
* currently in the `waiting` state associated with the current registration.
*
* If there is no current registration or no service worker is `waiting`,
* calling this will have no effect.
*/
messageSkipWaiting() {
if (this._registration && this._registration.waiting) {
messageSW(this._registration.waiting, SKIP_WAITING_MESSAGE);
}
}
/**
* Checks for a service worker already controlling the page and returns

@@ -405,6 +421,11 @@ * it if its script URL matches.

const isExternal = sw === this._externalSW;
const eventPrefix = isExternal ? 'external' : '';
const eventProps: {sw: ServiceWorker; originalEvent: Event; isUpdate?: boolean} = {
const eventProps: {
sw: ServiceWorker;
originalEvent: Event;
isUpdate?: boolean;
isExternal: boolean;
} = {
sw,
isExternal,
originalEvent

@@ -416,4 +437,3 @@ };

this.dispatchEvent(new WorkboxEvent(
eventPrefix + state as keyof WorkboxLifecycleEventMap, eventProps));
this.dispatchEvent(new WorkboxEvent(state as keyof WorkboxLifecycleEventMap, eventProps));

@@ -432,4 +452,3 @@ if (state === 'installed') {

if (state === 'installed' && registration.waiting === sw) {
this.dispatchEvent(new WorkboxEvent(
eventPrefix + 'waiting' as keyof WorkboxLifecycleEventMap, eventProps));
this.dispatchEvent(new WorkboxEvent('waiting', eventProps));

@@ -568,2 +587,4 @@ if (process.env.NODE_ENV !== 'production') {

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `installed`.

@@ -592,2 +613,4 @@ * @property {Workbox} target The `Workbox` instance.

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with

@@ -633,2 +656,4 @@ * a matching `scriptURL` was already waiting when this `Workbox`

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `activated`.

@@ -655,42 +680,1 @@ * @property {Workbox} target The `Workbox` instance.

/**
* The `externalinstalled` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `installed`.
*
* @event module:workbox-window.Workbox#externalinstalled
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalinstalled`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalwaiting` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `waiting`.
*
* @event module:workbox-window.Workbox#externalwaiting
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalwaiting`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalactivated` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `activated`.
*
* @event module:workbox-window.Workbox#externalactivated
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalactivated`.
* @property {Workbox} target The `Workbox` instance.
*/

@@ -14,2 +14,3 @@ import { WorkboxEventTarget } from './WorkboxEventTarget.js';

originalEvent?: Event;
isExternal?: boolean;
constructor(type: K, props: Omit<WorkboxEventMap[K], 'target' | 'type'>);

@@ -34,7 +35,2 @@ }

'controlling': WorkboxLifecycleEvent;
'externalinstalling': WorkboxLifecycleEvent;
'externalinstalled': WorkboxLifecycleEvent;
'externalwaiting': WorkboxLifecycleWaitingEvent;
'externalactivating': WorkboxLifecycleEvent;
'externalactivated': WorkboxLifecycleEvent;
'redundant': WorkboxLifecycleEvent;

@@ -41,0 +37,0 @@ }

@@ -13,5 +13,2 @@ import { WorkboxEventTarget } from './utils/WorkboxEventTarget.js';

* @fires [redundant]{@link module:workbox-window.Workbox#redundant}
* @fires [externalinstalled]{@link module:workbox-window.Workbox#externalinstalled}
* @fires [externalwaiting]{@link module:workbox-window.Workbox#externalwaiting}
* @fires [externalactivated]{@link module:workbox-window.Workbox#externalactivated}
* @memberof module:workbox-window

@@ -117,2 +114,10 @@ */

/**
* Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's
* currently in the `waiting` state associated with the current registration.
*
* If there is no current registration or no service worker is `waiting`,
* calling this will have no effect.
*/
messageSkipWaiting(): void;
/**
* Checks for a service worker already controlling the page and returns

@@ -181,2 +186,4 @@ * it if its script URL matches.

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `installed`.

@@ -204,2 +211,4 @@ * @property {Workbox} target The `Workbox` instance.

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with

@@ -243,2 +252,4 @@ * a matching `scriptURL` was already waiting when this `Workbox`

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `activated`.

@@ -263,40 +274,1 @@ * @property {Workbox} target The `Workbox` instance.

*/
/**
* The `externalinstalled` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `installed`.
*
* @event module:workbox-window.Workbox#externalinstalled
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalinstalled`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalwaiting` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `waiting`.
*
* @event module:workbox-window.Workbox#externalwaiting
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalwaiting`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalactivated` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `activated`.
*
* @event module:workbox-window.Workbox#externalactivated
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalactivated`.
* @property {Workbox} target The `Workbox` instance.
*/

@@ -23,2 +23,5 @@ /*

const REGISTRATION_TIMEOUT_DURATION = 60000;
// The de facto standard message that a service worker should be listening for
// to trigger a call to skipWaiting().
const SKIP_WAITING_MESSAGE = { type: 'SKIP_WAITING' };
/**

@@ -34,5 +37,2 @@ * A class to aid in handling service worker registration, updates, and

* @fires [redundant]{@link module:workbox-window.Workbox#redundant}
* @fires [externalinstalled]{@link module:workbox-window.Workbox#externalinstalled}
* @fires [externalwaiting]{@link module:workbox-window.Workbox#externalwaiting}
* @fires [externalactivated]{@link module:workbox-window.Workbox#externalactivated}
* @memberof module:workbox-window

@@ -137,5 +137,5 @@ */

const isExternal = sw === this._externalSW;
const eventPrefix = isExternal ? 'external' : '';
const eventProps = {
sw,
isExternal,
originalEvent

@@ -146,3 +146,3 @@ };

}
this.dispatchEvent(new WorkboxEvent(eventPrefix + state, eventProps));
this.dispatchEvent(new WorkboxEvent(state, eventProps));
if (state === 'installed') {

@@ -160,3 +160,3 @@ // This timeout is used to ignore cases where the service worker calls

if (state === 'installed' && registration.waiting === sw) {
this.dispatchEvent(new WorkboxEvent(eventPrefix + 'waiting', eventProps));
this.dispatchEvent(new WorkboxEvent('waiting', eventProps));
if (process.env.NODE_ENV !== 'production') {

@@ -412,6 +412,8 @@ if (isExternal) {

*/
async getSW() {
getSW() {
// If `this._sw` is set, resolve with that as we want `getSW()` to
// return the correct (new) service worker if an update is found.
return this._sw !== undefined ? this._sw : this._swDeferred.promise;
return this._sw !== undefined ?
Promise.resolve(this._sw) :
this._swDeferred.promise;
}

@@ -436,2 +438,14 @@ /**

/**
* Sends a `{type: 'SKIP_WAITING'}` message to the service worker that's
* currently in the `waiting` state associated with the current registration.
*
* If there is no current registration or no service worker is `waiting`,
* calling this will have no effect.
*/
messageSkipWaiting() {
if (this._registration && this._registration.waiting) {
messageSW(this._registration.waiting, SKIP_WAITING_MESSAGE);
}
}
/**
* Checks for a service worker already controlling the page and returns

@@ -507,2 +521,4 @@ * it if its script URL matches.

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `installed`.

@@ -530,2 +546,4 @@ * @property {Workbox} target The `Workbox` instance.

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {boolean|undefined} wasWaitingBeforeRegister True if a service worker with

@@ -569,2 +587,4 @@ * a matching `scriptURL` was already waiting when this `Workbox`

* controlling when this `Workbox` instance called `register()`.
* @property {boolean|undefined} isExternal True if this event is associated
* with an [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}.
* @property {string} type `activated`.

@@ -589,40 +609,1 @@ * @property {Workbox} target The `Workbox` instance.

*/
/**
* The `externalinstalled` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `installed`.
*
* @event module:workbox-window.Workbox#externalinstalled
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalinstalled`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalwaiting` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `waiting`.
*
* @event module:workbox-window.Workbox#externalwaiting
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalwaiting`.
* @property {Workbox} target The `Workbox` instance.
*/
/**
* The `externalactivated` event is dispatched if the state of an
* [external service worker]{@link https://developers.google.com/web/tools/workbox/modules/workbox-window#when_an_unexpected_version_of_the_service_worker_is_found}
* changes to `activated`.
*
* @event module:workbox-window.Workbox#externalactivated
* @type {WorkboxEvent}
* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.
* @property {string} type `externalactivated`.
* @property {Workbox} target The `Workbox` instance.
*/

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc