How to use the workbox-core/_private/logger.js.logger.groupCollapsed function in workbox-core

To help you get started, we’ve selected a few workbox-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleChrome / workbox / packages / workbox-routing / src / Router.ts View on Github external
handler = this._defaultHandler;
    }

    if (!handler) {
      if (process.env.NODE_ENV !== 'production') {
        // No handler so Workbox will do nothing. If logs is set of debug
        // i.e. verbose, we should print out this information.
        logger.debug(`No route found for: ${getFriendlyURL(url)}`);
      }
      return;
    }

    if (process.env.NODE_ENV !== 'production') {
      // We have a handler, meaning Workbox is going to handle the route.
      // print the routing details to the console.
      logger.groupCollapsed(`Router is responding to: ${getFriendlyURL(url)}`);

      debugMessages.forEach((msg) => {
        if (Array.isArray(msg)) {
          logger.log(...msg);
        } else {
          logger.log(msg);
        }
      });

      logger.groupEnd();
    }

    // Wrap in try and catch in case the handle method throws a synchronous
    // error. It should still callback to the catch handler.
    let responsePromise;
    try {
github GoogleChrome / workbox / packages / workbox-precaching / src / utils / addFetchListener.ts View on Github external
responsePromise = responsePromise.then((response) => {
        // Workbox is going to handle the route.
        // print the routing details to the console.
        logger.groupCollapsed(`Precaching is responding to: ` +
          getFriendlyURL(event.request.url));
        logger.log(`Serving the precached url: ${precachedURL}`);

        logger.groupCollapsed(`View request details here.`);
        logger.log(event.request);
        logger.groupEnd();

        logger.groupCollapsed(`View response details here.`);
        logger.log(response);
        logger.groupEnd();

        logger.groupEnd();
        return response;
      });
    }
github GoogleChrome / workbox / packages / workbox-precaching / src / utils / addFetchListener.ts View on Github external
responsePromise = responsePromise.then((response) => {
        // Workbox is going to handle the route.
        // print the routing details to the console.
        logger.groupCollapsed(`Precaching is responding to: ` +
          getFriendlyURL(event.request.url));
        logger.log(`Serving the precached url: ${precachedURL}`);

        logger.groupCollapsed(`View request details here.`);
        logger.log(event.request);
        logger.groupEnd();

        logger.groupCollapsed(`View response details here.`);
        logger.log(response);
        logger.groupEnd();

        logger.groupEnd();
        return response;
      });
    }
github GoogleChrome / workbox / packages / workbox-strategies / src / NetworkFirst.ts View on Github external
this._getNetworkPromise({timeoutId, request, event, logs});
    promises.push(networkPromise);

    // Promise.race() will resolve as soon as the first promise resolves.
    let response = await Promise.race(promises);
    // If Promise.race() resolved with null, it might be due to a network
    // timeout + a cache miss. If that were to happen, we'd rather wait until
    // the networkPromise resolves instead of returning null.
    // Note that it's fine to await an already-resolved promise, so we don't
    // have to check to see if it's still "in flight".
    if (!response) {
      response = await networkPromise;
    }

    if (process.env.NODE_ENV !== 'production') {
      logger.groupCollapsed(
          messages.strategyStart('NetworkFirst', request));
      for (let log of logs) {
        logger.log(log);
      }
      messages.printFinalResponse(response);
      logger.groupEnd();
    }

    if (!response) {
      throw new WorkboxError('no-response', {url: request.url});
    }
    return response;
  }
