title: Chrome extension - saving login details for popup
body: <p>I'm working on a Chrome extension that will require the user to log into an account in order to see their content. What I want to do is prevent the user from having to log in every time by saving some kind of cookie or localStorage with relevant login/ session data once they do login. </p>
  
  <p>So far after doing a bit of research it seems that using Google Chromes local storage API would be the best way of doing this (would be great if someone could confirm this). </p>
  
  <p>My issue is with setting and getting local storage. I've setup a dummy local storage scenario here just to try and get Chrome to store ANY kind of local storage for the extension:</p>
  
  <p>Popup.js:</p>
  
  <pre><code>function setCookie(){
      chrome.extension.sendMessage({name: 'setLoginCookie'}, function(otherResponse) {
          console.log(otherResponse)
      })
  }
  
  function getCookie(){
      chrome.extension.sendMessage({name: 'getloginCookie'}, function(response) {
          alert(response)
      })
  }
  </code></pre>
  
  <p>event.js:</p>
  
  <pre><code>chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
  
      if (request.name == 'setLoginCookie') {
          var obj = {test:"test"}    
          chrome.storage.sync.set(obj, function() {
              alert('Data saved');
          });           
      }    
  
      if (request.name == 'getLoginCookie') {
             chrome.storage.sync.get('test', function(data) {
                  sendResponse({ screenshotUrl: data.test });
          })       
      }
      return true;
  
  });
  </code></pre>
  
  <p>When the setCookie function is executed I get the alert of 'data saved!' which would indicate to me it has worked but when I check the local storage on my extensions Chrome dev tools there is nothing there and if I call the <code>getCookie</code> function then it doesn't pick up anything. </p>
  
  <p>Here are the permissions in my manifest.json:</p>
  
  <pre><code>  "permissions": [
      "storage",
     "cookies",      
      "tabs",
      "&lt;all_urls&gt;",
      "pageCapture",
      "downloads"      
    ],  
  </code></pre>
  
  <p>Have I used the wrong approach here? Is using <code>chrome.storage.sync</code> perhaps where i've gone wrong?</p>
  
  <p>Thanks</p>