Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

316
Vistas
Error in Service Worker: Cannot construct a Request with a Request object that has already been used

When the following service worker code runs I get a bunch of these errors:

serv-worker.js:38 Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope': Cannot construct a Request with a Request object that has already been used.

Question also asked here and unanswered: [https://stackoverflow.com/questions/55979921/error-request-object-that-has-already-been-used]

Appreciations for any help/explanation!

console.log('Start serv-worker.js');

const cacheName = '3.2121';

var urlsToCache = [
  'home.html',
  'home-js.js', 
  'web-bg.js', 
  'css/main.css',
  'css/edit-menus.css'
];

self.addEventListener('install', event => {
  console.log('Install event...', urlsToCache);
  event.waitUntil(
    caches.open(cacheName)
      .then(function(cache) {
        console.log('Opened cache', cacheName);
        return cache.addAll(urlsToCache);
      })
    );
});

//  Network first.
self.addEventListener('fetch', (event) => {
  // Check the cache first
  // If it's not found, send the request to the network
  // event.respondWith(
  //   caches.match(event.request).then(function (response) {
  //     return response || fetch(event.request).then(function (response) {
  //       return response;
  //     });
  //   })
  // );
  event.respondWith(async function() {
    try {
      console.log('aPull from network...', event.request);
      return await fetch(event.request);
    } catch (err) {
      console.log('aPull from cache...', event.request);
      return caches.match(event.request);
    }
  }());
});

self.addEventListener('message', function (event) {
  console.log('ServiceWorker cache version: ', cacheName, event);
  console.log('Received msg1: ', event.data);
  if (event.data.action === 'skipWaiting') {
    console.log('ccClearing cache: ', cacheName);
    // caches.delete('1.9rt1');     //  hardcode old one
    // caches.delete(cacheName);     //  actually removes cached versions
    caches.keys().then(function(names) {
      for (let name of names)
          caches.delete(name);
    });
    self.skipWaiting();
  }
});
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda