title: How to toggle switch chrome extension
body: <p>I am new to developing chrome extensions.
  I am trying to build a simple extension and I want that extension to be toggle between on and off states via the icon.</p>
  <p>Here is the code I am using so far for achieving this:</p>
  <p>(background.js)</p>
  <pre><code>var enabled = 1;
  chrome.action.onClicked.addListener(function () {
      console.log(enabled);
      if (enabled == 0) {
          enabled = 1;
          chrome.action.setIcon({
              path: &quot;images/on.png&quot;
          });
      } else {
          enabled = 0;
          chrome.action.setIcon({
              path: &quot;images/off.png&quot;
          });
      }
  });
  </code></pre>
  <p>And then in the same file, I am doing the stuff I want to do.
  This works so far but the problem is, yes the thing works with an if statement:</p>
  <pre><code>if(enabled == 1){
  do this...}
  </code></pre>
  <p>But after a while because of a reason that I couldn't understand (I've done console log debugs with the &quot;enabled&quot; variable, it works fine), the extension keeps working since its in the disabled state and the icon shows its disabled...</p>