cookies icon indicating copy to clipboard operation
cookies copied to clipboard

[Question] clearByName Android alternative?

Open francisleigh opened this issue 5 years ago • 5 comments

Hello! I am looking to be able to clear all Cookies for a specific Domain and can see that clearByName is only supported for IOS.

e.g docs

// clear cookies with name (IOS ONLY)
CookieManager.clearByName('http://example.com', 'cookie name', useWebKit)
	.then((succcess) => {
		console.log('CookieManager.clearByName from webkit-view =>', succcess);
});

Has anyone found a way to do this with Android?

Thank you Francis

francisleigh avatar Jan 19 '21 09:01 francisleigh

Thinking this package could be a viable alternative to this library.

francisleigh avatar Jan 27 '21 11:01 francisleigh

Need this property for the android platform. I don't want to clearAll cookies

trithien98 avatar Jul 15 '21 10:07 trithien98

Yeah Android doesn't support this out of the box https://developer.android.com/reference/android/webkit/CookieManager, hence only supporting iOS.

Open to seeing how we could design this feature since its been highly requested.

safaiyeh avatar Jul 19 '21 15:07 safaiyeh

Any update on this issue?
I'd love to know how to clear cookies for a certain URL on android

clemwo avatar Apr 11 '23 13:04 clemwo

Ok, so what works for me is simply setting the value of the cookie I want to delete to an empty string. But I honestly have no clue why the token gets automatically deleted when I set the value to an empty string. Can anyone else try this out and confirm this?
@safaiyeh

CookieManager.set(<url>, { name: "<cookieName>", value: ""})

Edit. In RFC 6265 it also says that in order to delete cookies, servers can simply send a cookie with the same value but an expiry date in the past. Maybe that's what's happening here? Either way that also seems like a good way to delete a single cookie 4.1.2

Notice that servers can delete cookies by sending the user agent a new cookie with an Expires attribute with a value in the past.

Edit2. Did another test. This deletes the cookie with the value of cookieName:

    CookieManager.set(url, {
      name: cookieName,
      value: '',
      expires: '2024-05-30T12:30:00.00-05:00',
    })

obviously the expiry date is not needed for the deletion here

clemwo avatar Apr 27 '23 15:04 clemwo