title: Chrome Extensions: DNS resolve with chrome.webRequest.onBeforeRequest
body: <p>Here is an example that redirects URLs containing <code>"someString"</code> to localhost, but it will resolve DNS for the URL before <code>redirectUrl</code> or <code>cancel</code>, this will leak some data, it is very unsafe.</p>
  
  <p>And, while using proxy extensions, it will resolve DNS remotely every time! How to fix this problem?</p>
  
  <pre><code>chrome.webRequest.onBeforeRequest.addListener(function(details) {
      if (details.url.indexOf("someString") &gt; 0) {
          console.log(details.url);
  
          /* test redirect */
          return {
              redirectUrl : "http://127.0.0.1/",
          };
  
          /* test cancel */
          // return {
              // cancel : true,
          // };
      }
  }, {
      urls : ["http://*/*", "https://*/*"],
  }, ["blocking"]);
  </code></pre>