When I set a value to session (cookie session), I can see that value from the client like below
However, when I try to get the cookie with javascript document.cookie
, this is all I get
How can I get the PLAY_SESSION cookie?
You can't get the session cookie in the JavaScript of your browser. For security reasons it's set to http-only.
If you just want to persist some small data between requests you can set your own cookie in the response of an action. Just set the http-only flag to false:
response().setCookie(
"theme", // name
"blue", // value
3600, // maximum age
"/some/path", // path
".example.com", // domain
false, // secure
false // http only
);
With the http-only flag set to false you can access your cookie from your JavaScript within the browser.