workbox-broadcast-update
Advanced tools
Comparing version 6.2.4 to 6.3.0
@@ -6,2 +6,3 @@ import { CacheDidUpdateCallbackParam } from 'workbox-core/types.js'; | ||
generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>; | ||
notifyAllClients?: boolean; | ||
} | ||
@@ -20,2 +21,3 @@ /** | ||
private readonly _generatePayload; | ||
private readonly _notifyAllClients; | ||
/** | ||
@@ -32,4 +34,7 @@ * Construct a BroadcastCacheUpdate instance with a specific `channelName` to | ||
* to the window clients. | ||
* @param {boolean} [options.notifyAllClients=true] If true (the default) then | ||
* all open clients will receive a message. If false, then only the client | ||
* that make the original request will be notified of the update. | ||
*/ | ||
constructor({ headersToCheck, generatePayload, }?: BroadcastCacheUpdateOptions); | ||
constructor({ generatePayload, headersToCheck, notifyAllClients, }?: BroadcastCacheUpdateOptions); | ||
/** | ||
@@ -36,0 +41,0 @@ * Compares two [Responses](https://developer.mozilla.org/en-US/docs/Web/API/Response) |
@@ -13,3 +13,3 @@ /* | ||
import { responsesAreSame } from './responsesAreSame.js'; | ||
import { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK } from './utils/constants.js'; | ||
import { CACHE_UPDATED_MESSAGE_META, CACHE_UPDATED_MESSAGE_TYPE, DEFAULT_HEADERS_TO_CHECK, NOTIFY_ALL_CLIENTS, } from './utils/constants.js'; | ||
import './_version.js'; | ||
@@ -54,6 +54,10 @@ // UA-sniff Safari: https://stackoverflow.com/questions/7944460/detect-safari-browser | ||
* to the window clients. | ||
* @param {boolean} [options.notifyAllClients=true] If true (the default) then | ||
* all open clients will receive a message. If false, then only the client | ||
* that make the original request will be notified of the update. | ||
*/ | ||
constructor({ headersToCheck, generatePayload, } = {}) { | ||
constructor({ generatePayload, headersToCheck, notifyAllClients, } = {}) { | ||
this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK; | ||
this._generatePayload = generatePayload || defaultPayloadGenerator; | ||
this._notifyAllClients = notifyAllClients !== null && notifyAllClients !== void 0 ? notifyAllClients : NOTIFY_ALL_CLIENTS; | ||
} | ||
@@ -146,6 +150,15 @@ /** | ||
} | ||
const windows = await self.clients.matchAll({ type: 'window' }); | ||
for (const win of windows) { | ||
win.postMessage(messageData); | ||
if (this._notifyAllClients) { | ||
const windows = await self.clients.matchAll({ type: 'window' }); | ||
for (const win of windows) { | ||
win.postMessage(messageData); | ||
} | ||
} | ||
else { | ||
// See https://github.com/GoogleChrome/workbox/issues/2895 | ||
if (options.event instanceof FetchEvent) { | ||
const client = await self.clients.get(options.event.clientId); | ||
client === null || client === void 0 ? void 0 : client.postMessage(messageData); | ||
} | ||
} | ||
} | ||
@@ -152,0 +165,0 @@ } |
@@ -66,2 +66,3 @@ this.workbox = this.workbox || {}; | ||
const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update'; | ||
const NOTIFY_ALL_CLIENTS = true; | ||
const DEFAULT_HEADERS_TO_CHECK = ['content-length', 'etag', 'last-modified']; | ||
@@ -117,9 +118,14 @@ | ||
* to the window clients. | ||
* @param {boolean} [options.notifyAllClients=true] If true (the default) then | ||
* all open clients will receive a message. If false, then only the client | ||
* that make the original request will be notified of the update. | ||
*/ | ||
constructor({ | ||
generatePayload, | ||
headersToCheck, | ||
generatePayload | ||
notifyAllClients | ||
} = {}) { | ||
this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK; | ||
this._generatePayload = generatePayload || defaultPayloadGenerator; | ||
this._notifyAllClients = notifyAllClients !== null && notifyAllClients !== void 0 ? notifyAllClients : NOTIFY_ALL_CLIENTS; | ||
} | ||
@@ -220,8 +226,16 @@ /** | ||
const windows = await self.clients.matchAll({ | ||
type: 'window' | ||
}); | ||
if (this._notifyAllClients) { | ||
const windows = await self.clients.matchAll({ | ||
type: 'window' | ||
}); | ||
for (const win of windows) { | ||
win.postMessage(messageData); | ||
for (const win of windows) { | ||
win.postMessage(messageData); | ||
} | ||
} else { | ||
// See https://github.com/GoogleChrome/workbox/issues/2895 | ||
if (options.event instanceof FetchEvent) { | ||
const client = await self.clients.get(options.event.clientId); | ||
client === null || client === void 0 ? void 0 : client.postMessage(messageData); | ||
} | ||
} | ||
@@ -228,0 +242,0 @@ } |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t,a,o,s){"use strict";try{self["workbox:broadcast-update:6.2.4"]&&_()}catch(t){}const e=(t,a,o)=>!o.some((o=>t.headers.has(o)&&a.headers.has(o)))||o.every((o=>{const s=t.headers.has(o)===a.headers.has(o),e=t.headers.get(o)===a.headers.get(o);return s&&e})),n=["content-length","etag","last-modified"],i=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function c(t){return{cacheName:t.cacheName,updatedURL:t.request.url}}class r{constructor({headersToCheck:t,generatePayload:a}={}){this.C=t||n,this.U=a||c}async notifyIfUpdated(t){if(t.oldResponse&&!e(t.oldResponse,t.newResponse,this.C)){const s={type:"CACHE_UPDATED",meta:"workbox-broadcast-update",payload:this.U(t)};if("navigate"===t.request.mode){let s;t.event instanceof FetchEvent&&(s=t.event.resultingClientId);await o.resultingClientExists(s)&&!i||await a.timeout(3500)}const e=await self.clients.matchAll({type:"window"});for(const t of e)t.postMessage(s)}}}return t.BroadcastCacheUpdate=r,t.BroadcastUpdatePlugin=class{constructor(t){this.cacheDidUpdate=async t=>{s.dontWaitFor(this.A.notifyIfUpdated(t))},this.A=new r(t)}},t.responsesAreSame=e,t}({},workbox.core._private,workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.broadcastUpdate=function(t,s,a,e){"use strict";try{self["workbox:broadcast-update:6.2.4"]&&_()}catch(t){}const n=(t,s,a)=>!a.some((a=>t.headers.has(a)&&s.headers.has(a)))||a.every((a=>{const e=t.headers.has(a)===s.headers.has(a),n=t.headers.get(a)===s.headers.get(a);return e&&n})),i=["content-length","etag","last-modified"],o=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);function c(t){return{cacheName:t.cacheName,updatedURL:t.request.url}}class r{constructor({generatePayload:t,headersToCheck:s,notifyAllClients:a}={}){this.C=s||i,this.A=t||c,this.U=null==a||a}async notifyIfUpdated(t){if(t.oldResponse&&!n(t.oldResponse,t.newResponse,this.C)){const e={type:"CACHE_UPDATED",meta:"workbox-broadcast-update",payload:this.A(t)};if("navigate"===t.request.mode){let e;t.event instanceof FetchEvent&&(e=t.event.resultingClientId);await a.resultingClientExists(e)&&!o||await s.timeout(3500)}if(this.U){const t=await self.clients.matchAll({type:"window"});for(const s of t)s.postMessage(e)}else if(t.event instanceof FetchEvent){const s=await self.clients.get(t.event.clientId);null==s||s.postMessage(e)}}}}return t.BroadcastCacheUpdate=r,t.BroadcastUpdatePlugin=class{constructor(t){this.cacheDidUpdate=async t=>{e.dontWaitFor(this.F.notifyIfUpdated(t))},this.F=new r(t)}},t.responsesAreSame=n,t}({},workbox.core._private,workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-broadcast-update.prod.js.map |
{ | ||
"name": "workbox-broadcast-update", | ||
"version": "6.2.4", | ||
"version": "6.3.0", | ||
"license": "MIT", | ||
@@ -25,5 +25,5 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "6.2.4" | ||
"workbox-core": "6.3.0" | ||
}, | ||
"gitHead": "0074b20b17b8047a6d9ecd7d9082778a61ad0468" | ||
"gitHead": "03055e64014a46f6cc977a3a50ad814c6409d36a" | ||
} |
// @ts-ignore | ||
try{self['workbox:broadcast-update:6.2.4']&&_()}catch(e){} | ||
try{self['workbox:broadcast-update:6.3.0']&&_()}catch(e){} |
@@ -15,7 +15,11 @@ /* | ||
import {responsesAreSame} from './responsesAreSame.js'; | ||
import {CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK} from './utils/constants.js'; | ||
import { | ||
CACHE_UPDATED_MESSAGE_META, | ||
CACHE_UPDATED_MESSAGE_TYPE, | ||
DEFAULT_HEADERS_TO_CHECK, | ||
NOTIFY_ALL_CLIENTS, | ||
} from './utils/constants.js'; | ||
import './_version.js'; | ||
// UA-sniff Safari: https://stackoverflow.com/questions/7944460/detect-safari-browser | ||
@@ -26,3 +30,2 @@ // TODO(philipwalton): remove once this Safari bug fix has been released. | ||
// Give TypeScript the correct global. | ||
@@ -33,3 +36,6 @@ declare let self: ServiceWorkerGlobalScope; | ||
headersToCheck?: string[]; | ||
generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>; | ||
generatePayload?: ( | ||
options: CacheDidUpdateCallbackParam, | ||
) => Record<string, any>; | ||
notifyAllClients?: boolean; | ||
} | ||
@@ -44,3 +50,5 @@ | ||
*/ | ||
function defaultPayloadGenerator(data: CacheDidUpdateCallbackParam): Record<string, any> { | ||
function defaultPayloadGenerator( | ||
data: CacheDidUpdateCallbackParam, | ||
): Record<string, any> { | ||
return { | ||
@@ -63,3 +71,6 @@ cacheName: data.cacheName, | ||
private readonly _headersToCheck: string[]; | ||
private readonly _generatePayload: (options: CacheDidUpdateCallbackParam) => Record<string, any>; | ||
private readonly _generatePayload: ( | ||
options: CacheDidUpdateCallbackParam, | ||
) => Record<string, any>; | ||
private readonly _notifyAllClients: boolean; | ||
@@ -77,9 +88,14 @@ /** | ||
* to the window clients. | ||
* @param {boolean} [options.notifyAllClients=true] If true (the default) then | ||
* all open clients will receive a message. If false, then only the client | ||
* that make the original request will be notified of the update. | ||
*/ | ||
constructor({ | ||
generatePayload, | ||
headersToCheck, | ||
generatePayload, | ||
notifyAllClients, | ||
}: BroadcastCacheUpdateOptions = {}) { | ||
this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK; | ||
this._generatePayload = generatePayload || defaultPayloadGenerator; | ||
this._notifyAllClients = notifyAllClients ?? NOTIFY_ALL_CLIENTS; | ||
} | ||
@@ -145,6 +161,14 @@ | ||
if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) { | ||
if ( | ||
!responsesAreSame( | ||
options.oldResponse, | ||
options.newResponse, | ||
this._headersToCheck, | ||
) | ||
) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log( | ||
`Newer response found (and cached) for:`, options.request.url); | ||
`Newer response found (and cached) for:`, | ||
options.request.url, | ||
); | ||
} | ||
@@ -182,5 +206,13 @@ | ||
const windows = await self.clients.matchAll({type: 'window'}); | ||
for (const win of windows) { | ||
win.postMessage(messageData); | ||
if (this._notifyAllClients) { | ||
const windows = await self.clients.matchAll({type: 'window'}); | ||
for (const win of windows) { | ||
win.postMessage(messageData); | ||
} | ||
} else { | ||
// See https://github.com/GoogleChrome/workbox/issues/2895 | ||
if (options.event instanceof FetchEvent) { | ||
const client = await self.clients.get(options.event.clientId); | ||
client?.postMessage(messageData); | ||
} | ||
} | ||
@@ -187,0 +219,0 @@ } |
@@ -13,2 +13,3 @@ /* | ||
export const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update'; | ||
export const NOTIFY_ALL_CLIENTS = true; | ||
export const DEFAULT_HEADERS_TO_CHECK: string[] = [ | ||
@@ -15,0 +16,0 @@ 'content-length', |
import '../_version.js'; | ||
export declare const CACHE_UPDATED_MESSAGE_TYPE = "CACHE_UPDATED"; | ||
export declare const CACHE_UPDATED_MESSAGE_META = "workbox-broadcast-update"; | ||
export declare const NOTIFY_ALL_CLIENTS = true; | ||
export declare const DEFAULT_HEADERS_TO_CHECK: string[]; |
@@ -11,2 +11,3 @@ /* | ||
export const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update'; | ||
export const NOTIFY_ALL_CLIENTS = true; | ||
export const DEFAULT_HEADERS_TO_CHECK = [ | ||
@@ -13,0 +14,0 @@ 'content-length', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
187228
1059
+ Addedworkbox-core@6.3.0(transitive)
- Removedworkbox-core@6.2.4(transitive)
Updatedworkbox-core@6.3.0