I want to create a chrome extension something like this
If i click on the extension icon page should start scrolling down, and keep scrolling until i click the icon again (toggle)
manifest.json is
{
    "name": "scrolldown",
    "description": "scroll down the page",
    "version": "0.1",
    "permissions": [
        "tabs",
        "<all_urls>"
    ],
    "browser_action": {
        "default_icon": "icon.png"
    },
    "background": {
       "scripts": [
            "background.js"
        ]
    },
    "manifest_version": 2
}
background.js is
var toggle=false;
chrome.browserAction.onClicked.addListener(function(tab) {
    toggle = !toggle;
    if (toggle) {
        var time = setInterval(function() {
            chrome.tabs.executeScript(tab.id,
                {
                    code: 'window.scrollBy(0, 1000);'
                }
            );
        }, 2000);
    } else {
        clearInterval(time);
    }
});
This code is half correct i.e If i click on the icon page start scrolling down , but if i click on icon again page does not stop . It keep scorlling down ,
i think there is something wrong in background.js
please help
 
     
    