How to use the workbox-core/_private/logger.js.logger.groupEnd 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
}

    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 {
      responsePromise = handler.handle({url, request, event, params});
    } catch (err) {
      responsePromise = Promise.reject(err);
    }

    if (responsePromise instanceof Promise && this._catchHandler) {
      responsePromise = responsePromise.catch((err) => {
        if (process.env.NODE_ENV !== 'production') {
          // Still include URL here as it will be async from the console group
          // and may not make sense without the URL
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-routing / src / Router.ts View on Github external
responsePromise = responsePromise.catch((err) => {
        if (process.env.NODE_ENV !== 'production') {
          // Still include URL here as it will be async from the console group
          // and may not make sense without the URL
          logger.groupCollapsed(`Error thrown when responding to: ` +
            ` ${getFriendlyURL(url)}. Falling back to Catch Handler.`);
          logger.error(`Error thrown by:`, route);
          logger.error(err);
          logger.groupEnd();
        }
        return this._catchHandler!.handle({url, request, event});
      });
    }
github GoogleChrome / workbox / packages / workbox-expiration / src / CacheExpiration.ts View on Github external
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;
      dontWaitFor(this.expireEntries());
    }
  }
github GoogleChrome / workbox / packages / workbox-strategies / src / CacheOnly.ts View on Github external
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;
  }
}
github GoogleChrome / workbox / packages / workbox-range-requests / src / createPartialResponse.ts View on Github external
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-strategies / src / utils / messages.ts View on Github external
printFinalResponse: (response?: Response) => {
    if (response) {
      logger.groupCollapsed(`View the final response here.`);
      logger.log(response || '[No response returned]');
      logger.groupEnd();
    }
  },
};
github GoogleChrome / workbox / packages / workbox-cacheable-response / src / CacheableResponse.ts View on Github external
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();

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

        logger.groupEnd();
      }
    }

    return cacheable;
  }
}
github GoogleChrome / workbox / packages / workbox-strategies / src / StaleWhileRevalidate.ts View on Github external
}
      try {
        response = await fetchAndCachePromise;
      } catch (err) {
        error = err;
      }
    }

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

    if (!response) {
      throw new WorkboxError('no-response', {url: request.url, error});
    }
    return response;
  }
github GoogleChrome / workbox / packages / workbox-strategies / src / NetworkOnly.ts View on Github external
plugins: this._plugins,
      });
    } catch (err) {
      error = err;
    }

    if (process.env.NODE_ENV !== 'production') {
      logger.groupCollapsed(
          messages.strategyStart('NetworkOnly', request));
      if (response) {
        logger.log(`Got response from network.`);
      } else {
        logger.log(`Unable to get a response from the network.`);
      }
      messages.printFinalResponse(response);
      logger.groupEnd();
    }

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