Because of the third-party cookie deprecation, I've updated some cookies for an application of mine accordingly to be "partitioned" using CHIPS.
In my case, for example, an affected cookie is set with JavaScript like this:
function setPartitionedCookie() {
document.cookie =
"cookie=delicious; Max-Age=86400; Path=/; Secure; SameSite=None; Partitioned;";
}
I'm trying to delete this cookie with JavaScript by setting the expiration date (Expires attribute) to a date in the past, as suggested in various questions here on Stack Overflow, see for example "Clearing all cookies with JavaScript".
Unfortunately, this does not work for partitioned cookies without also specifying the Secure and Partitioned attributes, at least in Chrome version 123:
function deletePartitionedCookie() {
/* "Secure" and "Partitioned" attributes are required to delete the partitioned cookie in Chrome */
// document.cookie = "cookie=; Expires=Thu, 01 Jan 1970 00:00:00 UTC; Secure; Partitioned;"; // this does work in Chrome
document.cookie = "cookie=; Expires=Thu, 01 Jan 1970 00:00:00 UTC;"; // this does not work in Chrome
}
From the answers to "Unable to delete cookie from javascript", I found out that it is sometimes required to also set the corresponding Path and Domain attributes. However, it's not explained why and in which cases this is required.
Is this behavior by design, or is there a specification for it? Could it even be a bug in Chrome?
What is the correct way to delete "partitioned cookies"?
Since Firefox and Safari do not support the Partitioned attribute, it is not yet an issue there. I haven't had a chance to test the behavior in Edge yet.
I'm not sure if an example here in the code snippet works, so I created this Glitch to test it:
https://delete-partitioned-cookies.glitch.me/