How to use the workbox-core/_private/resultingClientExists.resultingClientExists 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 philipwalton / blog / assets / sw / routes / content.js View on Github external
async cachedResponseWillBeUsed({cachedResponse, event, request}) {
    // Check `event.request` instead of `request` since the latter is a
    // code-generated request for the content partial and is not a
    // navigation request.
    if (event && event.request && event.request.mode === 'navigate') {
      const {resultingClientId} = event;

      // Don't await this promise (otherwise it would delay the response).
      resultingClientExists(resultingClientId).then(async (resultingClient) => {
        // Give browsers that don't implement `resultingClientId`` a bit of time
        // for the JS to load, since it's likely they also don't implement
        // `postMessage()` buffering.
        if (!resultingClient) {
          await sleep(3000);
        }

        messageWindows({
          type: 'NAVIGATION_REPORT',
          payload: {
            url: event.request.url,
            cacheHit: Boolean(cachedResponse),
          },
        });
      });
    }