title: Execute my Autofill Javascript on Chrome extension click
body: <p>I have a working Javascript which prompts the user for his email and password for first time; and afterwards, it autofills the username and password whenever the user revisits that webpage. In my html code, I just have to call my checkCookie() function to perform this on JSFiddle.net.</p>
  
  <p>Now I want to create a Chrome extension which on click runs the autofill JS. I have these codes but on extension click, I get no output. Can anybody suggest me what am I doing wrong.</p>
  
  <pre><code> // manifest.json
  
  {
     "manifest_version": 2,
  
     "name": "Auto-fill Passwords",
     "description": "This extension autofill password on click.",
     "version": "1.0",    
     "browser_action": {
     "default_icon": "icon.png"
      },
  
     "background": {
     "scripts": ["background.js"]
      }
  }
  
  
  
  
  // background.js
  chrome.browserAction.onClicked.addListener(function (tab) 
  { //Fired when User Clicks ICON
  
      chrome.tabs.executeScript(tab.id, {
          "file": "autofill.js"
      }, function () { 
  
    function setCookie(c_name, value, exdays) {
      var exdate = new Date();
      exdate.setDate(exdate.getDate() + exdays);
  
              var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
              document.cookie = c_name + "=" + c_value;
  
          }
  
  function checkCookie() {
  var username = prompt("Please enter your name:", "");
  var n= getCookie("username",username);
  if(n)
  {
    alert("UserID Match! The user's password is " +n) ;
  }
  else
  {
    //alert("UserID  password doesnot exist ");
    var password = prompt("Please enter your password:", "");
                  username += "!";
          username += password;
  alert("Username = "+ username);
  setCookie("username", username, 365);
  
  }
  
  }
  
  
          console.log("Script Executed .. "); // Notification on Completion
      });
   }
  });
  
  
  //autofill.js
  alert("Check cookie function is called");
  checkCookie();
  </code></pre>