Open cacieprins opened 7 months ago
We are implementing the CHIPs that is recommended by Chrome and even in the current version on retires it does not clear the cookie with partition. Are you seeing this as well @cacieprins ? We are also seeing duplication of the same cookie with and without partition. But that I think is a different issue other then the clearing.
I was not able to clear partitioned cookies using any cypress commands.
This is the workaround I am using to clear partitioned HttpOnly cookies after each test.
afterEach(() => {
const cookiesToRemove = ['cookie1', 'cookie2'];
const cookieAliases = [];
cy.url().then((url) => {
const currentUrl = new URL(url);
if (currentUrl.host) {
cookiesToRemove.forEach((cookieName) => {
const removeCookieUrl = `${currentUrl.protocol}//${currentUrl.host}/cypress/removeCookie/${cookieName}`;
cy.intercept('GET', removeCookieUrl, {
statusCode: 200,
headers: {
'Set-Cookie': `${cookieName}=; Max-Age=-1; path=/; Partitioned; secure; HttpOnly; SameSite=None`,
},
}).as(cookieName)
.then(() => {
fetch(removeCookieUrl, { method: 'GET' });
});
cookieAliases.push(cookieName);
});
}
});
cookieAliases.forEach((cookieName) => {
cy.wait(`@${cookieName}`).its('response.headers');
});
cy.clearAllCookies();
});
This uses an intercepted endpoint to remove the cookie via the Set-Cookie header. This endpoint is called using fetch after each test.
Hello, we use cypress for our tests and since Chrome 3rd-party cookies blocking in the future, we switched all our cookies to partitioned cookies (since we need to use our website inside an iframe). But now all tests are failing because cypress does not clear partitioned cookies.
Edit: Here is the workaround found:
beforeEach(() => {
cy.document().then(document => {
const cookies = document.cookie.split(`;`);
for (const cookie of cookies) {
document.cookie = cookie.split(`=`)[0].trim() + `=; Path=/; Secure; Partitioned; expires=` + new Date(0).toUTCString();
}
})
})
We need to add Path, Partitioned and Secure to be able to delete a partitioned cookie (As mentioned here).
Current behavior
In Chrome 123, when a domain has set a partitioned cookie, the
cy.clearAllCookies
command does not delete the partitioned cookie. As well, partitioned cookies do not seem to be cleared between tests in Chrome 123.Desired behavior
cy.clearAllCookies
should delete all cookies, included partitioned cookies. Partitioned cookies should be cleared between tests when test isolation is enabled.Test code to reproduce
(to be provided)
Cypress Version
13.7.2
Node version
v18.17.1
Operating System
macOS 14.3
Debug Logs
Other
These debug logs are from a modified
clear:cookies
case incdp_automation.ts
: