title: Chrome Extension - How to capture Scroll Position on open tabs
body: <p>I currently capture scroll location on a tab by running it in a content script (see below) and injecting JQuery.</p>
  
  <p><strong>Question</strong> How do I apply scroll capture to all tabs open not just the current tab I'm on?
  My try below works for just current tab.</p>
  
  <p>Unsure how to iterate a for loop across all tabs since don't have access to chrome.tabs API in content script.  Am I approaching this wrong by constantly tracking scroll capture and should use a background.js to call a content_script function only on a certain event?</p>
  
  <p>Thanks!</p>
  
  <p><strong>manifest.json</strong></p>
  
  <pre><code>{
  "manifest_version": 2,
  "name": "ScrollPosition",
  "version": "1.0",
  "background": {
  "page": "background.html"
  },
  "content_scripts": [
  { "matches": ["http://*/*", "https://*/*"],
  "js": ["jquery-1.11.1.min.js","content_script.js"]}
  ],
  "browser_action": {
      "default_icon": {
          "19": "images/icon19.png",
          "38": "images/icon38.png"
      },
      "default_popup": "popup.html"
  },
  "permissions": [
      "tabs",
      "windows",
      "&lt;all_urls&gt;",
      "chrome://favicon/",
  ]
  }
  </code></pre>
  
  <p><strong>content_script.js</strong></p>
  
  <pre><code>var scrollPosition = 0;
  
  function scrollPos() {
    $(document).scroll(function(){
      scrollPosition = $(this).scrollTop();  
      console.log('your scroll position is: '+scrollPosition);
    });
  };
  
  window.addEventListener("load", scrollPos);
  </code></pre>