title: On browser refresh / close, my cookie is deleted before it expires. Why?
body: <p>I'm setting and getting a cookie using JavaScript in a Google Apps Script gadget in a Google Sites page. I'm using the code below. It sets the cookie just fine and I can locate it through my browser settings (I'm using Chrome). I can link-click navigate around my site and return to the page that I'm testing using the back button and the cookie is read back just fine, but the moment I hit refresh or use the address bar to navigate the cookie disappears. What the heck is going on? Forgive me if I'm being dense, but this is incorrect behaviour, right? Otherwise, why even have an expires string at all? The cookie is supposed to stick around until it expires, regardless of browser refreshing or closing, no?</p>
  
  <p>The set cookie function produces a cookie string like:</p>
  
  <blockquote>
    <p>email=myusername@gmail.com;expires=Fri, 15 Jul 2016 16:57:00
    GMT;path=/;domain=.googleusercontent.com;</p>
  </blockquote>
  
  <p>I am setting "domain=.googleusercontent.com" because that is the domain where GAS live and I want my cookie available to several pages using the same gadget. Am I hitting some sandboxing thing that GAS is doing maybe?</p>
  
  <pre><code>function setCookie(email, daysToExpire) {
    var d = new Date();
    d.setTime(d.getTime() + (daysToExpire * 24 * 60 * 60 * 1000));
    var expires = 'expires=' + d.toGMTString();
    var cookie = 'email=' + email + ';' + expires + ';path=/;domain=.googleusercontent.com;';
    document.cookie = cookie;
  }
  
  function getCookie() {
    var email = 'email=';
    var ca = document.cookie.split(';');
    for(var i = 0; i &lt; ca.length; ++i) {
      var c = ca[i];
      while(c.charAt(0) == ' ') {
        c = c.substring(1);
      }
      if(c.indexOf(email) == 0) {
        return c.substring(email.length, c.length);
      }
    }
    return '';
  }
  </code></pre>