workbox-window
Advanced tools
Comparing version 6.3.0 to 6.4.0
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:window:6.2.4'] && _(); | ||
self['workbox:window:6.3.0'] && _(); | ||
} | ||
catch (e) { } |
@@ -8,3 +8,3 @@ (function (global, factory) { | ||
try { | ||
self['workbox:window:6.2.4'] && _(); | ||
self['workbox:window:6.3.0'] && _(); | ||
} catch (e) {} | ||
@@ -113,3 +113,3 @@ | ||
try { | ||
self['workbox:core:6.2.4'] && _(); | ||
self['workbox:core:6.3.0'] && _(); | ||
} catch (e) {} | ||
@@ -183,3 +183,4 @@ | ||
groupCollapsed: "#3498db", | ||
groupEnd: null | ||
groupEnd: null // No colored prefix on groupEnd | ||
}; | ||
@@ -186,0 +187,0 @@ |
@@ -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:6.2.4"]&&_()}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:6.2.4"]&&_()}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(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:6.3.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:6.3.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})})); | ||
//# sourceMappingURL=workbox-window.prod.umd.js.map |
@@ -7,3 +7,3 @@ import { messageSW } from './messageSW.js'; | ||
*/ | ||
export { messageSW, Workbox, }; | ||
export { messageSW, Workbox }; | ||
export * from './utils/WorkboxEvent.js'; |
@@ -14,4 +14,4 @@ /* | ||
*/ | ||
export { messageSW, Workbox, }; | ||
export { messageSW, Workbox }; | ||
// See https://github.com/GoogleChrome/workbox/issues/2770 | ||
export * from './utils/WorkboxEvent.js'; |
{ | ||
"name": "workbox-window", | ||
"version": "6.3.0", | ||
"version": "6.4.0", | ||
"license": "MIT", | ||
@@ -28,5 +28,5 @@ "author": "Google's Web DevRel Team", | ||
"@types/trusted-types": "^2.0.2", | ||
"workbox-core": "6.3.0" | ||
"workbox-core": "6.4.0" | ||
}, | ||
"gitHead": "03055e64014a46f6cc977a3a50ad814c6409d36a" | ||
"gitHead": "cdad230c678a3626c217615d5792eb0f1c77194c" | ||
} |
// @ts-ignore | ||
try{self['workbox:window:6.3.0']&&_()}catch(e){} | ||
try{self['workbox:window:6.4.0']&&_()}catch(e){} |
@@ -17,8 +17,5 @@ /* | ||
*/ | ||
export { | ||
messageSW, | ||
Workbox, | ||
}; | ||
export {messageSW, Workbox}; | ||
// See https://github.com/GoogleChrome/workbox/issues/2770 | ||
export * from './utils/WorkboxEvent.js'; |
@@ -11,3 +11,2 @@ /* | ||
/** | ||
@@ -39,2 +38,2 @@ * Sends a data object to a service worker via `postMessage` and resolves with | ||
export {messageSW} | ||
export {messageSW}; |
@@ -11,3 +11,2 @@ /* | ||
/** | ||
@@ -14,0 +13,0 @@ * Returns true if two URLs have the same `.href` property. The URLS can be |
@@ -12,3 +12,2 @@ /* | ||
/** | ||
@@ -26,3 +25,6 @@ * A minimal `Event` subclass shim. | ||
constructor(public type: K, props: Omit<WorkboxEventMap[K], 'target' | 'type'>) { | ||
constructor( | ||
public type: K, | ||
props: Omit<WorkboxEventMap[K], 'target' | 'type'>, | ||
) { | ||
Object.assign(this, props); | ||
@@ -38,3 +40,4 @@ } | ||
export interface WorkboxLifecycleEvent extends WorkboxEvent<keyof WorkboxLifecycleEventMap> { | ||
export interface WorkboxLifecycleEvent | ||
extends WorkboxEvent<keyof WorkboxLifecycleEventMap> { | ||
isUpdate?: boolean; | ||
@@ -48,13 +51,13 @@ } | ||
export interface WorkboxLifecycleEventMap { | ||
'installing': WorkboxLifecycleEvent; | ||
'installed': WorkboxLifecycleEvent; | ||
'waiting': WorkboxLifecycleWaitingEvent; | ||
'activating': WorkboxLifecycleEvent; | ||
'activated': WorkboxLifecycleEvent; | ||
'controlling': WorkboxLifecycleEvent; | ||
'redundant': WorkboxLifecycleEvent; | ||
installing: WorkboxLifecycleEvent; | ||
installed: WorkboxLifecycleEvent; | ||
waiting: WorkboxLifecycleWaitingEvent; | ||
activating: WorkboxLifecycleEvent; | ||
activated: WorkboxLifecycleEvent; | ||
controlling: WorkboxLifecycleEvent; | ||
redundant: WorkboxLifecycleEvent; | ||
} | ||
export interface WorkboxEventMap extends WorkboxLifecycleEventMap { | ||
'message': WorkboxMessageEvent; | ||
message: WorkboxMessageEvent; | ||
} |
@@ -11,3 +11,2 @@ /* | ||
export type ListenerCallback = (event: WorkboxEvent<any>) => any; | ||
@@ -22,3 +21,6 @@ | ||
export class WorkboxEventTarget { | ||
private readonly _eventListenerRegistry: Map<keyof WorkboxEventMap, Set<ListenerCallback>> = new Map(); | ||
private readonly _eventListenerRegistry: Map< | ||
keyof WorkboxEventMap, | ||
Set<ListenerCallback> | ||
> = new Map(); | ||
@@ -30,4 +32,7 @@ /** | ||
*/ | ||
addEventListener<K extends keyof WorkboxEventMap>(type: K, listener: (event: WorkboxEventMap[K]) => any): void { | ||
const foo = this._getEventListenersByType(type) | ||
addEventListener<K extends keyof WorkboxEventMap>( | ||
type: K, | ||
listener: (event: WorkboxEventMap[K]) => any, | ||
): void { | ||
const foo = this._getEventListenersByType(type); | ||
foo.add(listener as ListenerCallback); | ||
@@ -41,3 +46,6 @@ } | ||
*/ | ||
removeEventListener<K extends keyof WorkboxEventMap>(type: K, listener: (event: WorkboxEventMap[K]) => any): void { | ||
removeEventListener<K extends keyof WorkboxEventMap>( | ||
type: K, | ||
listener: (event: WorkboxEventMap[K]) => any, | ||
): void { | ||
this._getEventListenersByType(type).delete(listener as ListenerCallback); | ||
@@ -53,3 +61,3 @@ } | ||
const listeners = this._getEventListenersByType(event.type) | ||
const listeners = this._getEventListenersByType(event.type); | ||
for (const listener of listeners) { | ||
@@ -56,0 +64,0 @@ listener(event); |
@@ -21,3 +21,2 @@ /* | ||
// The time a SW must be in the waiting phase before we can conclude | ||
@@ -56,3 +55,4 @@ // `skipWaiting()` wasn't called. This 200 amount wasn't scientifically | ||
private readonly _activeDeferred: Deferred<ServiceWorker> = new Deferred(); | ||
private readonly _controllingDeferred: Deferred<ServiceWorker> = new Deferred(); | ||
private readonly _controllingDeferred: Deferred<ServiceWorker> = | ||
new Deferred(); | ||
@@ -103,7 +103,11 @@ private _registrationTime: DOMHighResTimeStamp = 0; | ||
*/ | ||
async register({immediate = false} = {}): Promise<ServiceWorkerRegistration | undefined> { | ||
async register({immediate = false} = {}): Promise< | ||
ServiceWorkerRegistration | undefined | ||
> { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (this._registrationTime) { | ||
logger.error('Cannot re-register a Workbox instance after it has ' + | ||
'been registered. Create a new instance instead.'); | ||
logger.error( | ||
'Cannot re-register a Workbox instance after it has ' + | ||
'been registered. Create a new instance instead.', | ||
); | ||
return; | ||
@@ -136,3 +140,6 @@ } | ||
this._compatibleControllingSW.addEventListener( | ||
'statechange', this._onStateChange, {once: true}); | ||
'statechange', | ||
this._onStateChange, | ||
{once: true}, | ||
); | ||
} | ||
@@ -146,4 +153,6 @@ | ||
const waitingSW = this._registration.waiting; | ||
if (waitingSW && | ||
urlsMatch(waitingSW.scriptURL, this._scriptURL.toString())) { | ||
if ( | ||
waitingSW && | ||
urlsMatch(waitingSW.scriptURL, this._scriptURL.toString()) | ||
) { | ||
// Store the waiting SW as the "own" Sw, even if it means overwriting | ||
@@ -155,12 +164,18 @@ // a compatible controller. | ||
// listener after awaiting `register()` will get this event. | ||
dontWaitFor(Promise.resolve().then(() => { | ||
this.dispatchEvent(new WorkboxEvent('waiting', { | ||
sw: waitingSW, | ||
wasWaitingBeforeRegister: true, | ||
})); | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.warn('A service worker was already waiting to activate ' + | ||
'before this script was registered...'); | ||
} | ||
})); | ||
dontWaitFor( | ||
Promise.resolve().then(() => { | ||
this.dispatchEvent( | ||
new WorkboxEvent('waiting', { | ||
sw: waitingSW, | ||
wasWaitingBeforeRegister: true, | ||
}), | ||
); | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.warn( | ||
'A service worker was already waiting to activate ' + | ||
'before this script was registered...', | ||
); | ||
} | ||
}), | ||
); | ||
} | ||
@@ -175,13 +190,19 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log('Successfully registered service worker.', | ||
this._scriptURL.toString()); | ||
logger.log( | ||
'Successfully registered service worker.', | ||
this._scriptURL.toString(), | ||
); | ||
if (navigator.serviceWorker.controller) { | ||
if (this._compatibleControllingSW) { | ||
logger.debug('A service worker with the same script URL ' + | ||
'is already controlling this page.'); | ||
logger.debug( | ||
'A service worker with the same script URL ' + | ||
'is already controlling this page.', | ||
); | ||
} else { | ||
logger.debug('A service worker with a different script URL is ' + | ||
logger.debug( | ||
'A service worker with a different script URL is ' + | ||
'currently controlling the page. The browser is now fetching ' + | ||
'the new script now...'); | ||
'the new script now...', | ||
); | ||
} | ||
@@ -193,3 +214,3 @@ } | ||
this._registerOptions.scope || this._scriptURL.toString(), | ||
document.baseURI | ||
document.baseURI, | ||
); | ||
@@ -200,4 +221,6 @@ const scopeURLBasePath = new URL('./', scopeURL.href).pathname; | ||
if (currentPageIsOutOfScope()) { | ||
logger.warn('The current page is not in scope for the registered ' + | ||
'service worker. Was this a mistake?'); | ||
logger.warn( | ||
'The current page is not in scope for the registered ' + | ||
'service worker. Was this a mistake?', | ||
); | ||
} | ||
@@ -208,3 +231,5 @@ } | ||
navigator.serviceWorker.addEventListener( | ||
'controllerchange', this._onControllerChange); | ||
'controllerchange', | ||
this._onControllerChange, | ||
); | ||
@@ -220,4 +245,6 @@ return this._registration; | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.error('Cannot update a Workbox instance without ' + | ||
'being registered. Register the Workbox instance first.'); | ||
logger.error( | ||
'Cannot update a Workbox instance without ' + | ||
'being registered. Register the Workbox instance first.', | ||
); | ||
} | ||
@@ -278,5 +305,5 @@ return; | ||
// return the correct (new) service worker if an update is found. | ||
return this._sw !== undefined ? | ||
Promise.resolve(this._sw) : | ||
this._swDeferred.promise; | ||
return this._sw !== undefined | ||
? Promise.resolve(this._sw) | ||
: this._swDeferred.promise; | ||
} | ||
@@ -326,4 +353,6 @@ | ||
const controller = navigator.serviceWorker.controller; | ||
if (controller && | ||
urlsMatch(controller.scriptURL, this._scriptURL.toString())) { | ||
if ( | ||
controller && | ||
urlsMatch(controller.scriptURL, this._scriptURL.toString()) | ||
) { | ||
return controller; | ||
@@ -347,3 +376,5 @@ } else { | ||
const reg = await navigator.serviceWorker.register( | ||
this._scriptURL as string, this._registerOptions); | ||
this._scriptURL as string, | ||
this._registerOptions, | ||
); | ||
@@ -386,19 +417,19 @@ // Keep track of when registration happened, so it can be used in the | ||
const 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 | ||
// 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: | ||
// 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 | ||
// triggered by this instance. | ||
true : false; | ||
// 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 | ||
// 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: | ||
// 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 | ||
// triggered by this instance. | ||
true | ||
: false; | ||
@@ -433,3 +464,3 @@ if (updateLikelyTriggeredExternally) { | ||
installingSW.addEventListener('statechange', this._onStateChange); | ||
} | ||
}; | ||
@@ -455,3 +486,3 @@ /** | ||
isExternal, | ||
originalEvent | ||
originalEvent, | ||
}; | ||
@@ -462,3 +493,5 @@ if (!isExternal && this._isUpdate) { | ||
this.dispatchEvent(new WorkboxEvent(state as keyof WorkboxLifecycleEventMap, eventProps)); | ||
this.dispatchEvent( | ||
new WorkboxEvent(state as keyof WorkboxLifecycleEventMap, eventProps), | ||
); | ||
@@ -481,7 +514,11 @@ if (state === 'installed') { | ||
if (isExternal) { | ||
logger.warn('An external service worker has installed but is ' + | ||
'waiting for this client to close before activating...'); | ||
logger.warn( | ||
'An external service worker has installed but is ' + | ||
'waiting for this client to close before activating...', | ||
); | ||
} else { | ||
logger.warn('The service worker has installed but is waiting ' + | ||
'for existing clients to close before activating...'); | ||
logger.warn( | ||
'The service worker has installed but is waiting ' + | ||
'for existing clients to close before activating...', | ||
); | ||
} | ||
@@ -502,4 +539,6 @@ } | ||
if (isExternal) { | ||
logger.warn('An external service worker has installed. ' + | ||
'You may want to suggest users reload this page.'); | ||
logger.warn( | ||
'An external service worker has installed. ' + | ||
'You may want to suggest users reload this page.', | ||
); | ||
} else { | ||
@@ -515,5 +554,7 @@ logger.log('Registered service worker installed.'); | ||
if (sw !== navigator.serviceWorker.controller) { | ||
logger.warn('The registered service worker is active but ' + | ||
logger.warn( | ||
'The registered service worker is active but ' + | ||
'not yet controlling the page. Reload or run ' + | ||
'`clients.claim()` in the service worker.'); | ||
'`clients.claim()` in the service worker.', | ||
); | ||
} | ||
@@ -531,3 +572,3 @@ } | ||
} | ||
} | ||
}; | ||
@@ -546,8 +587,10 @@ /** | ||
// See https://github.com/GoogleChrome/workbox/issues/2786 | ||
this.dispatchEvent(new WorkboxEvent('controlling', { | ||
isExternal, | ||
originalEvent, | ||
sw, | ||
isUpdate: this._isUpdate, | ||
})); | ||
this.dispatchEvent( | ||
new WorkboxEvent('controlling', { | ||
isExternal, | ||
originalEvent, | ||
sw, | ||
isUpdate: this._isUpdate, | ||
}), | ||
); | ||
@@ -558,5 +601,5 @@ if (!isExternal) { | ||
} | ||
this._controllingDeferred.resolve(sw!); | ||
this._controllingDeferred.resolve(sw); | ||
} | ||
} | ||
}; | ||
@@ -583,12 +626,14 @@ /** | ||
if (this._ownSWs.has(source as ServiceWorker)) { | ||
this.dispatchEvent(new WorkboxEvent('message', { | ||
// Can't change type 'any' of data. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
data, | ||
originalEvent, | ||
ports, | ||
sw: source as ServiceWorker, | ||
})); | ||
this.dispatchEvent( | ||
new WorkboxEvent('message', { | ||
// Can't change type 'any' of data. | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
data, | ||
originalEvent, | ||
ports, | ||
sw: source as ServiceWorker, | ||
}), | ||
); | ||
} | ||
} | ||
}; | ||
} | ||
@@ -722,2 +767,1 @@ | ||
*/ | ||
@@ -9,8 +9,8 @@ { | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"include": ["src/**/*.ts"], | ||
"references": [ | ||
{ "path": "../workbox-core/" } | ||
{ | ||
"path": "../workbox-core/" | ||
} | ||
] | ||
} |
@@ -29,12 +29,12 @@ import { WorkboxEventTarget } from './WorkboxEventTarget.js'; | ||
export interface WorkboxLifecycleEventMap { | ||
'installing': WorkboxLifecycleEvent; | ||
'installed': WorkboxLifecycleEvent; | ||
'waiting': WorkboxLifecycleWaitingEvent; | ||
'activating': WorkboxLifecycleEvent; | ||
'activated': WorkboxLifecycleEvent; | ||
'controlling': WorkboxLifecycleEvent; | ||
'redundant': WorkboxLifecycleEvent; | ||
installing: WorkboxLifecycleEvent; | ||
installed: WorkboxLifecycleEvent; | ||
waiting: WorkboxLifecycleWaitingEvent; | ||
activating: WorkboxLifecycleEvent; | ||
activated: WorkboxLifecycleEvent; | ||
controlling: WorkboxLifecycleEvent; | ||
redundant: WorkboxLifecycleEvent; | ||
} | ||
export interface WorkboxEventMap extends WorkboxLifecycleEventMap { | ||
'message': WorkboxMessageEvent; | ||
message: WorkboxMessageEvent; | ||
} |
@@ -94,7 +94,7 @@ /* | ||
// assumed to be external. | ||
(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; | ||
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) { | ||
@@ -141,3 +141,3 @@ this._externalSW = installingSW; | ||
isExternal, | ||
originalEvent | ||
originalEvent, | ||
}; | ||
@@ -426,5 +426,5 @@ if (!isExternal && this._isUpdate) { | ||
// return the correct (new) service worker if an update is found. | ||
return this._sw !== undefined ? | ||
Promise.resolve(this._sw) : | ||
this._swDeferred.promise; | ||
return this._sw !== undefined | ||
? Promise.resolve(this._sw) | ||
: this._swDeferred.promise; | ||
} | ||
@@ -431,0 +431,0 @@ /** |
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
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 4 instances in 1 package
5
80
4809
551717
+ Addedworkbox-core@6.4.0(transitive)
- Removedworkbox-core@6.3.0(transitive)
Updatedworkbox-core@6.4.0