Search code examples
javascripthtmlcookiessession-cookies

Why isn't document.cookie getting set?


I have this JavaScript code that sets the document.cookie but when running it I can see document.cookie doesn't actually get set. See the screenshot below.

 (function() { 
      var offset = (new Date()).getTimezoneOffset()
      console.log("WAR");
      var date = new Date();console.log(offset);
      date.setTime(date.getTime()+3600000);
      var variable = "utc_offset="+offset+"; expires="+date.toGMTString();+"; path=/";
      console.log(variable); 
      document.cookie=variable;
})()

enter image description here


Solution

  • That's because you're not on an actual webpage but on a new Chrome tab.