I am trying to learn cookies in js but the name=value pairs aren’t disappearing from the console when I set a well past due expiration date. I think it has something to do with the error code with the CSP. Does anybody know how to fix it?
the js code:
document.cookie = "firstName=Bob; expires=Sat, 1 2025 23:59:59 EST; path=/";
document.cookie = "lastName=Roberts; expires=Sat, 1 2000 23:59:59 EST; path=/";
console.log(document.cookie);
console line 1: firstName=Bob; lastName=Roberts
1 issue: Content Security Policy of your site blocks the use of ‘eval’ in JavaScript`
I tried changing time zones, and dates, and updating VSC.
2
Answers
You won’t see this kind of client-side created cookie expire, because it would only ever expire when the browser is (re)loading a page from the cookie’s domain.
Cookies are sent to the server as an identifying alphanumeric value that is the key to some data value. I for one don’t understand why you’d want to add one in JavaScript.
Think your date strings are just incorrect, this deletes those cookies: