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

204
Visualizações
Service worker fetch event passing in wrong type

I add a fetch event listener like this

self.addEventListener( 'fetch', fetch )

and here is my fetch function

const fetch = e => {
    console.log({e})
    if ( !e.request.url.startsWith( self.location.origin ) || e.request.method !== 'GET' ) return

    const save = async res => {
        const cache = await caches.open( dynamic )
        cache.put( e.request, res )
    }

    const process = async cached => {
        if ( cached ) return cached
        const res = await fetch( e.request.clone() )
        if ( res ) await save( res.clone() )
        return res
    }

    e.respondWith( caches.match( e.request ).then( process ))
}

When I look at the event thats being passed in, I expect a fetch event but this is what I see

console log

Its printing a request object after the correct Fetch event. When i try to access the url, it will of course throw an error as it will effectively be doing request.request.url

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

0

In your process method, you're calling the fetch function using a cloned Request, which is probably the Request you see in your console.

const res = await fetch( e.request.clone() )

This issue is because your custom method is called fetch, but in this case you probably want to use the native fetch method. Perhaps you should consider renaming your custom method to prevent conflicts like this.

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