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

324
Visualizações
how to solve service_worker_en.js:3 Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'WorkerGlobalScope'?

My Chrome console is giving this error for my website

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

I have read this article on S.O but still can not figure out what the problem really is with my code. Here is my service worker code

self.addEventListener("install", function(event) {
    event.waitUntil(preLoad());
});
var preLoad = function() {
    console.log("Installing web app");
    return caches.open("offline").then(function(cache) {
        console.log("caching index and important routes");
        return cache.addAll(["/", "/devotional-language-en-tab-9"]);
    });
};
self.addEventListener("fetch", function(event) {
    event.respondWith(checkResponse(event.request).catch(function() {
        return returnFromCache(event.request);
    }));
    event.waitUntil(addToCache(event.request));
});
var checkResponse = function(request) {
    return new Promise(function(fulfill, reject) {
        fetch(request).then(function(response) {
            if (response.status !== 404) {
                fulfill(response);
            } else {
                reject();
            }
        }, reject);
    });
};
var addToCache = function(request) {
    return caches.open("offline").then(function(cache) {
        return fetch(request).then(function(response) {
            console.log(response.url + " was cached");
            return cache.put(request, response);
        });
    });
};
var returnFromCache = function(request) {
    return caches.open("offline").then(function(cache) {
        return cache.match(request).then(function(matching) {
            if (!matching || matching.status == 404) {
                return cache.match("offline_en.html");
            } else {
                return matching;
            }
        });
    });
};

According to Chrome the error is mainly on this two lines :

enter image description here

how to solve service_worker_en.js:3 Uncaught (in promise) TypeError: ? Please I need a specific answer that will solve the issue.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to clone the request object before fetch using API_ENDPOINT.clone(), since the object is already consumed.

var addToCache = function(request) {
  return caches.open("offline").then(function(cache) {
    return fetch(request.clone()).then(function(response) {
      console.log(response.url + " was cached");
      return cache.put(request, response);
    });
  });
};
...
about 4 years ago · Juan Pablo Isaza Relatório
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