title: How do I make a webRequest Event Page that only listens for events when a flag is set?
body: <p>I am making an extension that can be ON or OFF, which I can check via a flag stored in local data.</p>
  
  <p>When ON, I want to listen for all webRequests and redirect them like so:</p>
  
  <pre><code>chrome.webRequest.onBeforeRequest.addListener(
  
    // callback
    function(info) {
      console.log("Got request: " + info.url + "\n Going to redirect");
      return {redirectUrl: chrome.extension.getURL("redirect.html")};
    },
  
    // filters
    {
      urls: [
        "&lt;all_urls&gt;"
      ]
    },
  
    // extraInfoSpec
    ["blocking"]);
  </code></pre>
  
  <p>But when OFF I do not want the event to fire at all. Ideally when OFF I wouldn't even be listening to events (if that would cut down on performance overhead in any significant way).  One option I see is checking the flag in my callback function and simply not redirecting if OFF, but that still has the event being handled. As I understand it, the event will not be handled if the RequestFilter does not pass. Can I modify the RequestFilter to also check my ON/OFF boolean flag before trying to handle the event? Or is the RequestFilter only meant for checking URLs, headers, etc.?</p>
  
  <p>Also my main reasoning for wanting to only handle events when ON is that it seems like a needless performance hit to try to handle EVERY webRequest - even if briefly. Would an immediate flag checking in the callback function not make any noticeable impact on performance anyway?</p>
  
  <p>I am new to Chrome Extension dev and webdev in general, so if there is a much cleaner/easier way of doing this then please let me know.</p>
  
  <p>Thanks!</p>