1

According to MDN:

The onfetch property of the ServiceWorkerGlobalScope interface is an event handler fired whenever a fetch event occurs (usually when the WindowOrWorkerGlobalScope.fetch() method is called.)

Does this mean that service worker can only intercept requests sent by fetch() from main thread? How about ajax requests? Is there any way to intercept them through service worker?

Chor
  • 833
  • 1
  • 5
  • 14

1 Answers1

1

Fetch events are sent when any resource is being fetched through HTTP, be it scripts, medias, links etc., and XHR.

So yes, a ServiceWorker should intercept XHR requests (though synchronous ones are only intercepted in Firefox...)

Kaiido
  • 123,334
  • 13
  • 219
  • 285