title: Chrome Extension, scrollTop=0 enywhere
body: <p>I'm making a chrome extension. And I've some problems with scrollTop (I hope this is the "get scroll height"!).</p>
  
  <p>First: structure: I've a manifest, an html page, a javascript, and an image.</p>
  
  <p>Second: Aim. I'm trying to scroll down to bottom, than go to top, and restart to scroll to bottom.. a loop.
  In manifest I've this:</p>
  
  <pre><code>{
   "background": {
         "page": "scroll.html"
   },
   "browser_action": {
         "default_icon": "icon.png",
         "default_title": ""
   },
   "content_scripts": [ {
         "js": [ "scroll.js" ],
         "matches": [ "http://*/*", "https://*/*" ]
   } ],
   "description": "Auto Scroll. UpDownUp!",
   "icons": {
         "128": "icon.png",
         "48": "icon.png"
   },    
   "manifest_version": 2,    
   "name": "Auto Scroll, UpDownUp",    
   "permissions": [ "tabs", "http://*/*", "https://*/*" ],    
   "version": "0.2.3"
  }
  </code></pre>
  
  <p>As you see I don't have any pop up html.</p>
  
  <p>In my html page i've this:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Auto Scroll&lt;/title&gt;
  &lt;/head&gt;
  &lt;body &gt;
  &lt;script src="scroll.js"&gt;&lt;/script&gt;
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>And In my scroll.js there are several functions, to start scrolling, and scrolling faster.
  But I don't need to quote all that code (164 lines).</p>
  
  <p>I've simply a lot of trash, and at the end it does only this simple thing:</p>
  
  <pre><code>chrome.tabs.update(id, {'url': 'javascript:document.body.scrollTop+=1;'});
  </code></pre>
  
  <p>My extension "works". But I've not done all what I wanted:</p>
  
  <p>This extension will only go down (and it does!!). I want that when I'm at bottom of page, the extension will execute:</p>
  
  <pre><code>chrome.tabs.update(id, {'url': 'javascript:document.body.scrollTop=0;'});
  </code></pre>
  
  <p>And I thought:</p>
  
  <p>1) get max scroll height, check with scrolltop, if same, use that code. If i do so, the extension will always go on top (after a little scroll down), as if these values are always(!!) equals.</p>
  
  <pre><code>if(document.body.scollTop==document.body.Height)
  {
  chrome.tabs.update(id, {'url': 'javascript:document.body.scrollTop=0;'});
  }
  </code></pre>
  
  <p>this is the result of first try... but doesn't works.</p>
  
  <p>2) var y=document.body.scrollTop --> scroll --> z=document.body.scrollTop. If y==z, then I'm on bottom, then go to top... this doesn't works, y and z are always equals!!!</p>
  
  <p>I used an alert(value) every time I use     </p>
  
  <pre><code>chrome.tabs.update(id, {'url': 'javascript:document.body.scrollTop+=1;'});
  </code></pre>
  
  <p>set as</p>
  
  <pre><code>alert(document.body.scollTop);
  </code></pre>
  
  <p>and pop up appear with "0". Always... I close the pop up, the extension scroll down a bit more, and pop up appear and there is 0 again!</p>
  
  <p>Ok... I'ts my fault!? </p>
  
  <p>I've an idea: my javascript is loaded by a background page, and the javascript act on a page in browser, mybe the scrollTop command give me background page height... and this is really BAD. 
  Can you help me finding the way to stop at end of "active" page to execute the "go-to-top" function!?</p>
  
  <p>Edit:</p>
  
  <p>I found something, if I use this </p>
  
  <pre><code>chrome.tabs.getSelected(null, function(tab) { 
      alert(tab.url);
  })
  </code></pre>
  
  <p>a window pop us telling me the acqual tab url. Looking at <a href="http://developer.chrome.com/extensions/tabs.html#type-Tab" rel="nofollow">this</a> I find that height is the tab properties, so I use:</p>
  
  <pre><code>    chrome.tabs.getSelected(null, function(tab) { 
      alert(tab.height);
  })
  </code></pre>
  
  <p>but the window popup and say "undefined" .... I really don't know what I've to do to retrieve the actual tab scroll position.</p>