i am using node/express server and angularjs as frontend. server sets the cookie and is shown correctly in the network response. but the cookie is not shown in the resource tab in the chrome developer tools. What are the possible reasons for the same.
For Google Chrome the default location for cookies is %LocalAppData%\Google\Chrome\User Data\Default\cookies.
Below are 2 potential reasons for not actually setting a valid cookie:
There could also be a bug in the chrome dev tools to not show your cookies, but you can check that easily by issuing another request to the server and see what cookies are actually received by the server.
It might be that your cookie is the HTTPOnly authentication cookie. Those are not shown in chrome unless you're browsing the localhost.
If you're certain that the cookie is set and is being sent to the server, but you cannot always see it in the cookies pane in the developer tools, check that both the host and the path match the current URL in the browser. One option which may not always be suitable, is to explicitly set Path=/
in the cookie, to match all URLs.
When you're browsing your site with the developer console open, the cookies pane will show only the cookies that match the current host and path in the URL. For example, if you set your cookie for subdomain.example.com but are currently at example.com, the cookie for subdomain.example.com will not appear, even if it is currently set. Navigate to subdomain.example.com and you should now see it in the console.
Likewise, say your Node application at example.com/api did not set the Path
in the cookie and it was automatically set to Path=/api
. This will only be visible on the console, when and if you browse to a page that starts with example.com/api/. Your JavaScript code in the same page, sending requests to example.com/api will naturally include this cookie, even though it's not visible on the console, due to the path in the URL being different.
You can see the domain and path for all cookies on the site information pop-up. This is typically done by clicking the icon to the left of the URL, e.g. a padlock if it's HTTPS. Under the cookies section, you can see a box like the picture below for Opera, similar to other browsers.
Note the path and domain for the selected cookie.
Explicitly set Path=/
in the cookie. According to the Set-Cookie MDN documentation for Path=<path-value>
:
Indicates the path that must exist in the requested URL for the browser to send the Cookie header.
The forward slash (/) character is interpreted as a directory separator, and subdirectories are matched as well. For example, for Path=/docs,
- the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match.
- the request paths /, /docsets, /fr/docs will not match.
What is implicit in the above quote, is that using Path=/
will match all URLs in the given domain. Before taking this approach, you should be certain that it suits all scenarios in your particular use cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With