question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Cookie Removal Api

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:5

github_iconTop GitHub Comments

1reaction
poziminskicommented, Oct 14, 2022

Here’s a helper script for clearing cookie by name in Playwright.

const clearCookieByName = async (context, cookieClearedName) => {
      const filteredCookies = await context
          .cookies()
          .filter((cookie) => cookie.name !== cookieClearedName)

      context.clearCookies()
      context.addCookies(filteredCookies)
}

const context = await browser.newContext()

await clearCookieByName(context, 'COOKIE_TO_REMOVE')
1reaction
shirshak55commented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cookies.remove() - Mozilla - MDN Web Docs
The remove() method of the cookies API deletes a cookie, given its name and URL. The call succeeds only if you include the...
Read more >
Remove Cookies by clicking on button - Web Extension API
The remove() method of the cookies API deletes a cookie, given its name and URL. This means you also need to specify the...
Read more >
Cookies API - The Chromium Projects
Overview. The proposed API allows Chrome extensions to access the browser's cookies, without having to send HTTP requests to obtain those cookies. Use...
Read more >
cookie banner API - HubSpot Developers
You can remove the cookie by calling the function again and including the {track: true} argument: _hsq.push(['doNotTrack', {track: true}]);.
Read more >
chrome.cookies - Chrome Developers
The underlying reason behind the cookie's change. If a cookie was inserted, or removed via an explicit call to "chrome.cookies.remove", "cause" will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found