+ 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.
+ */
+ const messages = {
+ 'invalid-value': ({
+ paramName,
+ validValueDescription,
+ value
+ }) => {
+ if (!paramName || !validValueDescription) {
+ throw new Error(`Unexpected input to 'invalid-value' error.`);
+ }
+ return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
+ },
+ 'not-an-array': ({
+ moduleName,
+ className,
+ funcName,
+ paramName
+ }) => {
+ if (!moduleName || !className || !funcName || !paramName) {
+ throw new Error(`Unexpected input to 'not-an-array' error.`);
+ }
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
+ },
+ 'incorrect-type': ({
+ expectedType,
+ paramName,
+ moduleName,
+ className,
+ funcName
+ }) => {
+ if (!expectedType || !paramName || !moduleName || !funcName) {
+ throw new Error(`Unexpected input to 'incorrect-type' error.`);
+ return `The return value from ` + `'${moduleName}.${classNameStr}${funcName}()' ` + `must be an instance of class ${expectedClassName}.`;
+ }
+ return `The parameter '${paramName}' passed into ` + `'${moduleName}.${classNameStr}${funcName}()' ` + `must be an instance of class ${expectedClassName}.`;
+ throw new Error(`Unexpected input to 'missing-a-method' error.`);
+ }
+ return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
+ },
+ 'add-to-cache-list-unexpected-type': ({
+ entry
+ }) => {
+ return `An unexpected entry was passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' The entry ` + `'${JSON.stringify(entry)}' isn't supported. You must supply an array of ` + `strings with one or more characters, objects with a url property or ` + `Request objects.`;
+ },
+ 'add-to-cache-list-conflicting-entries': ({
+ firstEntry,
+ secondEntry
+ }) => {
+ if (!firstEntry || !secondEntry) {
+ throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
+ }
+ return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${firstEntry} but different revision details. Workbox is ` + `unable to cache and version the asset correctly. Please remove one ` + `of the entries.`;
+ },
+ 'plugin-error-request-will-fetch': ({
+ thrownErrorMessage
+ }) => {
+ if (!thrownErrorMessage) {
+ throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`);
+ }
+ return `An error was thrown by a plugins 'requestWillFetch()' method. ` + `The thrown error message was: '${thrownErrorMessage}'.`;
+ },
+ 'invalid-cache-name': ({
+ cacheNameId,
+ value
+ }) => {
+ if (!cacheNameId) {
+ throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
+ }
+ return `You must provide a name containing at least one character for ` + `setCacheDetails({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`;
+ return `The route you're trying to unregister was not previously ` + `registered.`;
+ },
+ 'queue-replay-failed': ({
+ name
+ }) => {
+ return `Replaying the background sync queue '${name}' failed.`;
+ },
+ 'duplicate-queue-name': ({
+ name
+ }) => {
+ return `The Queue name '${name}' is already being used. ` + `All instances of backgroundSync.Queue must be given unique names.`;
+ },
+ 'expired-test-without-max-age': ({
+ methodName,
+ paramName
+ }) => {
+ return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
+ },
+ 'unsupported-route-type': ({
+ moduleName,
+ className,
+ funcName,
+ paramName
+ }) => {
+ return `The supplied '${paramName}' parameter was an unsupported type. ` + `Please check the docs for ${moduleName}.${className}.${funcName} for ` + `valid input types.`;
+ },
+ 'not-array-of-class': ({
+ value,
+ expectedClass,
+ moduleName,
+ className,
+ funcName,
+ paramName
+ }) => {
+ return `The supplied '${paramName}' parameter must be an array of ` + `'${expectedClass}' objects. Received '${JSON.stringify(value)},'. ` + `Please check the call to ${moduleName}.${className}.${funcName}() ` + `to fix the issue.`;
+ },
+ 'max-entries-or-age-required': ({
+ moduleName,
+ className,
+ funcName
+ }) => {
+ return `You must define either config.maxEntries or config.maxAgeSeconds` + `in ${moduleName}.${className}.${funcName}`;
+ },
+ 'statuses-or-headers-required': ({
+ moduleName,
+ className,
+ funcName
+ }) => {
+ return `You must define either config.statuses or config.headers` + `in ${moduleName}.${className}.${funcName}`;
+ },
+ 'invalid-string': ({
+ moduleName,
+ funcName,
+ paramName
+ }) => {
+ if (!paramName || !moduleName || !funcName) {
+ throw new Error(`Unexpected input to 'invalid-string' error.`);
+ }
+ return `When using strings, the '${paramName}' parameter must start with ` + `'http' (for cross-origin matches) or '/' (for same-origin matches). ` + `Please see the docs for ${moduleName}.${funcName}() for ` + `more info.`;
+ },
+ 'channel-name-required': () => {
+ return `You must provide a channelName to construct a ` + `BroadcastCacheUpdate instance.`;
+ },
+ 'invalid-responses-are-same-args': () => {
+ return `The arguments passed into responsesAreSame() appear to be ` + `invalid. Please ensure valid Responses are used.`;
+ },
+ 'expire-custom-caches-only': () => {
+ return `You must provide a 'cacheName' property when using the ` + `expiration plugin with a runtime caching strategy.`;
+ },
+ 'unit-must-be-bytes': ({
+ normalizedRangeHeader
+ }) => {
+ if (!normalizedRangeHeader) {
+ throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
+ }
+ return `The 'unit' portion of the Range header must be set to 'bytes'. ` + `The Range header provided was "${normalizedRangeHeader}"`;
+ },
+ 'single-range-only': ({
+ normalizedRangeHeader
+ }) => {
+ if (!normalizedRangeHeader) {
+ throw new Error(`Unexpected input to 'single-range-only' error.`);
+ }
+ return `Multiple ranges are not supported. Please use a single start ` + `value, and optional end value. The Range header provided was ` + `"${normalizedRangeHeader}"`;
+ },
+ 'invalid-range-values': ({
+ normalizedRangeHeader
+ }) => {
+ if (!normalizedRangeHeader) {
+ throw new Error(`Unexpected input to 'invalid-range-values' error.`);
+ }
+ return `The Range header is missing both start and end values. At least ` + `one of those values is needed. The Range header provided was ` + `"${normalizedRangeHeader}"`;
+ },
+ 'no-range-header': () => {
+ return `No Range header was found in the Request provided.`;
+ },
+ 'range-not-satisfiable': ({
+ size,
+ start,
+ end
+ }) => {
+ return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
+ },
+ 'attempt-to-cache-non-get-request': ({
+ url,
+ method
+ }) => {
+ return `Unable to cache '${url}' because it is a '${method}' request and ` + `only 'GET' requests can be cached.`;
+ },
+ 'cache-put-with-no-response': ({
+ url
+ }) => {
+ return `There was an attempt to cache '${url}' but the response was not ` + `defined.`;
+ },
+ 'no-response': ({
+ url,
+ error
+ }) => {
+ let message = `The strategy could not generate a response for '${url}'.`;
+ if (error) {
+ message += ` The underlying error is ${error}.`;
+ }
+ return message;
+ },
+ 'bad-precaching-response': ({
+ url,
+ status
+ }) => {
+ return `The precaching request for '${url}' failed` + (status ? ` with an HTTP status of ${status}.` : `.`);
+ },
+ 'non-precached-url': ({
+ url
+ }) => {
+ return `createHandlerBoundToURL('${url}') was called, but that URL is ` + `not precached. Please pass in a URL that is precached instead.`;
+ },
+ 'add-to-cache-list-conflicting-integrities': ({
+ url
+ }) => {
+ return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${url} with different integrity values. Please remove one of them.`;
+ },
+ 'missing-precache-entry': ({
+ cacheName,
+ url
+ }) => {
+ return `Unable to find a precached response in ${cacheName} for ${url}.`;
+ },
+ 'cross-origin-copy-response': ({
+ origin
+ }) => {
+ return `workbox-core.copyResponse() can only be used with same-origin ` + `responses. It was passed a response with origin ${origin}.`;
+ },
+ 'opaque-streams-source': ({
+ type
+ }) => {
+ const message = `One of the workbox-streams sources resulted in an ` + `'${type}' response.`;
+ if (type === 'opaqueredirect') {
+ return `${message} Please do not use a navigation request that results ` + `in a redirect as a source.`;
+ }
+ return `${message} Please ensure your sources are CORS-enabled.`;
+ }
+ };
+
+ /*
+ Copyright 2018 Google LLC
+
+ Use of this source code is governed by an MIT-style
+ license that can be found in the LICENSE file or at
+ * @param {RegExp} regExp The regular expression to match against URLs.
+ * @param {workbox-routing~handlerCallback} handler A callback
+ * function that returns a Promise resulting in a Response.
+ * @param {string} [method='GET'] The HTTP method to match the Route
+ * against.
+ */
+ constructor(regExp, handler, method) {
+ {
+ finalAssertExports.isInstance(regExp, RegExp, {
+ moduleName: 'workbox-routing',
+ className: 'RegExpRoute',
+ funcName: 'constructor',
+ paramName: 'pattern'
+ });
+ }
+ const match = ({
+ url
+ }) => {
+ const result = regExp.exec(url.href);
+ // Return immediately if there's no match.
+ if (!result) {
+ return;
+ }
+ // Require that the match start at the first character in the URL string
+ // if it's a cross-origin request.
+ // See https://github.com/GoogleChrome/workbox/issues/281 for the context
+ // behind this behavior.
+ if (url.origin !== location.origin && result.index !== 0) {
+ {
+ logger.debug(`The regular expression '${regExp.toString()}' only partially matched ` + `against the cross-origin URL '${url.toString()}'. RegExpRoute's will only ` + `handle cross-origin requests if they match the entire URL.`);
+ }
+ return;
+ }
+ // If the route matches, but there aren't any capture groups defined, then
+ // this will return [], which is truthy and therefore sufficient to
+ // indicate a match.
+ // If there are capture groups, then it will return their values.
+ return result.slice(1);
+ };
+ super(match, handler, method);
+ }
+ }
+
+ /*
+ Copyright 2018 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.
+ */
+ const getFriendlyURL = url => {
+ const urlObj = new URL(String(url), location.href);
+ // See https://github.com/GoogleChrome/workbox/issues/2323
+ // We want to include everything, except for the origin if it's same-origin.
+ // Warn developers that using an async matchCallback is almost always
+ // not the right thing to do.
+ if (matchResult instanceof Promise) {
+ logger.warn(`While routing ${getFriendlyURL(url)}, an async ` + `matchCallback function was used. Please convert the ` + `following route to use a synchronous matchCallback function:`, route);
+ }
+ }
+ // See https://github.com/GoogleChrome/workbox/issues/2079
+ // See https://github.com/pillarjs/path-to-regexp#parameters
+ const wildcards = '[*:?+]';
+ if (new RegExp(`${wildcards}`).exec(valueToCheck)) {
+ logger.debug(`The '$capture' parameter contains an Express-style wildcard ` + `character (${wildcards}). Strings are now always interpreted as ` + `exact matches; use a RegExp for partial or wildcard matches.`);
+ }
+ }
+ const matchCallback = ({
+ url
+ }) => {
+ {
+ if (url.pathname === captureUrl.pathname && url.origin !== captureUrl.origin) {
+ logger.debug(`${capture} only partially matches the cross-origin URL ` + `${url.toString()}. This route will only handle cross-origin requests ` + `if they match the entire URL.`);
+ }
+ }
+ return url.href === captureUrl.href;
+ };
+ // If `capture` is a string then `handler` and `method` must be present.
+ route = new Route(matchCallback, handler, method);
+ } else if (capture instanceof RegExp) {
+ // If `capture` is a `RegExp` then `handler` and `method` must be present.
+ route = new RegExpRoute(capture, handler, method);
+ } else if (typeof capture === 'function') {
+ // If `capture` is a function then `handler` and `method` must be present.
+ route = new Route(capture, handler, method);
+ } else if (capture instanceof Route) {
+ route = capture;
+ } else {
+ throw new WorkboxError('unsupported-route-type', {
+ if (effectiveRequest.method && effectiveRequest.method !== 'GET') {
+ throw new WorkboxError('attempt-to-cache-non-get-request', {
+ url: getFriendlyURL(effectiveRequest.url),
+ method: effectiveRequest.method
+ });
+ }
+ // See https://github.com/GoogleChrome/workbox/issues/2818
+ const vary = response.headers.get('Vary');
+ if (vary) {
+ logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)} ` + `has a 'Vary: ${vary}' header. ` + `Consider setting the {ignoreVary: true} option on your strategy ` + `to ensure cache matching and deletion works as expected.`);
+ }
+ }
+ if (!response) {
+ {
+ logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
+ }
+ throw new WorkboxError('cache-put-with-no-response', {
+ * Note: any work done after `doneWaiting()` settles should be manually
+ * passed to an event's `waitUntil()` method (not this handler's
+ * `waitUntil()` method), otherwise the service worker thread my be killed
+ * prior to your work completing.
+ */
+ async doneWaiting() {
+ let promise;
+ while (promise = this._extendLifetimePromises.shift()) {
+ await promise;
+ }
+ }
+ /**
+ * Stops running the strategy and immediately resolves any pending
+ * `waitUntil()` promises.
+ */
+ destroy() {
+ this._handlerDeferred.resolve(null);
+ }
+ /**
+ * This method will call cacheWillUpdate on the available plugins (or use
+ * status === 200) to determine if the Response is safe and valid to cache.
+ *
+ * @param {Request} options.request
+ * @param {Response} options.response
+ * @return {Promise<Response|undefined>}
+ *
+ * @private
+ */
+ async _ensureResponseSafeToCache(response) {
+ let responseToCache = response;
+ let pluginsUsed = false;
+ for (const callback of this.iterateCallbacks('cacheWillUpdate')) {
+ responseToCache = (await callback({
+ request: this.request,
+ response: responseToCache,
+ event: this.event
+ })) || undefined;
+ pluginsUsed = true;
+ if (!responseToCache) {
+ break;
+ }
+ }
+ if (!pluginsUsed) {
+ if (responseToCache && responseToCache.status !== 200) {
+ responseToCache = undefined;
+ }
+ {
+ if (responseToCache) {
+ if (responseToCache.status !== 200) {
+ if (responseToCache.status === 0) {
+ logger.warn(`The response for '${this.request.url}' ` + `is an opaque response. The caching strategy that you're ` + `using will not cache opaque responses by default.`);
+ } else {
+ logger.debug(`The response for '${this.request.url}' ` + `returned a status code of '${response.status}' and won't ` + `be cached as a result.`);
+ }
+ }
+ }
+ }
+ }
+ return responseToCache;
+ }
+ }
+
+ /*
+ Copyright 2020 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.
+ */
+ /**
+ * An abstract base class that all other strategy classes must extend from:
+ *
+ * @memberof workbox-strategies
+ */
+ class Strategy {
+ /**
+ * Creates a new instance of the strategy and sets all documented option
+ * properties as public instance properties.
+ *
+ * Note: if a custom strategy class extends the base Strategy class and does
+ * not need more than these properties, it does not need to define its own
+ * constructor.
+ *
+ * @param {Object} [options]
+ * @param {string} [options.cacheName] Cache name to store and retrieve
+ * requests. Defaults to the cache names provided by
+ const warningMessage = `Workbox is precaching URLs without revision ` + `info: ${urlsToWarnAbout.join(', ')}\nThis is generally NOT safe. ` + `Learn more at https://bit.ly/wb-precache`;
+ {
+ logger.warn(warningMessage);
+ }
+ }
+ }
+ }
+ /**
+ * Precaches new and updated assets. Call this method from the service worker
+ * install event.
+ *
+ * Note: this method calls `event.waitUntil()` for you, so you do not need
+ logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL matches this denylist pattern: ` + `${regExp.toString()}`);
+ }
+ return false;
+ }
+ }
+ if (this._allowlist.some(regExp => regExp.test(pathnameAndSearch))) {
+ {
+ logger.debug(`The navigation route ${pathnameAndSearch} ` + `is being used.`);
+ }
+ return true;
+ }
+ {
+ logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL being navigated to doesn't ` + `match the allowlist.`);
+ }
+ return false;
+ }
+ }
+
+ /*
+ 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.
+ */
+ /**
+ * Helper function that calls
+ * {@link PrecacheController#createHandlerBoundToURL} on the default
+ * {@link PrecacheController} instance.
+ *
+ * If you are creating your own {@link PrecacheController}, then call the
+ * {@link PrecacheController#createHandlerBoundToURL} on that instance,
+ * instead of using this function.
+ *
+ * @param {string} url The precached URL which will be used to lookup the
+ * `Response`.
+ * @param {boolean} [fallbackToNetwork=true] Whether to attempt to get the
+ * response from the network if there's a precache miss.