shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.9k stars 324 forks source link

Google Tag Manager fetch error #349

Open AykutSarac opened 2 years ago

AykutSarac commented 2 years ago

Summary

Getting the following error at console output

The FetchEvent for "<URL>" resulted in a network error response: the promise was resolved with an error response object.

Versions

How To Reproduce

Steps to reproduce the behavior:

  1. Go to 'https://jsonvisio.com/'
  2. See error

Link to minimal reproduce setup repository if any. https://github.com/AykutSarac/jsonvisio.com

Screenshots

image

If applicable, add screenshots to help explain your problem.

Additional Context

Add any other context about the problem here.

AykutSarac commented 2 years ago

Replicating the issue: 1- Hard reset the page (Command + Shift + R / CTRL + F5) - at this stage it works fine 2- Refresh page or revisit page

at stage 2 is where the problem occurs. Serviceworker is causing the issue here, if you unregister Serviceworker from Dev Tools > Application it works fine until it registers back. Any idea how to fix that? @shadowwalker?

robsongajunior commented 9 months ago

I'm not using next-pwa, but the same error in my app with Astro Build I solved cloning the response.

E.G

       const response = await fetch(clonedRequest);

        if ((response && response.ok) && clonedRequest.destination === 'script') {
          const clonedResponse = response.clone();

          const scriptContent = await clonedResponse.text();
          const clients = await self.clients.matchAll();

          for (const client of clients) {
            client.postMessage({
              cmd: 'runScript',
              content: scriptContent
            });
          }

          // Return the original response so the fetch completes as intended
          return response;
        } else {
          console.log(`response failure, sending original`);

          // If not a script or fetch wasn't successful, return the response directly
          return response;
        }

in the line seting clonedResponse is what i add to solve the same problem