获取和添加事件监听器

I read in https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Response_objects that you can use addEventListener to trigger when a fetch happens.

I'm playing with it, and I can't get it to fire. Here's the code. I'm also using Chrome

addEventListener('fetch', event => alert('test'));

After a service worker is installed and the user navigates to a different page or refreshes, the service worker will begin to receive fetch events, an example of which is below.

self.addEventListener('fetch', function(event) {
  event.respondWith(
    caches.match(event.request)
      .then(function(response) {
        // Cache hit - return response
        if (response) {
          return response;
        }
        return fetch(event.request);
      }
    )
  );
});