1 | this.workbox = this.workbox || {};
|
2 | this.workbox.core = (function (exports) {
|
3 | 'use strict';
|
4 |
|
5 | try {
|
6 | self['workbox:core:5.1.4'] && _();
|
7 | } catch (e) {}
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | const logger = (() => {
|
16 |
|
17 |
|
18 | if (!('__WB_DISABLE_DEV_LOGS' in self)) {
|
19 | self.__WB_DISABLE_DEV_LOGS = false;
|
20 | }
|
21 |
|
22 | let inGroup = false;
|
23 | const methodToColorMap = {
|
24 | debug: `#7f8c8d`,
|
25 | log: `#2ecc71`,
|
26 | warn: `#f39c12`,
|
27 | error: `#c0392b`,
|
28 | groupCollapsed: `#3498db`,
|
29 | groupEnd: null
|
30 | };
|
31 |
|
32 | const print = function (method, args) {
|
33 | if (self.__WB_DISABLE_DEV_LOGS) {
|
34 | return;
|
35 | }
|
36 |
|
37 | if (method === 'groupCollapsed') {
|
38 |
|
39 |
|
40 | if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
|
41 | console[method](...args);
|
42 | return;
|
43 | }
|
44 | }
|
45 |
|
46 | const styles = [`background: ${methodToColorMap[method]}`, `border-radius: 0.5em`, `color: white`, `font-weight: bold`, `padding: 2px 0.5em`];
|
47 |
|
48 | const logPrefix = inGroup ? [] : ['%cworkbox', styles.join(';')];
|
49 | console[method](...logPrefix, ...args);
|
50 |
|
51 | if (method === 'groupCollapsed') {
|
52 | inGroup = true;
|
53 | }
|
54 |
|
55 | if (method === 'groupEnd') {
|
56 | inGroup = false;
|
57 | }
|
58 | };
|
59 |
|
60 | const api = {};
|
61 | const loggerMethods = Object.keys(methodToColorMap);
|
62 |
|
63 | for (const key of loggerMethods) {
|
64 | const method = key;
|
65 |
|
66 | api[method] = (...args) => {
|
67 | print(method, args);
|
68 | };
|
69 | }
|
70 |
|
71 | return api;
|
72 | })();
|
73 |
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | const messages = {
|
82 | 'invalid-value': ({
|
83 | paramName,
|
84 | validValueDescription,
|
85 | value
|
86 | }) => {
|
87 | if (!paramName || !validValueDescription) {
|
88 | throw new Error(`Unexpected input to 'invalid-value' error.`);
|
89 | }
|
90 |
|
91 | return `The '${paramName}' parameter was given a value with an ` + `unexpected value. ${validValueDescription} Received a value of ` + `${JSON.stringify(value)}.`;
|
92 | },
|
93 | 'not-an-array': ({
|
94 | moduleName,
|
95 | className,
|
96 | funcName,
|
97 | paramName
|
98 | }) => {
|
99 | if (!moduleName || !className || !funcName || !paramName) {
|
100 | throw new Error(`Unexpected input to 'not-an-array' error.`);
|
101 | }
|
102 |
|
103 | return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
|
104 | },
|
105 | 'incorrect-type': ({
|
106 | expectedType,
|
107 | paramName,
|
108 | moduleName,
|
109 | className,
|
110 | funcName
|
111 | }) => {
|
112 | if (!expectedType || !paramName || !moduleName || !funcName) {
|
113 | throw new Error(`Unexpected input to 'incorrect-type' error.`);
|
114 | }
|
115 |
|
116 | return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}` + `${funcName}()' must be of type ${expectedType}.`;
|
117 | },
|
118 | 'incorrect-class': ({
|
119 | expectedClass,
|
120 | paramName,
|
121 | moduleName,
|
122 | className,
|
123 | funcName,
|
124 | isReturnValueProblem
|
125 | }) => {
|
126 | if (!expectedClass || !moduleName || !funcName) {
|
127 | throw new Error(`Unexpected input to 'incorrect-class' error.`);
|
128 | }
|
129 |
|
130 | if (isReturnValueProblem) {
|
131 | return `The return value from ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
|
132 | }
|
133 |
|
134 | return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className ? className + '.' : ''}${funcName}()' ` + `must be an instance of class ${expectedClass.name}.`;
|
135 | },
|
136 | 'missing-a-method': ({
|
137 | expectedMethod,
|
138 | paramName,
|
139 | moduleName,
|
140 | className,
|
141 | funcName
|
142 | }) => {
|
143 | if (!expectedMethod || !paramName || !moduleName || !className || !funcName) {
|
144 | throw new Error(`Unexpected input to 'missing-a-method' error.`);
|
145 | }
|
146 |
|
147 | return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
|
148 | },
|
149 | 'add-to-cache-list-unexpected-type': ({
|
150 | entry
|
151 | }) => {
|
152 | 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.`;
|
153 | },
|
154 | 'add-to-cache-list-conflicting-entries': ({
|
155 | firstEntry,
|
156 | secondEntry
|
157 | }) => {
|
158 | if (!firstEntry || !secondEntry) {
|
159 | throw new Error(`Unexpected input to ` + `'add-to-cache-list-duplicate-entries' error.`);
|
160 | }
|
161 |
|
162 | return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${firstEntry._entryId} but different revision details. Workbox is ` + `unable to cache and version the asset correctly. Please remove one ` + `of the entries.`;
|
163 | },
|
164 | 'plugin-error-request-will-fetch': ({
|
165 | thrownError
|
166 | }) => {
|
167 | if (!thrownError) {
|
168 | throw new Error(`Unexpected input to ` + `'plugin-error-request-will-fetch', error.`);
|
169 | }
|
170 |
|
171 | return `An error was thrown by a plugins 'requestWillFetch()' method. ` + `The thrown error message was: '${thrownError.message}'.`;
|
172 | },
|
173 | 'invalid-cache-name': ({
|
174 | cacheNameId,
|
175 | value
|
176 | }) => {
|
177 | if (!cacheNameId) {
|
178 | throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
|
179 | }
|
180 |
|
181 | return `You must provide a name containing at least one character for ` + `setCacheDetails({${cacheNameId}: '...'}). Received a value of ` + `'${JSON.stringify(value)}'`;
|
182 | },
|
183 | 'unregister-route-but-not-found-with-method': ({
|
184 | method
|
185 | }) => {
|
186 | if (!method) {
|
187 | throw new Error(`Unexpected input to ` + `'unregister-route-but-not-found-with-method' error.`);
|
188 | }
|
189 |
|
190 | return `The route you're trying to unregister was not previously ` + `registered for the method type '${method}'.`;
|
191 | },
|
192 | 'unregister-route-route-not-registered': () => {
|
193 | return `The route you're trying to unregister was not previously ` + `registered.`;
|
194 | },
|
195 | 'queue-replay-failed': ({
|
196 | name
|
197 | }) => {
|
198 | return `Replaying the background sync queue '${name}' failed.`;
|
199 | },
|
200 | 'duplicate-queue-name': ({
|
201 | name
|
202 | }) => {
|
203 | return `The Queue name '${name}' is already being used. ` + `All instances of backgroundSync.Queue must be given unique names.`;
|
204 | },
|
205 | 'expired-test-without-max-age': ({
|
206 | methodName,
|
207 | paramName
|
208 | }) => {
|
209 | return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
|
210 | },
|
211 | 'unsupported-route-type': ({
|
212 | moduleName,
|
213 | className,
|
214 | funcName,
|
215 | paramName
|
216 | }) => {
|
217 | return `The supplied '${paramName}' parameter was an unsupported type. ` + `Please check the docs for ${moduleName}.${className}.${funcName} for ` + `valid input types.`;
|
218 | },
|
219 | 'not-array-of-class': ({
|
220 | value,
|
221 | expectedClass,
|
222 | moduleName,
|
223 | className,
|
224 | funcName,
|
225 | paramName
|
226 | }) => {
|
227 | 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.`;
|
228 | },
|
229 | 'max-entries-or-age-required': ({
|
230 | moduleName,
|
231 | className,
|
232 | funcName
|
233 | }) => {
|
234 | return `You must define either config.maxEntries or config.maxAgeSeconds` + `in ${moduleName}.${className}.${funcName}`;
|
235 | },
|
236 | 'statuses-or-headers-required': ({
|
237 | moduleName,
|
238 | className,
|
239 | funcName
|
240 | }) => {
|
241 | return `You must define either config.statuses or config.headers` + `in ${moduleName}.${className}.${funcName}`;
|
242 | },
|
243 | 'invalid-string': ({
|
244 | moduleName,
|
245 | funcName,
|
246 | paramName
|
247 | }) => {
|
248 | if (!paramName || !moduleName || !funcName) {
|
249 | throw new Error(`Unexpected input to 'invalid-string' error.`);
|
250 | }
|
251 |
|
252 | 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.`;
|
253 | },
|
254 | 'channel-name-required': () => {
|
255 | return `You must provide a channelName to construct a ` + `BroadcastCacheUpdate instance.`;
|
256 | },
|
257 | 'invalid-responses-are-same-args': () => {
|
258 | return `The arguments passed into responsesAreSame() appear to be ` + `invalid. Please ensure valid Responses are used.`;
|
259 | },
|
260 | 'expire-custom-caches-only': () => {
|
261 | return `You must provide a 'cacheName' property when using the ` + `expiration plugin with a runtime caching strategy.`;
|
262 | },
|
263 | 'unit-must-be-bytes': ({
|
264 | normalizedRangeHeader
|
265 | }) => {
|
266 | if (!normalizedRangeHeader) {
|
267 | throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
|
268 | }
|
269 |
|
270 | return `The 'unit' portion of the Range header must be set to 'bytes'. ` + `The Range header provided was "${normalizedRangeHeader}"`;
|
271 | },
|
272 | 'single-range-only': ({
|
273 | normalizedRangeHeader
|
274 | }) => {
|
275 | if (!normalizedRangeHeader) {
|
276 | throw new Error(`Unexpected input to 'single-range-only' error.`);
|
277 | }
|
278 |
|
279 | return `Multiple ranges are not supported. Please use a single start ` + `value, and optional end value. The Range header provided was ` + `"${normalizedRangeHeader}"`;
|
280 | },
|
281 | 'invalid-range-values': ({
|
282 | normalizedRangeHeader
|
283 | }) => {
|
284 | if (!normalizedRangeHeader) {
|
285 | throw new Error(`Unexpected input to 'invalid-range-values' error.`);
|
286 | }
|
287 |
|
288 | 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}"`;
|
289 | },
|
290 | 'no-range-header': () => {
|
291 | return `No Range header was found in the Request provided.`;
|
292 | },
|
293 | 'range-not-satisfiable': ({
|
294 | size,
|
295 | start,
|
296 | end
|
297 | }) => {
|
298 | return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
|
299 | },
|
300 | 'attempt-to-cache-non-get-request': ({
|
301 | url,
|
302 | method
|
303 | }) => {
|
304 | return `Unable to cache '${url}' because it is a '${method}' request and ` + `only 'GET' requests can be cached.`;
|
305 | },
|
306 | 'cache-put-with-no-response': ({
|
307 | url
|
308 | }) => {
|
309 | return `There was an attempt to cache '${url}' but the response was not ` + `defined.`;
|
310 | },
|
311 | 'no-response': ({
|
312 | url,
|
313 | error
|
314 | }) => {
|
315 | let message = `The strategy could not generate a response for '${url}'.`;
|
316 |
|
317 | if (error) {
|
318 | message += ` The underlying error is ${error}.`;
|
319 | }
|
320 |
|
321 | return message;
|
322 | },
|
323 | 'bad-precaching-response': ({
|
324 | url,
|
325 | status
|
326 | }) => {
|
327 | return `The precaching request for '${url}' failed with an HTTP ` + `status of ${status}.`;
|
328 | },
|
329 | 'non-precached-url': ({
|
330 | url
|
331 | }) => {
|
332 | return `createHandlerBoundToURL('${url}') was called, but that URL is ` + `not precached. Please pass in a URL that is precached instead.`;
|
333 | },
|
334 | 'add-to-cache-list-conflicting-integrities': ({
|
335 | url
|
336 | }) => {
|
337 | return `Two of the entries passed to ` + `'workbox-precaching.PrecacheController.addToCacheList()' had the URL ` + `${url} with different integrity values. Please remove one of them.`;
|
338 | },
|
339 | 'missing-precache-entry': ({
|
340 | cacheName,
|
341 | url
|
342 | }) => {
|
343 | return `Unable to find a precached response in ${cacheName} for ${url}.`;
|
344 | }
|
345 | };
|
346 |
|
347 | |
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 | const generatorFunction = (code, details = {}) => {
|
356 | const message = messages[code];
|
357 |
|
358 | if (!message) {
|
359 | throw new Error(`Unable to find message for code '${code}'.`);
|
360 | }
|
361 |
|
362 | return message(details);
|
363 | };
|
364 |
|
365 | const messageGenerator = generatorFunction;
|
366 |
|
367 | |
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 | |
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 | class WorkboxError extends Error {
|
385 | |
386 |
|
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 | constructor(errorCode, details) {
|
394 | const message = messageGenerator(errorCode, details);
|
395 | super(message);
|
396 | this.name = errorCode;
|
397 | this.details = details;
|
398 | }
|
399 |
|
400 | }
|
401 |
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 | |
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | const isArray = (value, details) => {
|
417 | if (!Array.isArray(value)) {
|
418 | throw new WorkboxError('not-an-array', details);
|
419 | }
|
420 | };
|
421 |
|
422 | const hasMethod = (object, expectedMethod, details) => {
|
423 | const type = typeof object[expectedMethod];
|
424 |
|
425 | if (type !== 'function') {
|
426 | details['expectedMethod'] = expectedMethod;
|
427 | throw new WorkboxError('missing-a-method', details);
|
428 | }
|
429 | };
|
430 |
|
431 | const isType = (object, expectedType, details) => {
|
432 | if (typeof object !== expectedType) {
|
433 | details['expectedType'] = expectedType;
|
434 | throw new WorkboxError('incorrect-type', details);
|
435 | }
|
436 | };
|
437 |
|
438 | const isInstance = (object, expectedClass, details) => {
|
439 | if (!(object instanceof expectedClass)) {
|
440 | details['expectedClass'] = expectedClass;
|
441 | throw new WorkboxError('incorrect-class', details);
|
442 | }
|
443 | };
|
444 |
|
445 | const isOneOf = (value, validValues, details) => {
|
446 | if (!validValues.includes(value)) {
|
447 | details['validValueDescription'] = `Valid values are ${JSON.stringify(validValues)}.`;
|
448 | throw new WorkboxError('invalid-value', details);
|
449 | }
|
450 | };
|
451 |
|
452 | const isArrayOfClass = (value, expectedClass, details) => {
|
453 | const error = new WorkboxError('not-array-of-class', details);
|
454 |
|
455 | if (!Array.isArray(value)) {
|
456 | throw error;
|
457 | }
|
458 |
|
459 | for (const item of value) {
|
460 | if (!(item instanceof expectedClass)) {
|
461 | throw error;
|
462 | }
|
463 | }
|
464 | };
|
465 |
|
466 | const finalAssertExports = {
|
467 | hasMethod,
|
468 | isArray,
|
469 | isInstance,
|
470 | isOneOf,
|
471 | isType,
|
472 | isArrayOfClass
|
473 | };
|
474 |
|
475 | |
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 |
|
483 | const quotaErrorCallbacks = new Set();
|
484 |
|
485 | |
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 | |
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 |
|
500 | function registerQuotaErrorCallback(callback) {
|
501 | {
|
502 | finalAssertExports.isType(callback, 'function', {
|
503 | moduleName: 'workbox-core',
|
504 | funcName: 'register',
|
505 | paramName: 'callback'
|
506 | });
|
507 | }
|
508 |
|
509 | quotaErrorCallbacks.add(callback);
|
510 |
|
511 | {
|
512 | logger.log('Registered a callback to respond to quota errors.', callback);
|
513 | }
|
514 | }
|
515 |
|
516 | |
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 | const _cacheNameDetails = {
|
524 | googleAnalytics: 'googleAnalytics',
|
525 | precache: 'precache-v2',
|
526 | prefix: 'workbox',
|
527 | runtime: 'runtime',
|
528 | suffix: typeof registration !== 'undefined' ? registration.scope : ''
|
529 | };
|
530 |
|
531 | const _createCacheName = cacheName => {
|
532 | return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter(value => value && value.length > 0).join('-');
|
533 | };
|
534 |
|
535 | const eachCacheNameDetail = fn => {
|
536 | for (const key of Object.keys(_cacheNameDetails)) {
|
537 | fn(key);
|
538 | }
|
539 | };
|
540 |
|
541 | const cacheNames = {
|
542 | updateDetails: details => {
|
543 | eachCacheNameDetail(key => {
|
544 | if (typeof details[key] === 'string') {
|
545 | _cacheNameDetails[key] = details[key];
|
546 | }
|
547 | });
|
548 | },
|
549 | getGoogleAnalyticsName: userCacheName => {
|
550 | return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
551 | },
|
552 | getPrecacheName: userCacheName => {
|
553 | return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
554 | },
|
555 | getPrefix: () => {
|
556 | return _cacheNameDetails.prefix;
|
557 | },
|
558 | getRuntimeName: userCacheName => {
|
559 | return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
560 | },
|
561 | getSuffix: () => {
|
562 | return _cacheNameDetails.suffix;
|
563 | }
|
564 | };
|
565 |
|
566 | |
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 | |
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 | async function executeQuotaErrorCallbacks() {
|
582 | {
|
583 | logger.log(`About to run ${quotaErrorCallbacks.size} ` + `callbacks to clean up caches.`);
|
584 | }
|
585 |
|
586 | for (const callback of quotaErrorCallbacks) {
|
587 | await callback();
|
588 |
|
589 | {
|
590 | logger.log(callback, 'is complete.');
|
591 | }
|
592 | }
|
593 |
|
594 | {
|
595 | logger.log('Finished running callbacks.');
|
596 | }
|
597 | }
|
598 |
|
599 | |
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 | const getFriendlyURL = url => {
|
608 | const urlObj = new URL(String(url), location.href);
|
609 |
|
610 |
|
611 | return urlObj.href.replace(new RegExp(`^${location.origin}`), '');
|
612 | };
|
613 |
|
614 | |
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 | const pluginUtils = {
|
622 | filter: (plugins, callbackName) => {
|
623 | return plugins.filter(plugin => callbackName in plugin);
|
624 | }
|
625 | };
|
626 |
|
627 | |
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 | |
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 | const _getEffectiveRequest = async ({
|
651 | request,
|
652 | mode,
|
653 | plugins = []
|
654 | }) => {
|
655 | const cacheKeyWillBeUsedPlugins = pluginUtils.filter(plugins, "cacheKeyWillBeUsed"
|
656 |
|
657 | );
|
658 | let effectiveRequest = request;
|
659 |
|
660 | for (const plugin of cacheKeyWillBeUsedPlugins) {
|
661 | effectiveRequest = await plugin["cacheKeyWillBeUsed"
|
662 |
|
663 | ].call(plugin, {
|
664 | mode,
|
665 | request: effectiveRequest
|
666 | });
|
667 |
|
668 | if (typeof effectiveRequest === 'string') {
|
669 | effectiveRequest = new Request(effectiveRequest);
|
670 | }
|
671 |
|
672 | {
|
673 | finalAssertExports.isInstance(effectiveRequest, Request, {
|
674 | moduleName: 'Plugin',
|
675 | funcName: "cacheKeyWillBeUsed"
|
676 |
|
677 | ,
|
678 | isReturnValueProblem: true
|
679 | });
|
680 | }
|
681 | }
|
682 |
|
683 | return effectiveRequest;
|
684 | };
|
685 | |
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 | const _isResponseSafeToCache = async ({
|
702 | request,
|
703 | response,
|
704 | event,
|
705 | plugins = []
|
706 | }) => {
|
707 | let responseToCache = response;
|
708 | let pluginsUsed = false;
|
709 |
|
710 | for (const plugin of plugins) {
|
711 | if ("cacheWillUpdate"
|
712 |
|
713 | in plugin) {
|
714 | pluginsUsed = true;
|
715 | const pluginMethod = plugin["cacheWillUpdate"
|
716 |
|
717 | ];
|
718 | responseToCache = await pluginMethod.call(plugin, {
|
719 | request,
|
720 | response: responseToCache,
|
721 | event
|
722 | });
|
723 |
|
724 | {
|
725 | if (responseToCache) {
|
726 | finalAssertExports.isInstance(responseToCache, Response, {
|
727 | moduleName: 'Plugin',
|
728 | funcName: "cacheWillUpdate"
|
729 |
|
730 | ,
|
731 | isReturnValueProblem: true
|
732 | });
|
733 | }
|
734 | }
|
735 |
|
736 | if (!responseToCache) {
|
737 | break;
|
738 | }
|
739 | }
|
740 | }
|
741 |
|
742 | if (!pluginsUsed) {
|
743 | {
|
744 | if (responseToCache) {
|
745 | if (responseToCache.status !== 200) {
|
746 | if (responseToCache.status === 0) {
|
747 | logger.warn(`The response for '${request.url}' is an opaque ` + `response. The caching strategy that you're using will not ` + `cache opaque responses by default.`);
|
748 | } else {
|
749 | logger.debug(`The response for '${request.url}' returned ` + `a status code of '${response.status}' and won't be cached as a ` + `result.`);
|
750 | }
|
751 | }
|
752 | }
|
753 | }
|
754 |
|
755 | responseToCache = responseToCache && responseToCache.status === 200 ? responseToCache : undefined;
|
756 | }
|
757 |
|
758 | return responseToCache ? responseToCache : null;
|
759 | };
|
760 | |
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 |
|
775 |
|
776 |
|
777 | const matchWrapper = async ({
|
778 | cacheName,
|
779 | request,
|
780 | event,
|
781 | matchOptions,
|
782 | plugins = []
|
783 | }) => {
|
784 | const cache = await self.caches.open(cacheName);
|
785 | const effectiveRequest = await _getEffectiveRequest({
|
786 | plugins,
|
787 | request,
|
788 | mode: 'read'
|
789 | });
|
790 | let cachedResponse = await cache.match(effectiveRequest, matchOptions);
|
791 |
|
792 | {
|
793 | if (cachedResponse) {
|
794 | logger.debug(`Found a cached response in '${cacheName}'.`);
|
795 | } else {
|
796 | logger.debug(`No cached response found in '${cacheName}'.`);
|
797 | }
|
798 | }
|
799 |
|
800 | for (const plugin of plugins) {
|
801 | if ("cachedResponseWillBeUsed"
|
802 |
|
803 | in plugin) {
|
804 | const pluginMethod = plugin["cachedResponseWillBeUsed"
|
805 |
|
806 | ];
|
807 | cachedResponse = await pluginMethod.call(plugin, {
|
808 | cacheName,
|
809 | event,
|
810 | matchOptions,
|
811 | cachedResponse,
|
812 | request: effectiveRequest
|
813 | });
|
814 |
|
815 | {
|
816 | if (cachedResponse) {
|
817 | finalAssertExports.isInstance(cachedResponse, Response, {
|
818 | moduleName: 'Plugin',
|
819 | funcName: "cachedResponseWillBeUsed"
|
820 |
|
821 | ,
|
822 | isReturnValueProblem: true
|
823 | });
|
824 | }
|
825 | }
|
826 | }
|
827 | }
|
828 |
|
829 | return cachedResponse;
|
830 | };
|
831 | |
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 | const putWrapper = async ({
|
851 | cacheName,
|
852 | request,
|
853 | response,
|
854 | event,
|
855 | plugins = [],
|
856 | matchOptions
|
857 | }) => {
|
858 | {
|
859 | if (request.method && request.method !== 'GET') {
|
860 | throw new WorkboxError('attempt-to-cache-non-get-request', {
|
861 | url: getFriendlyURL(request.url),
|
862 | method: request.method
|
863 | });
|
864 | }
|
865 | }
|
866 |
|
867 | const effectiveRequest = await _getEffectiveRequest({
|
868 | plugins,
|
869 | request,
|
870 | mode: 'write'
|
871 | });
|
872 |
|
873 | if (!response) {
|
874 | {
|
875 | logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`);
|
876 | }
|
877 |
|
878 | throw new WorkboxError('cache-put-with-no-response', {
|
879 | url: getFriendlyURL(effectiveRequest.url)
|
880 | });
|
881 | }
|
882 |
|
883 | const responseToCache = await _isResponseSafeToCache({
|
884 | event,
|
885 | plugins,
|
886 | response,
|
887 | request: effectiveRequest
|
888 | });
|
889 |
|
890 | if (!responseToCache) {
|
891 | {
|
892 | logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will ` + `not be cached.`, responseToCache);
|
893 | }
|
894 |
|
895 | return;
|
896 | }
|
897 |
|
898 | const cache = await self.caches.open(cacheName);
|
899 | const updatePlugins = pluginUtils.filter(plugins, "cacheDidUpdate"
|
900 |
|
901 | );
|
902 | const oldResponse = updatePlugins.length > 0 ? await matchWrapper({
|
903 | cacheName,
|
904 | matchOptions,
|
905 | request: effectiveRequest
|
906 | }) : null;
|
907 |
|
908 | {
|
909 | logger.debug(`Updating the '${cacheName}' cache with a new Response for ` + `${getFriendlyURL(effectiveRequest.url)}.`);
|
910 | }
|
911 |
|
912 | try {
|
913 | await cache.put(effectiveRequest, responseToCache);
|
914 | } catch (error) {
|
915 |
|
916 | if (error.name === 'QuotaExceededError') {
|
917 | await executeQuotaErrorCallbacks();
|
918 | }
|
919 |
|
920 | throw error;
|
921 | }
|
922 |
|
923 | for (const plugin of updatePlugins) {
|
924 | await plugin["cacheDidUpdate"
|
925 |
|
926 | ].call(plugin, {
|
927 | cacheName,
|
928 | event,
|
929 | oldResponse,
|
930 | newResponse: responseToCache,
|
931 | request: effectiveRequest
|
932 | });
|
933 | }
|
934 | };
|
935 |
|
936 | const cacheWrapper = {
|
937 | put: putWrapper,
|
938 | match: matchWrapper
|
939 | };
|
940 |
|
941 | |
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 | let supportStatus;
|
949 | |
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 | function canConstructReadableStream() {
|
961 | if (supportStatus === undefined) {
|
962 |
|
963 | try {
|
964 | new ReadableStream({
|
965 | start() {}
|
966 |
|
967 | });
|
968 | supportStatus = true;
|
969 | } catch (error) {
|
970 | supportStatus = false;
|
971 | }
|
972 | }
|
973 |
|
974 | return supportStatus;
|
975 | }
|
976 |
|
977 | |
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 | let supportStatus$1;
|
985 | |
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 | function canConstructResponseFromBodyStream() {
|
996 | if (supportStatus$1 === undefined) {
|
997 | const testResponse = new Response('');
|
998 |
|
999 | if ('body' in testResponse) {
|
1000 | try {
|
1001 | new Response(testResponse.body);
|
1002 | supportStatus$1 = true;
|
1003 | } catch (error) {
|
1004 | supportStatus$1 = false;
|
1005 | }
|
1006 | }
|
1007 |
|
1008 | supportStatus$1 = false;
|
1009 | }
|
1010 |
|
1011 | return supportStatus$1;
|
1012 | }
|
1013 |
|
1014 | |
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 | |
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 | function dontWaitFor(promise) {
|
1027 |
|
1028 | promise.then(() => {});
|
1029 | }
|
1030 |
|
1031 | |
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 | |
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 | class DBWrapper {
|
1047 | |
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 | constructor(name, version, {
|
1057 | onupgradeneeded,
|
1058 | onversionchange
|
1059 | } = {}) {
|
1060 | this._db = null;
|
1061 | this._name = name;
|
1062 | this._version = version;
|
1063 | this._onupgradeneeded = onupgradeneeded;
|
1064 |
|
1065 | this._onversionchange = onversionchange || (() => this.close());
|
1066 | }
|
1067 | |
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 | get db() {
|
1076 | return this._db;
|
1077 | }
|
1078 | |
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 | async open() {
|
1088 | if (this._db) return;
|
1089 | this._db = await new Promise((resolve, reject) => {
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 | let openRequestTimedOut = false;
|
1096 | setTimeout(() => {
|
1097 | openRequestTimedOut = true;
|
1098 | reject(new Error('The open request was blocked and timed out'));
|
1099 | }, this.OPEN_TIMEOUT);
|
1100 | const openRequest = indexedDB.open(this._name, this._version);
|
1101 |
|
1102 | openRequest.onerror = () => reject(openRequest.error);
|
1103 |
|
1104 | openRequest.onupgradeneeded = evt => {
|
1105 | if (openRequestTimedOut) {
|
1106 | openRequest.transaction.abort();
|
1107 | openRequest.result.close();
|
1108 | } else if (typeof this._onupgradeneeded === 'function') {
|
1109 | this._onupgradeneeded(evt);
|
1110 | }
|
1111 | };
|
1112 |
|
1113 | openRequest.onsuccess = () => {
|
1114 | const db = openRequest.result;
|
1115 |
|
1116 | if (openRequestTimedOut) {
|
1117 | db.close();
|
1118 | } else {
|
1119 | db.onversionchange = this._onversionchange.bind(this);
|
1120 | resolve(db);
|
1121 | }
|
1122 | };
|
1123 | });
|
1124 | return this;
|
1125 | }
|
1126 | |
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 | async getKey(storeName, query) {
|
1138 | return (await this.getAllKeys(storeName, query, 1))[0];
|
1139 | }
|
1140 | |
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | async getAll(storeName, query, count) {
|
1153 | return await this.getAllMatching(storeName, {
|
1154 | query,
|
1155 | count
|
1156 | });
|
1157 | }
|
1158 | |
1159 |
|
1160 |
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 | async getAllKeys(storeName, query, count) {
|
1171 | const entries = await this.getAllMatching(storeName, {
|
1172 | query,
|
1173 | count,
|
1174 | includeKeys: true
|
1175 | });
|
1176 | return entries.map(entry => entry.key);
|
1177 | }
|
1178 | |
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 | async getAllMatching(storeName, {
|
1198 | index,
|
1199 | query = null,
|
1200 |
|
1201 | direction = 'next',
|
1202 | count,
|
1203 | includeKeys = false
|
1204 | } = {}) {
|
1205 | return await this.transaction([storeName], 'readonly', (txn, done) => {
|
1206 | const store = txn.objectStore(storeName);
|
1207 | const target = index ? store.index(index) : store;
|
1208 | const results = [];
|
1209 | const request = target.openCursor(query, direction);
|
1210 |
|
1211 | request.onsuccess = () => {
|
1212 | const cursor = request.result;
|
1213 |
|
1214 | if (cursor) {
|
1215 | results.push(includeKeys ? cursor : cursor.value);
|
1216 |
|
1217 | if (count && results.length >= count) {
|
1218 | done(results);
|
1219 | } else {
|
1220 | cursor.continue();
|
1221 | }
|
1222 | } else {
|
1223 | done(results);
|
1224 | }
|
1225 | };
|
1226 | });
|
1227 | }
|
1228 | |
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 | async transaction(storeNames, type, callback) {
|
1248 | await this.open();
|
1249 | return await new Promise((resolve, reject) => {
|
1250 | const txn = this._db.transaction(storeNames, type);
|
1251 |
|
1252 | txn.onabort = () => reject(txn.error);
|
1253 |
|
1254 | txn.oncomplete = () => resolve();
|
1255 |
|
1256 | callback(txn, value => resolve(value));
|
1257 | });
|
1258 | }
|
1259 | |
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 | async _call(method, storeName, type, ...args) {
|
1272 | const callback = (txn, done) => {
|
1273 | const objStore = txn.objectStore(storeName);
|
1274 |
|
1275 |
|
1276 | const request = objStore[method].apply(objStore, args);
|
1277 |
|
1278 | request.onsuccess = () => done(request.result);
|
1279 | };
|
1280 |
|
1281 | return await this.transaction([storeName], type, callback);
|
1282 | }
|
1283 | |
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 | close() {
|
1299 | if (this._db) {
|
1300 | this._db.close();
|
1301 |
|
1302 | this._db = null;
|
1303 | }
|
1304 | }
|
1305 |
|
1306 | }
|
1307 |
|
1308 |
|
1309 | DBWrapper.prototype.OPEN_TIMEOUT = 2000;
|
1310 |
|
1311 | const methodsToWrap = {
|
1312 | readonly: ['get', 'count', 'getKey', 'getAll', 'getAllKeys'],
|
1313 | readwrite: ['add', 'put', 'clear', 'delete']
|
1314 | };
|
1315 |
|
1316 | for (const [mode, methods] of Object.entries(methodsToWrap)) {
|
1317 | for (const method of methods) {
|
1318 | if (method in IDBObjectStore.prototype) {
|
1319 |
|
1320 | DBWrapper.prototype[method] = async function (storeName, ...args) {
|
1321 | return await this._call(method, storeName, mode, ...args);
|
1322 | };
|
1323 | }
|
1324 | }
|
1325 | }
|
1326 |
|
1327 | |
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 | |
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 | class Deferred {
|
1344 | |
1345 |
|
1346 |
|
1347 | constructor() {
|
1348 | this.promise = new Promise((resolve, reject) => {
|
1349 | this.resolve = resolve;
|
1350 | this.reject = reject;
|
1351 | });
|
1352 | }
|
1353 |
|
1354 | }
|
1355 |
|
1356 | |
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 |
|
1363 | |
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 |
|
1373 | const deleteDatabase = async name => {
|
1374 | await new Promise((resolve, reject) => {
|
1375 | const request = indexedDB.deleteDatabase(name);
|
1376 |
|
1377 | request.onerror = () => {
|
1378 | reject(request.error);
|
1379 | };
|
1380 |
|
1381 | request.onblocked = () => {
|
1382 | reject(new Error('Delete blocked'));
|
1383 | };
|
1384 |
|
1385 | request.onsuccess = () => {
|
1386 | resolve();
|
1387 | };
|
1388 | });
|
1389 | };
|
1390 |
|
1391 | |
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 | |
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 | const wrappedFetch = async ({
|
1415 | request,
|
1416 | fetchOptions,
|
1417 | event,
|
1418 | plugins = []
|
1419 | }) => {
|
1420 | if (typeof request === 'string') {
|
1421 | request = new Request(request);
|
1422 | }
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 | if (event instanceof FetchEvent && event.preloadResponse) {
|
1428 | const possiblePreloadResponse = await event.preloadResponse;
|
1429 |
|
1430 | if (possiblePreloadResponse) {
|
1431 | {
|
1432 | logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL(request.url)}'`);
|
1433 | }
|
1434 |
|
1435 | return possiblePreloadResponse;
|
1436 | }
|
1437 | }
|
1438 |
|
1439 | {
|
1440 | finalAssertExports.isInstance(request, Request, {
|
1441 | paramName: 'request',
|
1442 | expectedClass: Request,
|
1443 | moduleName: 'workbox-core',
|
1444 | className: 'fetchWrapper',
|
1445 | funcName: 'wrappedFetch'
|
1446 | });
|
1447 | }
|
1448 |
|
1449 | const failedFetchPlugins = pluginUtils.filter(plugins, "fetchDidFail"
|
1450 |
|
1451 | );
|
1452 |
|
1453 |
|
1454 |
|
1455 | const originalRequest = failedFetchPlugins.length > 0 ? request.clone() : null;
|
1456 |
|
1457 | try {
|
1458 | for (const plugin of plugins) {
|
1459 | if ("requestWillFetch"
|
1460 |
|
1461 | in plugin) {
|
1462 | const pluginMethod = plugin["requestWillFetch"
|
1463 |
|
1464 | ];
|
1465 | const requestClone = request.clone();
|
1466 | request = await pluginMethod.call(plugin, {
|
1467 | request: requestClone,
|
1468 | event
|
1469 | });
|
1470 |
|
1471 | if ("dev" !== 'production') {
|
1472 | if (request) {
|
1473 | finalAssertExports.isInstance(request, Request, {
|
1474 | moduleName: 'Plugin',
|
1475 | funcName: "cachedResponseWillBeUsed"
|
1476 |
|
1477 | ,
|
1478 | isReturnValueProblem: true
|
1479 | });
|
1480 | }
|
1481 | }
|
1482 | }
|
1483 | }
|
1484 | } catch (err) {
|
1485 | throw new WorkboxError('plugin-error-request-will-fetch', {
|
1486 | thrownError: err
|
1487 | });
|
1488 | }
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 | const pluginFilteredRequest = request.clone();
|
1494 |
|
1495 | try {
|
1496 | let fetchResponse;
|
1497 |
|
1498 | if (request.mode === 'navigate') {
|
1499 | fetchResponse = await fetch(request);
|
1500 | } else {
|
1501 | fetchResponse = await fetch(request, fetchOptions);
|
1502 | }
|
1503 |
|
1504 | if ("dev" !== 'production') {
|
1505 | logger.debug(`Network request for ` + `'${getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`);
|
1506 | }
|
1507 |
|
1508 | for (const plugin of plugins) {
|
1509 | if ("fetchDidSucceed"
|
1510 |
|
1511 | in plugin) {
|
1512 | fetchResponse = await plugin["fetchDidSucceed"
|
1513 |
|
1514 | ].call(plugin, {
|
1515 | event,
|
1516 | request: pluginFilteredRequest,
|
1517 | response: fetchResponse
|
1518 | });
|
1519 |
|
1520 | if ("dev" !== 'production') {
|
1521 | if (fetchResponse) {
|
1522 | finalAssertExports.isInstance(fetchResponse, Response, {
|
1523 | moduleName: 'Plugin',
|
1524 | funcName: "fetchDidSucceed"
|
1525 |
|
1526 | ,
|
1527 | isReturnValueProblem: true
|
1528 | });
|
1529 | }
|
1530 | }
|
1531 | }
|
1532 | }
|
1533 |
|
1534 | return fetchResponse;
|
1535 | } catch (error) {
|
1536 | {
|
1537 | logger.error(`Network request for ` + `'${getFriendlyURL(request.url)}' threw an error.`, error);
|
1538 | }
|
1539 |
|
1540 | for (const plugin of failedFetchPlugins) {
|
1541 | await plugin["fetchDidFail"
|
1542 |
|
1543 | ].call(plugin, {
|
1544 | error,
|
1545 | event,
|
1546 | originalRequest: originalRequest.clone(),
|
1547 | request: pluginFilteredRequest.clone()
|
1548 | });
|
1549 | }
|
1550 |
|
1551 | throw error;
|
1552 | }
|
1553 | };
|
1554 |
|
1555 | const fetchWrapper = {
|
1556 | fetch: wrappedFetch
|
1557 | };
|
1558 |
|
1559 | |
1560 |
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 | |
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 | function timeout(ms) {
|
1575 | return new Promise(resolve => setTimeout(resolve, ms));
|
1576 | }
|
1577 |
|
1578 | |
1579 |
|
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 | const MAX_RETRY_TIME = 2000;
|
1585 | |
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 | async function resultingClientExists(resultingClientId) {
|
1597 | if (!resultingClientId) {
|
1598 | return;
|
1599 | }
|
1600 |
|
1601 | let existingWindows = await self.clients.matchAll({
|
1602 | type: 'window'
|
1603 | });
|
1604 | const existingWindowIds = new Set(existingWindows.map(w => w.id));
|
1605 | let resultingWindow;
|
1606 | const startTime = performance.now();
|
1607 |
|
1608 | while (performance.now() - startTime < MAX_RETRY_TIME) {
|
1609 | existingWindows = await self.clients.matchAll({
|
1610 | type: 'window'
|
1611 | });
|
1612 | resultingWindow = existingWindows.find(w => {
|
1613 | if (resultingClientId) {
|
1614 |
|
1615 | return w.id === resultingClientId;
|
1616 | } else {
|
1617 |
|
1618 | return !existingWindowIds.has(w.id);
|
1619 | }
|
1620 | });
|
1621 |
|
1622 | if (resultingWindow) {
|
1623 | break;
|
1624 | }
|
1625 |
|
1626 |
|
1627 | await timeout(100);
|
1628 | }
|
1629 |
|
1630 | return resultingWindow;
|
1631 | }
|
1632 |
|
1633 | |
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 | var _private = Object.freeze({
|
1642 | __proto__: null,
|
1643 | assert: finalAssertExports,
|
1644 | cacheNames: cacheNames,
|
1645 | cacheWrapper: cacheWrapper,
|
1646 | canConstructReadableStream: canConstructReadableStream,
|
1647 | canConstructResponseFromBodyStream: canConstructResponseFromBodyStream,
|
1648 | dontWaitFor: dontWaitFor,
|
1649 | DBWrapper: DBWrapper,
|
1650 | Deferred: Deferred,
|
1651 | deleteDatabase: deleteDatabase,
|
1652 | executeQuotaErrorCallbacks: executeQuotaErrorCallbacks,
|
1653 | fetchWrapper: fetchWrapper,
|
1654 | getFriendlyURL: getFriendlyURL,
|
1655 | logger: logger,
|
1656 | resultingClientExists: resultingClientExists,
|
1657 | timeout: timeout,
|
1658 | WorkboxError: WorkboxError
|
1659 | });
|
1660 |
|
1661 | |
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 | |
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 |
|
1683 |
|
1684 | const cacheNames$1 = {
|
1685 | get googleAnalytics() {
|
1686 | return cacheNames.getGoogleAnalyticsName();
|
1687 | },
|
1688 |
|
1689 | get precache() {
|
1690 | return cacheNames.getPrecacheName();
|
1691 | },
|
1692 |
|
1693 | get prefix() {
|
1694 | return cacheNames.getPrefix();
|
1695 | },
|
1696 |
|
1697 | get runtime() {
|
1698 | return cacheNames.getRuntimeName();
|
1699 | },
|
1700 |
|
1701 | get suffix() {
|
1702 | return cacheNames.getSuffix();
|
1703 | }
|
1704 |
|
1705 | };
|
1706 |
|
1707 | |
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 |
|
1714 | |
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 |
|
1731 | async function copyResponse(response, modifier) {
|
1732 | const clonedResponse = response.clone();
|
1733 |
|
1734 | const responseInit = {
|
1735 | headers: new Headers(clonedResponse.headers),
|
1736 | status: clonedResponse.status,
|
1737 | statusText: clonedResponse.statusText
|
1738 | };
|
1739 |
|
1740 | const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
1741 |
|
1742 |
|
1743 |
|
1744 | const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
1745 | return new Response(body, modifiedResponseInit);
|
1746 | }
|
1747 |
|
1748 | |
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 | |
1756 |
|
1757 |
|
1758 |
|
1759 |
|
1760 |
|
1761 |
|
1762 | function clientsClaim() {
|
1763 | self.addEventListener('activate', () => self.clients.claim());
|
1764 | }
|
1765 |
|
1766 | |
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 | |
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 | function setCacheNameDetails(details) {
|
1792 | {
|
1793 | Object.keys(details).forEach(key => {
|
1794 | finalAssertExports.isType(details[key], 'string', {
|
1795 | moduleName: 'workbox-core',
|
1796 | funcName: 'setCacheNameDetails',
|
1797 | paramName: `details.${key}`
|
1798 | });
|
1799 | });
|
1800 |
|
1801 | if ('precache' in details && details['precache'].length === 0) {
|
1802 | throw new WorkboxError('invalid-cache-name', {
|
1803 | cacheNameId: 'precache',
|
1804 | value: details['precache']
|
1805 | });
|
1806 | }
|
1807 |
|
1808 | if ('runtime' in details && details['runtime'].length === 0) {
|
1809 | throw new WorkboxError('invalid-cache-name', {
|
1810 | cacheNameId: 'runtime',
|
1811 | value: details['runtime']
|
1812 | });
|
1813 | }
|
1814 |
|
1815 | if ('googleAnalytics' in details && details['googleAnalytics'].length === 0) {
|
1816 | throw new WorkboxError('invalid-cache-name', {
|
1817 | cacheNameId: 'googleAnalytics',
|
1818 | value: details['googleAnalytics']
|
1819 | });
|
1820 | }
|
1821 | }
|
1822 |
|
1823 | cacheNames.updateDetails(details);
|
1824 | }
|
1825 |
|
1826 | |
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 | |
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 | function skipWaiting() {
|
1842 |
|
1843 |
|
1844 | self.addEventListener('install', () => self.skipWaiting());
|
1845 | }
|
1846 |
|
1847 | exports._private = _private;
|
1848 | exports.cacheNames = cacheNames$1;
|
1849 | exports.clientsClaim = clientsClaim;
|
1850 | exports.copyResponse = copyResponse;
|
1851 | exports.registerQuotaErrorCallback = registerQuotaErrorCallback;
|
1852 | exports.setCacheNameDetails = setCacheNameDetails;
|
1853 | exports.skipWaiting = skipWaiting;
|
1854 |
|
1855 | return exports;
|
1856 |
|
1857 | }({}));
|
1858 |
|