Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!