Socket
Socket
Sign inDemoInstall

workbox-window

Package Overview
Dependencies
Maintainers
4
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-window - npm Package Compare versions

Comparing version 5.0.0-alpha.1 to 5.0.0-alpha.2

2

_version.js
// @ts-ignore
try {
self['workbox:window:5.0.0-alpha.1'] && _();
self['workbox:window:5.0.0-alpha.2'] && _();
}
catch (e) { }

@@ -9,3 +9,3 @@ (function (global, factory) {

try {
self['workbox:window:5.0.0-alpha.1'] && _();
self['workbox:window:5.0.0-alpha.2'] && _();
} catch (e) {}

@@ -72,3 +72,3 @@

try {
self['workbox:core:5.0.0-alpha.1'] && _();
self['workbox:core:5.0.0-alpha.2'] && _();
} catch (e) {}

@@ -111,3 +111,3 @@

*/
var logger = function () {
var logger = function () {
var inGroup = false;

@@ -183,2 +183,3 @@ var methodToColorMap = {

*/
/**

@@ -190,3 +191,2 @@ * A minimal `EventTarget` shim.

*/
var WorkboxEventTarget =

@@ -196,3 +196,3 @@ /*#__PURE__*/

function WorkboxEventTarget() {
this._eventListenerRegistry = {};
this._eventListenerRegistry = new Map();
}

@@ -209,3 +209,5 @@ /**

_proto.addEventListener = function addEventListener(type, listener) {
this._getEventListenersByType(type).add(listener);
var foo = this._getEventListenersByType(type);
foo.add(listener);
};

@@ -260,3 +262,7 @@ /**

_proto._getEventListenersByType = function _getEventListenersByType(type) {
return this._eventListenerRegistry[type] = this._eventListenerRegistry[type] || new Set();
if (!this._eventListenerRegistry.has(type)) {
this._eventListenerRegistry.set(type, new Set());
}
return this._eventListenerRegistry.get(type);
};

@@ -323,2 +329,20 @@

function _invoke(body, then) {
var result = body();
if (result && result.then) {
return result.then(then);
}
return then(result);
}
function _awaitIgnored(value, direct) {
if (!direct) {
return value && value.then ? value.then(_empty) : Promise.resolve();
}
}
function _empty() {}
function _async(f) {

@@ -338,12 +362,2 @@ return function () {

function _invoke(body, then) {
var result = body();
if (result && result.then) {
return result.then(then);
}
return then(result);
}
function _await(value, then, direct) {

@@ -360,10 +374,2 @@ if (direct) {

}
function _awaitIgnored(value, direct) {
if (!direct) {
return value && value.then ? value.then(_empty) : Promise.resolve();
}
}
function _empty() {}
// `skipWaiting()` wasn't called. This 200 amount wasn't scientifically

@@ -605,11 +611,14 @@ // chosen, but it seems to avoid false positives in my testing.

_this._onMessage = function (originalEvent) {
_this._onMessage = _async(function (originalEvent) {
var data = originalEvent.data;
_this.dispatchEvent(new WorkboxEvent('message', {
data: data,
originalEvent: originalEvent
}));
};
var _this2 = _this,
_dispatchEvent = _this2.dispatchEvent;
return _await(_this.getSW(), function (_this$getSW) {
_dispatchEvent.call(_this2, new WorkboxEvent('message', {
data: data,
sw: _this$getSW,
originalEvent: originalEvent
}));
});
});
_this._scriptURL = scriptURL;

@@ -633,3 +642,3 @@ _this._registerOptions = registerOptions;

_proto.register = _async(function (_temp) {
var _this2 = this;
var _this3 = this;

@@ -641,3 +650,3 @@ var _ref = _temp === void 0 ? {} : _temp,

{
if (_this2._registrationTime) {
if (_this3._registrationTime) {
logger.error('Cannot re-register a Workbox instance after it has ' + 'been registered. Create a new instance instead.');

@@ -657,22 +666,22 @@ return;

// at registration time.
_this2._isUpdate = Boolean(navigator.serviceWorker.controller); // Before registering, attempt to determine if a SW is already controlling
_this3._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.
_this2._compatibleControllingSW = _this2._getControllingSWIfCompatible();
return _await(_this2._registerScript(), function (_this2$_registerScrip) {
_this2._registration = _this2$_registerScrip;
_this3._compatibleControllingSW = _this3._getControllingSWIfCompatible();
return _await(_this3._registerScript(), function (_this3$_registerScrip) {
_this3._registration = _this3$_registerScrip;
// If we have a compatible controller, store the controller as the "own"
// SW, resolve active/controlling deferreds and add necessary listeners.
if (_this2._compatibleControllingSW) {
_this2._sw = _this2._compatibleControllingSW;
if (_this3._compatibleControllingSW) {
_this3._sw = _this3._compatibleControllingSW;
_this2._activeDeferred.resolve(_this2._compatibleControllingSW);
_this3._activeDeferred.resolve(_this3._compatibleControllingSW);
_this2._controllingDeferred.resolve(_this2._compatibleControllingSW);
_this3._controllingDeferred.resolve(_this3._compatibleControllingSW);
_this2._reportWindowReady(_this2._compatibleControllingSW);
_this3._reportWindowReady(_this3._compatibleControllingSW);
_this2._compatibleControllingSW.addEventListener('statechange', _this2._onStateChange, {
_this3._compatibleControllingSW.addEventListener('statechange', _this3._onStateChange, {
once: true

@@ -687,12 +696,12 @@ });

var waitingSW = _this2._registration.waiting;
var waitingSW = _this3._registration.waiting;
if (waitingSW && urlsMatch(waitingSW.scriptURL, _this2._scriptURL)) {
if (waitingSW && urlsMatch(waitingSW.scriptURL, _this3._scriptURL)) {
// Store the waiting SW as the "own" Sw, even if it means overwriting
// a compatible controller.
_this2._sw = waitingSW; // Run this in the next microtask, so any code that adds an event
_this3._sw = waitingSW; // Run this in the next microtask, so any code that adds an event
// listener after awaiting `register()` will get this event.
Promise.resolve().then(function () {
_this2.dispatchEvent(new WorkboxEvent('waiting', {
_this3.dispatchEvent(new WorkboxEvent('waiting', {
sw: waitingSW,

@@ -709,11 +718,11 @@ wasWaitingBeforeRegister: true

if (_this2._sw) {
_this2._swDeferred.resolve(_this2._sw);
if (_this3._sw) {
_this3._swDeferred.resolve(_this3._sw);
}
{
logger.log('Successfully registered service worker.', _this2._scriptURL);
logger.log('Successfully registered service worker.', _this3._scriptURL);
if (navigator.serviceWorker.controller) {
if (_this2._compatibleControllingSW) {
if (_this3._compatibleControllingSW) {
logger.debug('A service worker with the same script URL ' + 'is already controlling this page.');

@@ -726,3 +735,3 @@ } else {

var currentPageIsOutOfScope = function currentPageIsOutOfScope() {
var scopeURL = new URL(_this2._registerOptions.scope || _this2._scriptURL, document.baseURI);
var scopeURL = new URL(_this3._registerOptions.scope || _this3._scriptURL, document.baseURI);
var scopeURLBasePath = new URL('./', scopeURL.href).pathname;

@@ -737,5 +746,5 @@ return !location.pathname.startsWith(scopeURLBasePath);

_this2._registration.addEventListener('updatefound', _this2._onUpdateFound);
_this3._registration.addEventListener('updatefound', _this3._onUpdateFound);
navigator.serviceWorker.addEventListener('controllerchange', _this2._onControllerChange, {
navigator.serviceWorker.addEventListener('controllerchange', _this3._onControllerChange, {
once: true

@@ -745,9 +754,9 @@ }); // Add message listeners.

if ('BroadcastChannel' in self) {
_this2._broadcastChannel = new BroadcastChannel('workbox');
_this3._broadcastChannel = new BroadcastChannel('workbox');
_this2._broadcastChannel.addEventListener('message', _this2._onMessage);
_this3._broadcastChannel.addEventListener('message', _this3._onMessage);
}
navigator.serviceWorker.addEventListener('message', _this2._onMessage);
return _this2._registration;
navigator.serviceWorker.addEventListener('message', _this3._onMessage);
return _this3._registration;
});

@@ -757,2 +766,20 @@ });

/**
* Checks for updates of the registered service worker.
*/
_proto.update = _async(function () {
var _this4 = this;
if (!_this4._registration) {
{
logger.error('Cannot update a Workbox instance without ' + 'being registered. Register the Workbox instance first.');
}
return;
} // Try to update registration
return _awaitIgnored(_this4._registration.update());
});
/**
* Resolves to the service worker registered by this instance as soon as it

@@ -783,7 +810,7 @@ * is active. If a service worker was already controlling at registration

_proto.getSW = _async(function () {
var _this3 = this;
var _this5 = 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 _this3._sw !== undefined ? _this3._sw : _this3._swDeferred.promise;
return _this5._sw !== undefined ? _this5._sw : _this5._swDeferred.promise;
});

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

_proto.messageSW = _async(function (data) {
var _this4 = this;
var _this6 = this;
return _await(_this4.getSW(), function (sw) {
return _await(_this6.getSW(), function (sw) {
return messageSW(sw, data);

@@ -814,3 +841,3 @@ });

* Checks for a service worker already controlling the page and returns
* it if its script URL matchs.
* it if its script URL matches.
*

@@ -839,10 +866,10 @@ * @private

_proto._registerScript = _async(function () {
var _this5 = this;
var _this7 = this;
return _catch(function () {
return _await(navigator.serviceWorker.register(_this5._scriptURL, _this5._registerOptions), function (reg) {
return _await(navigator.serviceWorker.register(_this7._scriptURL, _this7._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.
_this5._registrationTime = performance.now();
_this7._registrationTime = performance.now();
return reg;

@@ -901,10 +928,2 @@ });

/*
Copyright 2019 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
exports.Workbox = Workbox;

@@ -911,0 +930,0 @@ exports.messageSW = messageSW;

@@ -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.0.0-alpha.1"]&&_()}catch(n){}function t(n,t){return new Promise(function(e){var i=new MessageChannel;i.port1.onmessage=function(n){e(n.data)},n.postMessage(t,[i.port2])})}function e(n,t){for(var e=0;e<t.length;e++){var i=t[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}try{self["workbox:core:5.0.0-alpha.1"]&&_()}catch(n){}var i=function(){var n=this;this.promise=new Promise(function(t,e){n.resolve=t,n.reject=e})};function r(n,t){var e=location.href;return new URL(n,e).href===new URL(t,e).href}var o=function(n,t){this.type=n,Object.assign(this,t)};function a(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(n.apply(this,t))}catch(n){return Promise.reject(n)}}}function u(n,t,e){return e?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}function c(){}var f=200,s=6e4,v=function(n){var v,h;function l(t,e){var a;return void 0===e&&(e={}),(a=n.call(this)||this).t={},a.i=0,a.o=new i,a.u=new i,a.s=new i,a.v=0,a.h=function(){var n=a.l,t=n.installing;a.i>0||!r(t.scriptURL,a.g)||performance.now()>a.v+s?(a.m=t,n.removeEventListener("updatefound",a.h)):(a.p=t,a.o.resolve(t)),++a.i,t.addEventListener("statechange",a.P)},a.P=function(n){var t=a.l,e=n.target,i=e.state,r=e===a.m,u=r?"external":"",c={sw:e,originalEvent:n};!r&&a.k&&(c.isUpdate=!0),a.dispatchEvent(new o(u+i,c)),"installed"===i?a.j=self.setTimeout(function(){"installed"===i&&t.waiting===e&&a.dispatchEvent(new o(u+"waiting",c))},f):"activating"===i&&(clearTimeout(a.j),r||a.u.resolve(e))},a.O=function(n){var t=a.p;t===navigator.serviceWorker.controller&&(a.dispatchEvent(new o("controlling",{sw:t,originalEvent:n,isUpdate:a.k})),a.s.resolve(t))},a._=function(n){var t=n.data;a.dispatchEvent(new o("message",{data:t,originalEvent:n}))},a.g=t,a.t=e,a}h=n,(v=l).prototype=Object.create(h.prototype),v.prototype.constructor=v,v.__proto__=h;var d,w,g,m=l.prototype;return m.register=a(function(n){var t,e,i=this,a=(void 0===n?{}:n).immediate,f=void 0!==a&&a;return t=function(){return i.k=Boolean(navigator.serviceWorker.controller),i.B=i.R(),u(i.C(),function(n){i.l=n,i.B&&(i.p=i.B,i.u.resolve(i.B),i.s.resolve(i.B),i.L(i.B),i.B.addEventListener("statechange",i.P,{once:!0}));var t=i.l.waiting;return t&&r(t.scriptURL,i.g)&&(i.p=t,Promise.resolve().then(function(){i.dispatchEvent(new o("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})),i.p&&i.o.resolve(i.p),i.l.addEventListener("updatefound",i.h),navigator.serviceWorker.addEventListener("controllerchange",i.O,{once:!0}),"BroadcastChannel"in self&&(i.U=new BroadcastChannel("workbox"),i.U.addEventListener("message",i._)),navigator.serviceWorker.addEventListener("message",i._),i.l})},(e=function(){if(!f&&"complete"!==document.readyState)return function(n,t){if(!t)return n&&n.then?n.then(c):Promise.resolve()}(new Promise(function(n){return addEventListener("load",n)}))}())&&e.then?e.then(t):t(e)}),m.getSW=a(function(){return void 0!==this.p?this.p:this.o.promise}),m.messageSW=a(function(n){return u(this.getSW(),function(e){return t(e,n)})}),m.R=function(){var n=navigator.serviceWorker.controller;return n&&r(n.scriptURL,this.g)?n:void 0},m.C=a(function(){var n=this;return function(n,t){try{var e=n()}catch(n){return t(n)}return e&&e.then?e.then(void 0,t):e}(function(){return u(navigator.serviceWorker.register(n.g,n.t),function(t){return n.v=performance.now(),t})},function(n){throw n})}),m.L=function(n){t(n,{type:"WINDOW_READY",meta:"workbox-window"})},d=l,(w=[{key:"active",get:function(){return this.u.promise}},{key:"controlling",get:function(){return this.s.promise}}])&&e(d.prototype,w),g&&e(d,g),l}(function(){function n(){this.W={}}var t=n.prototype;return t.addEventListener=function(n,t){this.A(n).add(t)},t.removeEventListener=function(n,t){this.A(n).delete(t)},t.dispatchEvent=function(n){n.target=this;var t=this.A(n.type),e=Array.isArray(t),i=0;for(t=e?t:t[Symbol.iterator]();;){var r;if(e){if(i>=t.length)break;r=t[i++]}else{if((i=t.next()).done)break;r=i.value}r(n)}},t.A=function(n){return this.W[n]=this.W[n]||new Set},n}());n.Workbox=v,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.0.0-alpha.2"]&&_()}catch(n){}function t(n,t){return new Promise(function(e){var i=new MessageChannel;i.port1.onmessage=function(n){e(n.data)},n.postMessage(t,[i.port2])})}function e(n,t){for(var e=0;e<t.length;e++){var i=t[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}}try{self["workbox:core:5.0.0-alpha.2"]&&_()}catch(n){}var i=function(){var n=this;this.promise=new Promise(function(t,e){n.resolve=t,n.reject=e})};function r(n,t){var e=location.href;return new URL(n,e).href===new URL(t,e).href}var o=function(n,t){this.type=n,Object.assign(this,t)};function u(n,t){if(!t)return n&&n.then?n.then(a):Promise.resolve()}function a(){}function c(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(n.apply(this,t))}catch(n){return Promise.reject(n)}}}function f(n,t,e){return e?t?t(n):n:(n&&n.then||(n=Promise.resolve(n)),t?n.then(t):n)}var s=200,v=6e4,h=function(n){var a,h;function l(t,e){var u;return void 0===e&&(e={}),(u=n.call(this)||this).t={},u.i=0,u.o=new i,u.u=new i,u.s=new i,u.v=0,u.h=function(){var n=u.l,t=n.installing;u.i>0||!r(t.scriptURL,u.g)||performance.now()>u.v+v?(u.m=t,n.removeEventListener("updatefound",u.h)):(u.p=t,u.o.resolve(t)),++u.i,t.addEventListener("statechange",u.P)},u.P=function(n){var t=u.l,e=n.target,i=e.state,r=e===u.m,a=r?"external":"",c={sw:e,originalEvent:n};!r&&u.k&&(c.isUpdate=!0),u.dispatchEvent(new o(a+i,c)),"installed"===i?u.j=self.setTimeout(function(){"installed"===i&&t.waiting===e&&u.dispatchEvent(new o(a+"waiting",c))},s):"activating"===i&&(clearTimeout(u.j),r||u.u.resolve(e))},u.O=function(n){var t=u.p;t===navigator.serviceWorker.controller&&(u.dispatchEvent(new o("controlling",{sw:t,originalEvent:n,isUpdate:u.k})),u.s.resolve(t))},u._=c(function(n){var t=n.data,e=u,i=e.dispatchEvent;return f(u.getSW(),function(r){i.call(e,new o("message",{data:t,sw:r,originalEvent:n}))})}),u.g=t,u.t=e,u}h=n,(a=l).prototype=Object.create(h.prototype),a.prototype.constructor=a,a.__proto__=h;var w,d,g,m=l.prototype;return m.register=c(function(n){var t,e,i=this,a=(void 0===n?{}:n).immediate,c=void 0!==a&&a;return t=function(){return i.k=Boolean(navigator.serviceWorker.controller),i.B=i.R(),f(i.C(),function(n){i.l=n,i.B&&(i.p=i.B,i.u.resolve(i.B),i.s.resolve(i.B),i.L(i.B),i.B.addEventListener("statechange",i.P,{once:!0}));var t=i.l.waiting;return t&&r(t.scriptURL,i.g)&&(i.p=t,Promise.resolve().then(function(){i.dispatchEvent(new o("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})),i.p&&i.o.resolve(i.p),i.l.addEventListener("updatefound",i.h),navigator.serviceWorker.addEventListener("controllerchange",i.O,{once:!0}),"BroadcastChannel"in self&&(i.M=new BroadcastChannel("workbox"),i.M.addEventListener("message",i._)),navigator.serviceWorker.addEventListener("message",i._),i.l})},(e=function(){if(!c&&"complete"!==document.readyState)return u(new Promise(function(n){return addEventListener("load",n)}))}())&&e.then?e.then(t):t(e)}),m.update=c(function(){if(this.l)return u(this.l.update())}),m.getSW=c(function(){return void 0!==this.p?this.p:this.o.promise}),m.messageSW=c(function(n){return f(this.getSW(),function(e){return t(e,n)})}),m.R=function(){var n=navigator.serviceWorker.controller;return n&&r(n.scriptURL,this.g)?n:void 0},m.C=c(function(){var n=this;return function(n,t){try{var e=n()}catch(n){return t(n)}return e&&e.then?e.then(void 0,t):e}(function(){return f(navigator.serviceWorker.register(n.g,n.t),function(t){return n.v=performance.now(),t})},function(n){throw n})}),m.L=function(n){t(n,{type:"WINDOW_READY",meta:"workbox-window"})},w=l,(d=[{key:"active",get:function(){return this.u.promise}},{key:"controlling",get:function(){return this.s.promise}}])&&e(w.prototype,d),g&&e(w,g),l}(function(){function n(){this.U=new Map}var t=n.prototype;return t.addEventListener=function(n,t){this.W(n).add(t)},t.removeEventListener=function(n,t){this.W(n).delete(t)},t.dispatchEvent=function(n){n.target=this;var t=this.W(n.type),e=Array.isArray(t),i=0;for(t=e?t:t[Symbol.iterator]();;){var r;if(e){if(i>=t.length)break;r=t[i++]}else{if((i=t.next()).done)break;r=i.value}r(n)}},t.W=function(n){return this.U.has(n)||this.U.set(n,new Set),this.U.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.0.0-alpha.1",
"version": "5.0.0-alpha.2",
"license": "MIT",

@@ -32,5 +32,5 @@ "author": "Google's Web DevRel Team",

"dependencies": {
"workbox-core": "^5.0.0-alpha.1"
"workbox-core": "^5.0.0-alpha.2"
},
"gitHead": "20d2110ddace710a46af06addd4977cae08f5942"
"gitHead": "0cb0029b692c3802545238fe59b6d6179ca32f6c"
}
// @ts-ignore
try{self['workbox:window:5.0.0-alpha.1']&&_()}catch(e){}
try{self['workbox:window:5.0.0-alpha.2']&&_()}catch(e){}

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

import {WorkboxEventTarget} from './WorkboxEventTarget.js';

@@ -15,10 +14,2 @@ import '../_version.js';

export interface WorkboxEventProps {
sw?: ServiceWorker;
data?: any;
originalEvent?: Event;
isUpdate?: boolean;
wasWaitingBeforeRegister?: boolean;
}
/**

@@ -30,8 +21,41 @@ * A minimal `Event` subclass shim.

*/
export class WorkboxEvent {
target: WorkboxEventTarget;
export class WorkboxEvent<K extends keyof WorkboxEventMap> {
target?: WorkboxEventTarget;
sw: ServiceWorker;
originalEvent?: Event;
constructor(public type: string, props: WorkboxEventProps) {
constructor(public type: K, props: Omit<WorkboxEventMap[K], 'target' | 'type'>) {
Object.assign(this, props);
}
}
export interface WorkboxMessageEvent extends WorkboxEvent<'message'> {
originalEvent: Event;
data: any;
}
export interface WorkboxLifecycleEvent extends WorkboxEvent<keyof WorkboxLifecycleEventMap> {
isUpdate?: boolean;
}
export interface WorkboxLifecycleWaitingEvent extends WorkboxLifecycleEvent {
wasWaitingBeforeRegister?: boolean;
}
export interface WorkboxLifecycleEventMap {
'installing': WorkboxLifecycleEvent;
'installed': WorkboxLifecycleEvent;
'waiting': WorkboxLifecycleWaitingEvent;
'activating': WorkboxLifecycleEvent;
'activated': WorkboxLifecycleEvent;
'controlling': WorkboxLifecycleEvent;
'externalinstalling': WorkboxLifecycleEvent;
'externalinstalled': WorkboxLifecycleEvent;
'externalwaiting': WorkboxLifecycleWaitingEvent;
'externalactivating': WorkboxLifecycleEvent;
'externalactivated': WorkboxLifecycleEvent;
}
export interface WorkboxEventMap extends WorkboxLifecycleEventMap {
'message': WorkboxMessageEvent;
}

@@ -9,9 +9,7 @@ /*

import {WorkboxEvent} from './WorkboxEvent.js';
import '../_version.js';
import {WorkboxEvent, WorkboxEventMap} from './WorkboxEvent.js';
export type ListenerCallback = (event: WorkboxEvent) => void;
export type ListenerCallback = (event: WorkboxEvent<any>) => any;
/**

@@ -24,3 +22,3 @@ * A minimal `EventTarget` shim.

export class WorkboxEventTarget {
private _eventListenerRegistry: {[type: string]: Set<ListenerCallback>} = {};
private _eventListenerRegistry: Map<keyof WorkboxEventMap, Set<ListenerCallback>> = new Map();

@@ -32,4 +30,5 @@ /**

*/
addEventListener(type: string, listener: ListenerCallback) {
this._getEventListenersByType(type).add(listener);
addEventListener<K extends keyof WorkboxEventMap>(type: K, listener: (event: WorkboxEventMap[K]) => any) {
const foo = this._getEventListenersByType(type)
foo.add(listener);
}

@@ -42,3 +41,3 @@

*/
removeEventListener(type: string, listener: ListenerCallback) {
removeEventListener<K extends keyof WorkboxEventMap>(type: K, listener: (event: WorkboxEventMap[K]) => any) {
this._getEventListenersByType(type).delete(listener);

@@ -51,3 +50,3 @@ }

*/
dispatchEvent(event: WorkboxEvent) {
dispatchEvent(event: WorkboxEvent<any>) {
event.target = this;

@@ -69,6 +68,8 @@

*/
private _getEventListenersByType(type: string) {
return this._eventListenerRegistry[type] =
(this._eventListenerRegistry[type] || new Set());
private _getEventListenersByType(type: keyof WorkboxEventMap) {
if (!this._eventListenerRegistry.has(type)) {
this._eventListenerRegistry.set(type, new Set());
}
return this._eventListenerRegistry.get(type)!;
}
}

@@ -14,8 +14,6 @@ /*

import {urlsMatch} from './utils/urlsMatch.js';
import {WorkboxEvent} from './utils/WorkboxEvent.js';
import {WorkboxEvent, WorkboxLifecycleEventMap} from './utils/WorkboxEvent.js';
import './_version.js';
import {WorkboxEventProps} from './utils/WorkboxEvent.js';
// The time a SW must be in the waiting phase before we can conclude

@@ -200,2 +198,18 @@ // `skipWaiting()` wasn't called. This 200 amount wasn't scientifically

/**
* Checks for updates of the registered service worker.
*/
async update() {
if (!this._registration) {
if (process.env.NODE_ENV !== 'production') {
logger.error('Cannot update a Workbox instance without ' +
'being registered. Register the Workbox instance first.');
}
return;
}
// Try to update registration
await this._registration.update();
}
/**
* Resolves to the service worker registered by this instance as soon as it

@@ -270,3 +284,3 @@ * is active. If a service worker was already controlling at registration

* Checks for a service worker already controlling the page and returns
* it if its script URL matchs.
* it if its script URL matches.
*

@@ -276,3 +290,3 @@ * @private

*/
_getControllingSWIfCompatible() {
private _getControllingSWIfCompatible() {
const controller = navigator.serviceWorker.controller;

@@ -292,3 +306,3 @@ if (controller && urlsMatch(controller.scriptURL, this._scriptURL)) {

*/
async _registerScript() {
private async _registerScript() {
try {

@@ -320,3 +334,3 @@ const reg = await navigator.serviceWorker.register(

*/
_reportWindowReady(sw: ServiceWorker) {
private _reportWindowReady(sw: ServiceWorker) {
messageSW(sw, {

@@ -331,3 +345,3 @@ type: 'WINDOW_READY',

*/
_onUpdateFound = () => {
private _onUpdateFound = () => {
// `this._registration` will never be `undefined` after an update is found.

@@ -401,6 +415,6 @@ const registration = this._registration!;

*/
_onStateChange = (originalEvent: Event) => {
private _onStateChange = (originalEvent: Event) => {
// `this._registration` will never be `undefined` after an update is found.
const registration = this._registration!;
const sw = <ServiceWorker>originalEvent.target;
const sw = originalEvent.target as ServiceWorker;
const {state} = sw;

@@ -410,3 +424,6 @@ const isExternal = sw === this._externalSW;

const eventProps = <WorkboxEventProps> {sw, originalEvent};
const eventProps: {sw: ServiceWorker, originalEvent: Event, isUpdate?: boolean} = {
sw,
originalEvent
};
if (!isExternal && this._isUpdate) {

@@ -417,3 +434,3 @@ eventProps.isUpdate = true;

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

@@ -433,3 +450,3 @@ if (state === 'installed') {

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

@@ -491,3 +508,3 @@ if (process.env.NODE_ENV !== 'production') {

*/
_onControllerChange = (originalEvent: Event) => {
private _onControllerChange = (originalEvent: Event) => {
const sw = this._sw;

@@ -500,2 +517,3 @@ if (sw === navigator.serviceWorker.controller) {

}));
if (process.env.NODE_ENV !== 'production') {

@@ -512,5 +530,9 @@ logger.log('Registered service worker now controlling this page.');

*/
_onMessage = (originalEvent: MessageEvent) => {
private _onMessage = async (originalEvent: MessageEvent) => {
const {data} = originalEvent;
this.dispatchEvent(new WorkboxEvent('message', {data, originalEvent}));
this.dispatchEvent(new WorkboxEvent('message', {
data,
sw: await this.getSW(),
originalEvent,
}));
}

@@ -569,3 +591,6 @@ }

* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The native `controllerchange` event
* @property {Event|undefined} originalEvent The original
* [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event, or `undefined` in the case where the service worker was waiting
* to before `.register()` was called.
* @property {boolean|undefined} isUpdate True if a service worker was already

@@ -656,3 +681,3 @@ * controlling when this `Workbox` instance called `register()`.

* @property {ServiceWorker} sw The service worker instance.
* @property {Event|undefined} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.

@@ -659,0 +684,0 @@ * @property {string} type `externalwaiting`.

import { WorkboxEventTarget } from './WorkboxEventTarget.js';
import '../_version.js';
export interface WorkboxEventProps {
sw?: ServiceWorker;
data?: any;
originalEvent?: Event;
isUpdate?: boolean;
wasWaitingBeforeRegister?: boolean;
}
/**

@@ -16,6 +9,34 @@ * A minimal `Event` subclass shim.

*/
export declare class WorkboxEvent {
type: string;
target: WorkboxEventTarget;
constructor(type: string, props: WorkboxEventProps);
export declare class WorkboxEvent<K extends keyof WorkboxEventMap> {
type: K;
target?: WorkboxEventTarget;
sw: ServiceWorker;
originalEvent?: Event;
constructor(type: K, props: Omit<WorkboxEventMap[K], 'target' | 'type'>);
}
export interface WorkboxMessageEvent extends WorkboxEvent<'message'> {
originalEvent: Event;
data: any;
}
export interface WorkboxLifecycleEvent extends WorkboxEvent<keyof WorkboxLifecycleEventMap> {
isUpdate?: boolean;
}
export interface WorkboxLifecycleWaitingEvent extends WorkboxLifecycleEvent {
wasWaitingBeforeRegister?: boolean;
}
export interface WorkboxLifecycleEventMap {
'installing': WorkboxLifecycleEvent;
'installed': WorkboxLifecycleEvent;
'waiting': WorkboxLifecycleWaitingEvent;
'activating': WorkboxLifecycleEvent;
'activated': WorkboxLifecycleEvent;
'controlling': WorkboxLifecycleEvent;
'externalinstalling': WorkboxLifecycleEvent;
'externalinstalled': WorkboxLifecycleEvent;
'externalwaiting': WorkboxLifecycleWaitingEvent;
'externalactivating': WorkboxLifecycleEvent;
'externalactivated': WorkboxLifecycleEvent;
}
export interface WorkboxEventMap extends WorkboxLifecycleEventMap {
'message': WorkboxMessageEvent;
}

@@ -1,4 +0,3 @@

import { WorkboxEvent } from './WorkboxEvent.js';
import '../_version.js';
export declare type ListenerCallback = (event: WorkboxEvent) => void;
import { WorkboxEvent, WorkboxEventMap } from './WorkboxEvent.js';
export declare type ListenerCallback = (event: WorkboxEvent<any>) => any;
/**

@@ -17,3 +16,3 @@ * A minimal `EventTarget` shim.

*/
addEventListener(type: string, listener: ListenerCallback): void;
addEventListener<K extends keyof WorkboxEventMap>(type: K, listener: (event: WorkboxEventMap[K]) => any): void;
/**

@@ -24,3 +23,3 @@ * @param {string} type

*/
removeEventListener(type: string, listener: ListenerCallback): void;
removeEventListener<K extends keyof WorkboxEventMap>(type: K, listener: (event: WorkboxEventMap[K]) => any): void;
/**

@@ -30,3 +29,3 @@ * @param {Object} event

*/
dispatchEvent(event: WorkboxEvent): void;
dispatchEvent(event: WorkboxEvent<any>): void;
/**

@@ -33,0 +32,0 @@ * Returns a Set of listeners associated with the passed event type.

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

*/
import '../_version.js';
/**

@@ -18,3 +17,3 @@ * A minimal `EventTarget` shim.

constructor() {
this._eventListenerRegistry = {};
this._eventListenerRegistry = new Map();
}

@@ -27,3 +26,4 @@ /**

addEventListener(type, listener) {
this._getEventListenersByType(type).add(listener);
const foo = this._getEventListenersByType(type);
foo.add(listener);
}

@@ -58,5 +58,7 @@ /**

_getEventListenersByType(type) {
return this._eventListenerRegistry[type] =
(this._eventListenerRegistry[type] || new Set());
if (!this._eventListenerRegistry.has(type)) {
this._eventListenerRegistry.set(type, new Set());
}
return this._eventListenerRegistry.get(type);
}
}

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

/**
* Checks for updates of the registered service worker.
*/
update(): Promise<void>;
/**
* Resolves to the service worker registered by this instance as soon as it

@@ -115,3 +119,3 @@ * is active. If a service worker was already controlling at registration

* Checks for a service worker already controlling the page and returns
* it if its script URL matchs.
* it if its script URL matches.
*

@@ -121,3 +125,3 @@ * @private

*/
_getControllingSWIfCompatible(): ServiceWorker | undefined;
private _getControllingSWIfCompatible;
/**

@@ -129,3 +133,3 @@ * Registers a service worker for this instances script URL and register

*/
_registerScript(): Promise<ServiceWorkerRegistration>;
private _registerScript;
/**

@@ -137,7 +141,7 @@ * Sends a message to the passed service worker that the window is ready.

*/
_reportWindowReady(sw: ServiceWorker): void;
private _reportWindowReady;
/**
* @private
*/
_onUpdateFound: () => void;
private _onUpdateFound;
/**

@@ -147,3 +151,3 @@ * @private

*/
_onStateChange: (originalEvent: Event) => void;
private _onStateChange;
/**

@@ -153,3 +157,3 @@ * @private

*/
_onControllerChange: (originalEvent: Event) => void;
private _onControllerChange;
/**

@@ -159,3 +163,3 @@ * @private

*/
_onMessage: (originalEvent: MessageEvent) => void;
private _onMessage;
}

@@ -207,3 +211,6 @@ /**

* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The native `controllerchange` event
* @property {Event|undefined} originalEvent The original
* [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event, or `undefined` in the case where the service worker was waiting
* to before `.register()` was called.
* @property {boolean|undefined} isUpdate True if a service worker was already

@@ -289,3 +296,3 @@ * controlling when this `Workbox` instance called `register()`.

* @property {ServiceWorker} sw The service worker instance.
* @property {Event|undefined} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.

@@ -292,0 +299,0 @@ * @property {string} type `externalwaiting`.

@@ -134,3 +134,6 @@ /*

const eventPrefix = isExternal ? 'external' : '';
const eventProps = { sw, originalEvent };
const eventProps = {
sw,
originalEvent
};
if (!isExternal && this._isUpdate) {

@@ -229,5 +232,9 @@ eventProps.isUpdate = true;

*/
this._onMessage = (originalEvent) => {
this._onMessage = async (originalEvent) => {
const { data } = originalEvent;
this.dispatchEvent(new WorkboxEvent('message', { data, originalEvent }));
this.dispatchEvent(new WorkboxEvent('message', {
data,
sw: await this.getSW(),
originalEvent,
}));
};

@@ -336,2 +343,16 @@ this._scriptURL = scriptURL;

/**
* Checks for updates of the registered service worker.
*/
async update() {
if (!this._registration) {
if (process.env.NODE_ENV !== 'production') {
logger.error('Cannot update a Workbox instance without ' +
'being registered. Register the Workbox instance first.');
}
return;
}
// Try to update registration
await this._registration.update();
}
/**
* Resolves to the service worker registered by this instance as soon as it

@@ -402,3 +423,3 @@ * is active. If a service worker was already controlling at registration

* Checks for a service worker already controlling the page and returns
* it if its script URL matchs.
* it if its script URL matches.
*

@@ -500,3 +521,6 @@ * @private

* @property {ServiceWorker} sw The service worker instance.
* @property {Event} originalEvent The native `controllerchange` event
* @property {Event|undefined} originalEvent The original
* [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event, or `undefined` in the case where the service worker was waiting
* to before `.register()` was called.
* @property {boolean|undefined} isUpdate True if a service worker was already

@@ -582,3 +606,3 @@ * controlling when this `Workbox` instance called `register()`.

* @property {ServiceWorker} sw The service worker instance.
* @property {Event|undefined} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* @property {Event} originalEvent The original [`statechange`]{@link https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/onstatechange}
* event.

@@ -585,0 +609,0 @@ * @property {string} type `externalwaiting`.

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc