{“version”:3,“file”:“workbox-broadcast-update.prod.js”,“sources”:,“sourcesContent”:[“"use strict";n// @ts-ignorentry {n self && _();n}ncatch (e) { }n”,“/*n Copyright 2018 Google LLCnn Use of this source code is governed by an MIT-stylen license that can be found in the LICENSE file or atn opensource.org/licenses/MIT.n*/nimport { WorkboxError } from 'workbox-core/_private/WorkboxError.js';nimport { logger } from 'workbox-core/_private/logger.js';nimport './_version.js';n/**n * Given two `Response's`, compares several header values to see if they aren * the same or not.n *n * @param {Response} firstResponsen * @param {Response} secondResponsen * @param {Array<string>} headersToCheckn * @return {boolean}n *n * @memberof module:workbox-broadcast-updaten */nconst responsesAreSame = (firstResponse, secondResponse, headersToCheck) => {n if (process.env.NODE_ENV !== 'production') {n if (!(firstResponse instanceof Response &&n secondResponse instanceof Response)) {n throw new WorkboxError('invalid-responses-are-same-args');n }n }n const atLeastOneHeaderAvailable = headersToCheck.some((header) => {n return firstResponse.headers.has(header) &&n secondResponse.headers.has(header);n });n if (!atLeastOneHeaderAvailable) {n if (process.env.NODE_ENV !== 'production') {n logger.warn(`Unable to determine where the response has been updated ` +n `because none of the headers that would be checked are present.`);n logger.debug(`Attempting to compare the following: `, firstResponse, secondResponse, headersToCheck);n }n // Just return true, indicating the that responses are the same, since wen // can't determine otherwise.n return true;n }n return headersToCheck.every((header) => {n const headerStateComparison = firstResponse.headers.has(header) ===n secondResponse.headers.has(header);n const headerValueComparison = firstResponse.headers.get(header) ===n secondResponse.headers.get(header);n return headerStateComparison && headerValueComparison;n });n};nexport { responsesAreSame };n”,“/*n Copyright 2018 Google LLCnn Use of this source code is governed by an MIT-stylen license that can be found in the LICENSE file or atn opensource.org/licenses/MIT.n*/nimport '../_version.js';nexport const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED';nexport const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update';nexport const DEFAULT_HEADERS_TO_CHECK = [n 'content-length',n 'etag',n 'last-modified',n];n”,“/*n Copyright 2018 Google LLCnn Use of this source code is governed by an MIT-stylen license that can be found in the LICENSE file or atn opensource.org/licenses/MIT.n*/nimport { assert } from 'workbox-core/_private/assert.js';nimport { timeout } from 'workbox-core/_private/timeout.js';nimport { resultingClientExists } from 'workbox-core/_private/resultingClientExists.js';nimport { logger } from 'workbox-core/_private/logger.js';nimport { responsesAreSame } from './responsesAreSame.js';nimport { CACHE_UPDATED_MESSAGE_TYPE, CACHE_UPDATED_MESSAGE_META, DEFAULT_HEADERS_TO_CHECK } from './utils/constants.js';nimport './_version.js';n// UA-sniff Safari: stackoverflow.com/questions/7944460/detect-safari-browsern// TODO(philipwalton): remove once this Safari bug fix has been released.n// bugs.webkit.org/show_bug.cgi?id=201169nconst isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);n/**n * Generates the default payload used in update messages. By default then * payload includes the `cacheName` and `updatedURL` fields.n *n * @return Objectn * @privaten */nfunction defaultPayloadGenerator(data) {n return {n cacheName: data.cacheName,n updatedURL: data.request.url,n };n}n/**n * Uses the `postMessage()` API to inform any open windows/tabs when a cachedn * response has been updated.n *n * For efficiency's sake, the underlying response bodies are not compared;n * only specific response headers are checked.n *n * @memberof module:workbox-broadcast-updaten */nclass BroadcastCacheUpdate {n /**n * Construct a BroadcastCacheUpdate instance with a specific `channelName` ton * broadcast messages onn *n * @param {Object} optionsn * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]n * A list of headers that will be used to determine whether the responsesn * differ.n * @param {string} [options.generatePayload] A function whose return valuen * will be used as the `payload` field in any cache update messages sentn * to the window clients.n */n constructor({ headersToCheck, generatePayload, } = {}) {n this._headersToCheck = headersToCheck || DEFAULT_HEADERS_TO_CHECK;n this._generatePayload = generatePayload || defaultPayloadGenerator;n }n /**n * Compares two [Responses](developer.mozilla.org/en-US/docs/Web/API/Response)n * and sends a message (via `postMessage()`) to all window clients if then * responses differ (note: neither of the Responses can ben * {@link stackoverflow.com/questions/39109789|opaque}).n *n * The message that's posted has the following format (where `payload` cann * be customized via the `generatePayload` option the instance is createdn * with):n *n * “`n * {n * type: 'CACHE_UPDATED',n * meta: 'workbox-broadcast-update',n * payload: {n * cacheName: 'the-cache-name',n * updatedURL: 'example.com/‘n * }n * }n * “`n *n * @param {Object} optionsn * @param {Response} [options.oldResponse] Cached response to compare.n * @param {Response} options.newResponse Possibly updated response to compare.n * @param {Request} options.request The request.n * @param {string} options.cacheName Name of the cache the responses belongn * to. This is included in the broadcast message.n * @param {Event} [options.event] event An optional event that triggeredn * this possible cache update.n * @return {Promise} Resolves once the update is sent.n */n async notifyIfUpdated(options) {n if (process.env.NODE_ENV !== 'production') {n assert.isType(options.cacheName, 'string', {n moduleName: 'workbox-broadcast-update',n className: 'BroadcastCacheUpdate',n funcName: 'notifyIfUpdated',n paramName: 'cacheName',n });n assert.isInstance(options.newResponse, Response, {n moduleName: 'workbox-broadcast-update',n className: 'BroadcastCacheUpdate',n funcName: 'notifyIfUpdated',n paramName: 'newResponse',n });n assert.isInstance(options.request, Request, {n moduleName: 'workbox-broadcast-update',n className: 'BroadcastCacheUpdate',n funcName: 'notifyIfUpdated',n paramName: 'request',n });n }n // Without two responses there is nothing to compare.n if (!options.oldResponse) {n return;n }n if (!responsesAreSame(options.oldResponse, options.newResponse, this._headersToCheck)) {n if (process.env.NODE_ENV !== 'production') {n logger.log(`Newer response found (and cached) for:`, options.request.url);n }n const messageData = {n type: CACHE_UPDATED_MESSAGE_TYPE,n meta: CACHE_UPDATED_MESSAGE_META,n payload: this._generatePayload(options),n };n // For navigation requests, wait until the new window client existsn // before sending the messagen if (options.request.mode === 'navigate') {n let resultingClientId;n if (options.event instanceof FetchEvent) {n resultingClientId = options.event.resultingClientId;n }n const resultingWin = await resultingClientExists(resultingClientId);n // Safari does not currently implement postMessage buffering andn // there's no good way to feature detect that, so to increase then // chances of the message being delivered in Safari, we add a timeout.n // We also do this if `resultingClientExists()` didn't return a client,n // which means it timed out, so it's worth waiting a bit longer.n if (!resultingWin || isSafari) {n // 3500 is chosen because (according to CrUX data) 80% of mobilen // websites hit the DOMContentLoaded event in less than 3.5 seconds.n // And presumably sites implementing service worker are on then // higher end of the performance spectrum.n await timeout(3500);n }n }n const windows = await self.clients.matchAll({ type: 'window' });n for (const win of windows) {n win.postMessage(messageData);n }n }n }n}nexport { BroadcastCacheUpdate };n”,“/*n Copyright 2018 Google LLCnn Use of this source code is governed by an MIT-stylen license that can be found in the LICENSE file or atn opensource.org/licenses/MIT.n*/nimport { dontWaitFor } from 'workbox-core/_private/dontWaitFor.js';nimport { BroadcastCacheUpdate } from './BroadcastCacheUpdate.js';nimport './_version.js';n/**n * This plugin will automatically broadcast a message whenever a cached responsen * is updated.n *n * @memberof module:workbox-broadcast-updaten */nclass BroadcastUpdatePlugin {n /**n * Construct a BroadcastCacheUpdate instance with the passed options andn * calls its [`notifyIfUpdated()`]{@link module:workbox-broadcast-update.BroadcastCacheUpdate~notifyIfUpdated}n * method whenever the plugin's `cacheDidUpdate` callback is invoked.n *n * @param {Object} optionsn * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]n * A list of headers that will be used to determine whether the responsesn * differ.n * @param {string} [options.generatePayload] A function whose return valuen * will be used as the `payload` field in any cache update messages sentn * to the window clients.n */n constructor(options) {n /**n * A "lifecycle" callback that will be triggered automatically by then * `workbox-sw` and `workbox-runtime-caching` handlers when an entry isn * added to a cache.n *n * @privaten * @param {Object} options The input object to this function.n * @param {string} options.cacheName Name of the cache being updated.n * @param {Response} [options.oldResponse] The previous cached value, if any.n * @param {Response} options.newResponse The new value in the cache.n * @param {Request} options.request The request that triggered the update.n * @param {Request} [options.event] The event that triggered the update.n */n this.cacheDidUpdate = async (options) => {n dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));n };n this._broadcastUpdate = new BroadcastCacheUpdate(options);n }n}nexport { BroadcastUpdatePlugin };n”],“names”:,“mappings”:“0FAEA,IACIA,KAAK,mCAAqCC,IAE9C,MAAOC,UCgBDC,EAAmB,CAACC,EAAeC,EAAgBC,KAOnBA,EAAeC,KAAMC,GAC5CJ,EAAcK,QAAQC,IAAIF,IAC7BH,EAAeI,QAAQC,IAAIF,KAY5BF,EAAeK,MAAOH,UACnBI,EAAwBR,EAAcK,QAAQC,IAAIF,KACpDH,EAAeI,QAAQC,IAAIF,GACzBK,EAAwBT,EAAcK,QAAQK,IAAIN,KACpDH,EAAeI,QAAQK,IAAIN,UACxBI,GAAyBC,ICrC3BE,EAA2B,CACpC,iBACA,OACA,iBCIEC,EAAW,iCAAiCC,KAAKC,UAAUC,WAQjE,SAASC,EAAwBC,SACtB,CACHC,UAAWD,EAAKC,UAChBC,WAAYF,EAAKG,QAAQC,KAYjC,MAAMC,EAaFC,aAAYrB,eAAEA,EAAFsB,gBAAkBA,GAAqB,SAC1CC,EAAkBvB,GAAkBS,OACpCe,EAAmBF,GAAmBR,wBAiCzBW,MAsBbA,EAAQC,cAGR7B,EAAiB4B,EAAQC,YAAaD,EAAQE,YAAaC,KAAKL,GAAkB,OAI7EM,EAAc,CAChBC,KD9G0B,gBC+G1BC,KD9G0B,2BC+G1BC,QAASJ,KAAKJ,EAAiBC,OAIN,aAAzBA,EAAQP,QAAQe,KAAqB,KACjCC,EACAT,EAAQU,iBAAiBC,aACzBF,EAAoBT,EAAQU,MAAMD,yBAEXG,wBAAsBH,KAM5BxB,SAKX4B,UAAQ,YAGhBC,QAAgB7C,KAAK8C,QAAQC,SAAS,CAAEX,KAAM,eAC/C,MAAMY,KAAOH,EACdG,EAAIC,YAAYd,6DCjIhC,MAcIR,YAAYI,QAcHmB,eAAiBC,MAAAA,IAClBC,cAAYlB,KAAKmB,EAAiBC,gBAAgBvB,UAEjDsB,EAAmB,IAAI3B,EAAqBK”}