title: Can JavaScript or ServiceWorkers detect network activity / Ajax events?
body: <p>Is there a way for a <code>ServiceWorker</code> (or other mechanism) to detect when resources are being downloaded?</p>
  
  <p>For example, I'd like to be notified if any of the following happen:</p>
  
  <ul>
  <li><code>&lt;img src&gt;</code> downloads</li>
  <li>a resource in a <code>background-image: url(...)</code> downloads</li>
  <li>A stylesheet has encountered an <code>@import</code> and is fetching resources</li>
  <li><code>&lt;script src&gt;</code> downloads</li>
  <li>Some script invokes a new <code>XMLHTTPRequest</code> or <code>fetch</code></li>
  </ul>
  
  <p>Short of <a href="https://stackoverflow.com/a/3597640/1063035">hacking open the <code>XMLHttpRequest.prototype</code> methods</a>, does JavaScript offer a way to listen to network activity?</p>
  
  <p><em>It's sort of the opposite to <a href="https://stackoverflow.com/questions/33543449/can-i-detect-if-a-browsers-network-activity-is-idle">this question about idle network activity</a></em></p>