You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to clear the cookie using its name or domain etc. It has a lot of uses like logging out and logging in to certain websites.
Currently, we have only one way to clear the whole cookie. Yes, there are workaround like getting all cookies filtering them, and writing the cookies back using add cookies. So I am making this proposal to add cookie removal API which clears based on name or URL etc.
await context.clearCookies(cookie => cookie.name.startsWith("HELLO")) would remove all cookies which has name that starts with HELLO?
Reacted by Eftal BULUT, vsravuri, Ghustavh97, Szymon Marczak, Ian VanSchooten, Andrew D. Bond, Evan Henley, Martin Hogge, Frank Fiegel, Adishwar Rishi and 11 more
There is an workaround. Firstly, store the cookies in variable, clear the cookies and insert the cookies by filtering out the one which you don't need.
This feature would be really appreciated. I was using the workaround (clear/filter/add) but there is a small period of time where there is no cookies in the storage, and I got once an issue where a request has been sent during this small period of time. The request was missing a cookie and because of that the test failed.
I've worked around it by updating my test to try to avoid any requests sending while I'm filtering cookies, but I can't guarantee this won't happen again. This is why I would love being able to clear a specific cookie without the need to first clear them all.
Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.
If you disagree with this closure, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.
Activity
manochernazari commentedon Feb 28, 2022
Any update on this, I really need to be able to delete specific cookie during automated test.
shirshak55 commentedon Feb 28, 2022
manochernazari
There is an workaround. Firstly, store the cookies in variable, clear the cookies and insert the cookies by filtering out the one which you don't need.
manochernazari commentedon Mar 3, 2022
Shirshak (@shirshak55) many thanks for your sugguestion. I got passed the issue just like you sugguested.
Martin-Hogge commentedon Aug 10, 2022
This feature would be really appreciated. I was using the workaround (clear/filter/add) but there is a small period of time where there is no cookies in the storage, and I got once an issue where a request has been sent during this small period of time. The request was missing a cookie and because of that the test failed.
I've worked around it by updating my test to try to avoid any requests sending while I'm filtering cookies, but I can't guarantee this won't happen again. This is why I would love being able to clear a specific cookie without the need to first clear them all.
poziminski commentedon Oct 14, 2022
Here's a helper script for clearing cookie by name in Playwright.
pavelfeldman commentedon Jun 30, 2023
Why was this issue closed?
Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.
If you disagree with this closure, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.
IanVS commentedon May 21, 2024
It looks like this has been addressed in Playwright 1.43: https://playwright.dev/docs/release-notes#new-apis-1.
context.clearCookies()now supports an optional filter:https://playwright.dev/docs/api/class-browsercontext#browser-context-clear-cookies