github GoogleChrome / workbox / packages / workbox-expiration / src / CacheExpiration.ts View on Github external
const minTimestamp = this._maxAgeSeconds ?
        Date.now() - (this._maxAgeSeconds * 1000) : 0;

    const urlsExpired = await this._timestampModel.expireEntries(
        minTimestamp, this._maxEntries);

    // Delete URLs from the cache
    const cache = await self.caches.open(this._cacheName);
    for (const url of urlsExpired) {
      await cache.delete(url);
    }

    if (process.env.NODE_ENV !== 'production') {
      if (urlsExpired.length > 0) {
        logger.groupCollapsed(
            `Expired ${urlsExpired.length} ` +
          `${urlsExpired.length === 1 ? 'entry' : 'entries'} and removed ` +
          `${urlsExpired.length === 1 ? 'it' : 'them'} from the ` +
          `'${this._cacheName}' cache.`);
        logger.log(`Expired the following ${urlsExpired.length === 1 ?
            'URL' : 'URLs'}:`);
        urlsExpired.forEach((url) => logger.log(`    ${url}`));
        logger.groupEnd();
      } else {
        logger.debug(`Cache expiration ran and found no entries to remove.`);
      }
    }

    this._isRunning = false;
    if (this._rerunRequested) {
      this._rerunRequested = false;
github GoogleChrome / workbox / packages / workbox-range-requests / src / createPartialResponse.ts View on Github external
status: 206,
      statusText: 'Partial Content',
      headers: originalResponse.headers,
    });

    slicedResponse.headers.set('Content-Length', String(slicedBlobSize));
    slicedResponse.headers.set('Content-Range',
        `bytes ${effectiveBoundaries.start}-${effectiveBoundaries.end - 1}/` +
        originalBlob.size);

    return slicedResponse;
  } catch (error) {
    if (process.env.NODE_ENV !== 'production') {
      logger.warn(`Unable to construct a partial response; returning a ` +
        `416 Range Not Satisfiable response instead.`);
      logger.groupCollapsed(`View details here.`);
      logger.log(error);
      logger.log(request);
      logger.log(originalResponse);
      logger.groupEnd();
    }

    return new Response('', {
      status: 416,
      statusText: 'Range Not Satisfiable',
    });
  }
}
github GoogleChrome / workbox / packages / workbox-cacheable-response / src / CacheableResponse.ts View on Github external
cacheable = this._statuses.includes(response.status);
    }

    if (this._headers && cacheable) {
      cacheable = Object.keys(this._headers).some((headerName) => {
        return response.headers.get(headerName) === this._headers![headerName];
      });
    }

    if (process.env.NODE_ENV !== 'production') {
      if (!cacheable) {
        logger.groupCollapsed(`The request for ` +
          `'${getFriendlyURL(response.url)}' returned a response that does ` +
          `not meet the criteria for being cached.`);

        logger.groupCollapsed(`View cacheability criteria here.`);
        logger.log(`Cacheable statuses: ` +
          JSON.stringify(this._statuses));
        logger.log(`Cacheable headers: ` +
          JSON.stringify(this._headers, null, 2));
        logger.groupEnd();

        const logFriendlyHeaders: {[key: string]: string} = {};
        response.headers.forEach((value, key) => {
          logFriendlyHeaders[key] = value;
        });

        logger.groupCollapsed(`View response status and headers here.`);
        logger.log(`Response status: ` + response.status);
        logger.log(`Response headers: ` +
          JSON.stringify(logFriendlyHeaders, null, 2));
        logger.groupEnd();
github GoogleChrome / workbox / packages / workbox-cacheable-response / src / CacheableResponse.ts View on Github external
let cacheable = true;

    if (this._statuses) {
      cacheable = this._statuses.includes(response.status);
    }

    if (this._headers && cacheable) {
      cacheable = Object.keys(this._headers).some((headerName) => {
        return response.headers.get(headerName) === this._headers![headerName];
      });
    }

    if (process.env.NODE_ENV !== 'production') {
      if (!cacheable) {
        logger.groupCollapsed(`The request for ` +
          `'${getFriendlyURL(response.url)}' returned a response that does ` +
          `not meet the criteria for being cached.`);

        logger.groupCollapsed(`View cacheability criteria here.`);
        logger.log(`Cacheable statuses: ` +
          JSON.stringify(this._statuses));
        logger.log(`Cacheable headers: ` +
          JSON.stringify(this._headers, null, 2));
        logger.groupEnd();

        const logFriendlyHeaders: {[key: string]: string} = {};
        response.headers.forEach((value, key) => {
          logFriendlyHeaders[key] = value;
        });

        logger.groupCollapsed(`View response status and headers here.`);
github GoogleChrome / workbox / packages / workbox-strategies / src / CacheOnly.ts View on Github external
className: 'CacheOnly',
        funcName: 'makeRequest',
        paramName: 'request',
      });
    }

    const response = await cacheWrapper.match({
      cacheName: this._cacheName,
      request,
      event,
      matchOptions: this._matchOptions,
      plugins: this._plugins,
    });

    if (process.env.NODE_ENV !== 'production') {
      logger.groupCollapsed(
          messages.strategyStart('CacheOnly', request));
      if (response) {
        logger.log(`Found a cached response in the '${this._cacheName}'` +
          ` cache.`);
        messages.printFinalResponse(response);
      } else {
        logger.log(`No response found in the '${this._cacheName}' cache.`);
      }
      logger.groupEnd();
    }

    if (!response) {
      throw new WorkboxError('no-response', {url: request.url});
    }
    return response;
  }