title: Writing an equivalent to Chrome's onBeforeRequest in a Safari extension
body: <p>Chrome extensions have the ability to intercept <em>all</em> web requests to specified URLs using <code>chrome.webRequest.onBeforeRequest</code>. This includes not only static asset requests, but requests for AJAX, PJAX, favicons, and everything in between.</p>
  
  <p>Apple provides a few close approximations to this functionality, such as the <code>beforeLoad</code> (handles images, CSS, and JS) and <code>beforeNavigate</code> (handles full page loads) event handlers, but neither catch AJAX requests. I've tried overloading XMLHttpRequest in an attempt to catch AJAX loads to no avail (I might be doing something wrong). Here's a brief example of how I'm doing this:</p>
  
  <pre><code>var originalOpen = window.XMLHttpRequest.prototype.open;
  window.XMLHttpRequest.prototype.open = function(method, url, async, username, password) {
      console.log("overriden");
      return originalOpen.apply(this, arguments);
  }
  </code></pre>
  
  <p>How can I catch all web requests (AJAX, CSS, JS, etc.) in a Safari extension?</p>