Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

318
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda